1
0
mirror of https://github.com/robonen/canvas-3d.git synced 2026-03-20 02:44:40 +00:00

Merge pull request #7 from robonen/docker

Docker
This commit is contained in:
2022-11-17 16:11:41 +07:00
committed by GitHub
11 changed files with 1909 additions and 1622 deletions

16
.dockerignore Normal file
View File

@@ -0,0 +1,16 @@
# Ignore everything
*
# Allow files and directories
!.env
!src
!nuxt.config.ts
!tsconfig.json
!package.json
!package-lock.json
# Ignore unnecessary files inside allowed directories
**/*~
**/*.log
**/.DS_Store
**/Thumbs.db

View File

@@ -1 +1,12 @@
NUXT_API_HOST=https://localhost APP_NAME=canvas-3d
# Infrastucture config
FORWARD_APP_PORT=3000
FORWARD_DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=password
DB_DATABASE=c3d
# App config
NUXT_API_HOST=http://localhost/api

18
.gitignore vendored
View File

@@ -5,16 +5,18 @@
# Temporary files # Temporary files
node_modules node_modules
tmp **/*~
*.log* **/*.log
**/.DS_Store
**/Thumbs.db
# Build # Build
src/.nuxt **/.nuxt
.nuxt **/.nitro
.nitro **/.cache
.cache **/.output
.output **/dist
dist
# Environment # Environment
.env .env
.env

25
Dockerfile Normal file
View File

@@ -0,0 +1,25 @@
ARG NODE_VERSION=18.12-slim
# Stage 1: Build the application
FROM node:${NODE_VERSION} AS builder
WORKDIR /build
# See .dockerignore
COPY . .
RUN npm cache clean --force && npm ci && npm run build
# Stage 2: Run the application
FROM node:${NODE_VERSION}
WORKDIR /app
COPY --from=builder /build/src/.output .
ENV HOST=0.0.0.0
ENV PORT=3000
EXPOSE 3000
ENTRYPOINT ["node", "./server/index.mjs"]

36
Taskfile.yml Normal file
View File

@@ -0,0 +1,36 @@
version: '3'
dotenv: [ '.env' ]
tasks:
make:env:
cmds:
- '[ ! -f .env ] && cp .env.example .env; exit 0'
make:install:
cmds:
- '[ ! -d node_modules ] && npm install; exit 0'
local:run:
ignore_error: true
deps: [ make:env, make:install ]
cmds:
- npm run dev
docker:run:
deps: [ make:env ]
cmds:
- docker-compose -p $APP_NAME up -d
docker:stop:
cmds:
- docker-compose -p $APP_NAME down
docker:stop:rm:
cmds:
- docker-compose -p $APP_NAME down -v --remove-orphans
test:performance:
ignore_error: true
cmds:
- docker run --rm -i --network host grafana/k6 run --vus 1000 --duration 30s - < ./src/tests/performance/test_main_page.js

View File

@@ -0,0 +1,50 @@
server {
listen 80;
# default docker DNS
resolver 127.0.0.11 ipv6=off valid=10s;
# . files
location ~ /\.(?!well-known) {
deny all;
}
# logging
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
# reverse proxy
location / {
proxy_pass http://app:3000$request_uri;
proxy_set_header Host $host;
proxy_http_version 1.1;
# proxy headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
# proxy timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
# favicon.ico
location = /favicon.ico {
log_not_found off;
}
# robots.txt
location = /robots.txt {
log_not_found off;
}
# gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
}

60
docker-compose.yml Normal file
View File

@@ -0,0 +1,60 @@
version: '3'
services:
proxy_lb:
container_name: proxy_lb
image: nginx:latest
ports:
- '${PROXY_PORT:-80}:80'
- '${PROXY_PORT_SSL:-443}:443'
volumes:
- './config/nginx/proxy_lb.conf:/etc/nginx/conf.d/default.conf'
networks:
- c3d_net
depends_on:
- app
app:
# container_name: app
build:
context: .
dockerfile: Dockerfile
deploy:
mode: replicated
replicas: 2
expose:
- '${FORWARD_APP_PORT:-3000}'
# ports:
# - '${FORWARD_APP_PORT:-3000}:3000'
networks:
- c3d_net
depends_on:
- db
db:
container_name: db
image: 'postgres:latest'
ports:
- '${FORWARD_DB_PORT:-5432}:5432'
environment:
PGPASSWORD: '${DB_PASSWORD:-secret}'
POSTGRES_DB: '${DB_DATABASE}'
POSTGRES_USER: '${DB_USERNAME}'
POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
volumes:
- 'c3d_vol:/var/lib/postgresql/data'
networks:
- c3d_net
healthcheck:
test: [ "CMD", "pg_isready", "-q", "-d", "${DB_DATABASE}", "-U", "${DB_USERNAME}" ]
retries: 3
timeout: 5s
volumes:
c3d_vol:
driver: local
networks:
c3d_net:
driver: bridge

3284
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,11 @@
{ {
"name": "canvas3d",
"description": "Web application for affine transformations of three-dimensional figures",
"bugs": {
"url": "https://github.com/robonen/canvas-3d/issues?q=is:open is:issue label:bug"
},
"author": "Andrew Robonen <robonenandrew@gmail.com>",
"license": "MIT",
"private": true, "private": true,
"scripts": { "scripts": {
"build": "nuxt build", "build": "nuxt build",
@@ -14,8 +21,8 @@
"devDependencies": { "devDependencies": {
"@vueuse/core": "^9.3.1", "@vueuse/core": "^9.3.1",
"@vueuse/nuxt": "^9.3.1", "@vueuse/nuxt": "^9.3.1",
"nuxt": "^3.0.0",
"husky": "^8.0.2", "husky": "^8.0.2",
"nuxt": "3.0.0-rc.11",
"sass": "^1.55.0" "sass": "^1.55.0"
} }
} }

9
src/server/api/test.ts Normal file
View File

@@ -0,0 +1,9 @@
import {defineEventHandler} from 'h3';
export default defineEventHandler((event) => {
console.log('Request received');
return {
api: 'works',
};
});

View File

@@ -0,0 +1,7 @@
import http from 'k6/http';
import {sleep} from 'k6';
export default function () {
http.get('http://localhost');
sleep(1);
}