Added Dockerfile for standalone image

pull/12/head
Guus van Meerveld 1 year ago
parent 65634c75b9
commit eb9a891807
Signed by: Guusvanmeerveld
GPG Key ID: 2BA7D7912771966E

@ -0,0 +1,20 @@
**
!/nginx
!/entrypoint.sh
!/packages/server/src
!/packages/server/package.json
!/packages/server/yarn.lock
!/packages/server/tsconfig.build.json
!/packages/server/tsconfig.json
!/packages/client/src
!/packages/client/index.html
!/packages/client/splashscreen.html
!/packages/client/tsconfig.json
!/packages/client/tsconfig.node.json
!/packages/client/vite.config.ts
!/packages/client/package.json
!/packages/client/yarn.lock

@ -63,7 +63,7 @@ jobs:
with:
context: packages/client
push: true
tags: guusvanmeerveld/mail-client:latest
tags: guusvanmeerveld/dust-mail:client
# Cache
cache-from: type=gha

@ -74,7 +74,7 @@ jobs:
with:
push: true
context: packages/server
tags: guusvanmeerveld/mail-server:latest
tags: guusvanmeerveld/dust-mail:server
# Cache
cache-from: type=gha

@ -0,0 +1,39 @@
name: Deploy Standalone
on:
workflow_run:
workflows: ["Deploy Client", "Deploy Server"]
branches: [main]
types:
- completed
jobs:
docker:
name: Build Docker image
runs-on: ubuntu-latest
needs: test
steps:
- name: Setup
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# Login
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: guusvanmeerveld
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Build & Push
- name: Build Dockerfile and push
uses: docker/build-push-action@v2
with:
push: true
context: .
tags: guusvanmeerveld/dust-mail:standalone
# Cache
cache-from: type=gha
cache-to: type=gha,mode=max

@ -0,0 +1,60 @@
#
# This Dockerfile combines both the client and the server into a single container
#
ARG BASE_IMAGE=node:12-alpine
# Build client
FROM $BASE_IMAGE AS client-builder
WORKDIR /app
COPY ./packages/client .
RUN yarn install --frozen-lockfile
ENV NODE_ENV "production"
ENV VITE_DEFAULT_SERVER "/api"
ENV VITE_APP_NAME "Dust-Mail"
RUN yarn build
# Build server
FROM $BASE_IMAGE AS server-builder
WORKDIR /app
COPY ./packages/server .
RUN yarn install --frozen-lockfile
RUN yarn build
RUN yarn install --production --ignore-scripts --prefer-offline
# Run nginx + api
FROM nginx:stable-alpine as runner
RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/v3.11/main/ nodejs=12.22.6-r0
COPY --from=client-builder /app/dist /client
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
WORKDIR /server
ENV NODE_ENV "production"
ENV BASE_PATH "api"
COPY --from=server-builder /app/dist ./dist
COPY --from=server-builder /app/node_modules ./node_modules
COPY --from=server-builder /app/package.json ./package.json
COPY entrypoint.sh .
CMD [ "./entrypoint.sh" ]

@ -0,0 +1,8 @@
version: '3.3'
services:
app:
build: .
container_name: dust-mail
ports:
- 3000:80

@ -0,0 +1,3 @@
#!/bin/sh
nginx -g "daemon off;" & node dist/main && fg

@ -0,0 +1,14 @@
server {
listen 80;
server_name localhost;
location / {
root /client;
index index.html;
expires 30d;
}
location /api {
proxy_pass http://127.0.0.1:3000;
}
}

@ -1,4 +1,4 @@
FROM node:16-alpine AS builder
FROM node:12-alpine AS builder
WORKDIR /app
@ -8,6 +8,8 @@ RUN yarn install --frozen-lockfile
ENV NODE_ENV "production"
ENV VITE_APP_NAME "Dust-Mail"
RUN yarn build

@ -2,7 +2,7 @@ version: '3.3'
services:
app:
container_name: dust-mail
container_name: dust-mail-client
build: .
ports:
- 3000:80

@ -20,9 +20,7 @@ FROM $BASE_IMAGE AS runner
WORKDIR /app
ENV NODE_ENV production
RUN mkdir /apk
ENV NODE_ENV "production"
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules

@ -3,6 +3,6 @@ version: '3.3'
services:
app:
build: .
container_name: mail-server
container_name: dust-mail-server
ports:
- 3000:3000

@ -1,14 +1,18 @@
import { NestFactory } from "@nestjs/core";
import helmet from "helmet";
import { AppModule } from "./app.module";
import { port } from "./constants";
import { AppLogger } from "./utils/logger";
import { NestFactory } from "@nestjs/core";
import helmet from "helmet";
async function bootstrap() {
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
const app = await NestFactory.create(AppModule, { logger: new AppLogger() });
if (process.env.BASE_PATH) app.setGlobalPrefix(process.env.BASE_PATH);
app.enableCors();
app.use(helmet());

Loading…
Cancel
Save