Skip to content

Commit

Permalink
Merge pull request #1 from JuribaDev/add-docker-files
Browse files Browse the repository at this point in the history
add docker files and some libraries
  • Loading branch information
JuribaDev authored Aug 22, 2024
2 parents cda63ec + 7c2d7ed commit f5b22e5
Show file tree
Hide file tree
Showing 8 changed files with 2,139 additions and 167 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches:
- main
pull_request:
branches:
- main

permissions:
actions: read
Expand Down
21 changes: 21 additions & 0 deletions apps/client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Build stage
FROM docker.io/node:lts-alpine3.20 AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build -- --prod

# Production stage
FROM nginx:stable-alpine
COPY --from=build /app/dist/client /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
RUN chown -R nginx:nginx /usr/share/nginx/html && chmod -R 755 /usr/share/nginx/html && \
chown -R nginx:nginx /var/cache/nginx && \
chown -R nginx:nginx /var/log/nginx && \
chown -R nginx:nginx /etc/nginx/conf.d
RUN touch /var/run/nginx.pid && \
chown -R nginx:nginx /var/run/nginx.pid
USER nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
49 changes: 49 additions & 0 deletions apps/client/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;

location / {
try_files $uri $uri/ /index.html;
}

add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self' http://localhost:3000;" always;

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;
}
}
4 changes: 4 additions & 0 deletions apps/client/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@
}
},
"defaultConfiguration": "production"
},
"docker-build": {
"dependsOn": ["build"],
"command": "docker build -f apps/client/Dockerfile . -t client"
}
}
}
21 changes: 21 additions & 0 deletions apps/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Build stage
FROM docker.io/node:lts-alpine3.20 AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# Production stage
FROM nginx:stable-alpine
RUN apk add --no-cache dumb-init
ENV NODE_ENV production
WORKDIR /app
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nestjs -u 1001
RUN chown -R nestjs:nodejs /app
USER nestjs
EXPOSE 3000
CMD ["dumb-init", "node", "dist/main"]
4 changes: 4 additions & 0 deletions apps/server/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"options": {
"jestConfig": "apps/server/jest.config.ts"
}
},
"docker-build": {
"dependsOn": ["build"],
"command": "docker build -f apps/server/Dockerfile . -t server"
}
}
}
Loading

0 comments on commit f5b22e5

Please sign in to comment.