diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..3c3629e6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..c903750a --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,43 @@ +name: build docker + +on: + push: + tags: + - v* + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to coding registry + uses: docker/login-action@v2 + with: + registry: bangbang93-docker.pkg.coding.net + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract Git Tag + run: echo "GIT_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v4 + env: + IMAGE_TAG: ${{ env.GIT_TAG }} + IMAGE_NAME: bangbang93-docker.pkg.coding.net/mirrors/bangbang93/freyja + with: + push: true + cache-from: type=gha + cache-to: type=gha,mode=max + tags: | + ${{ env.IMAGE_NAME }}:latest + ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..6141abb0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +ARG BASE_IMAGE=node:18.18.0-alpine +FROM $BASE_IMAGE AS build + +WORKDIR /app + +COPY package.json package-lock.json ./ +RUN npm ci + +COPY client ./client +RUN npm run build:client +COPY src ./src +COPY tsconfig.* nest-cli.json ./ +RUN npm run build:server + + +FROM $BASE_IMAGE AS dependencies + +WORKDIR /app + +COPY package.json package-lock.json ./ +RUN npm ci --omit=dev + +FROM $BASE_IMAGE AS release + +RUN apk add --no-cache tini + +WORKDIR /app + +COPY public public +COPY --from=dependencies /app/node_modules ./node_modules +COPY --from=build /app/client/dist ./client/dist +COPY --from=build /app/dist ./dist + +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["node", "--enable-source-maps", "dist/main.js"] diff --git a/src/setup-dev-server.ts b/src/setup-dev-server.ts index a64e97f9..52ccee20 100644 --- a/src/setup-dev-server.ts +++ b/src/setup-dev-server.ts @@ -1,11 +1,11 @@ import {Application} from 'express' +import {join} from 'path' import {App} from 'vue' import webpack from 'webpack' -import wdm from 'webpack-dev-middleware' -const path = require('path') export async function setupDevServer(app: Application): Promise<(args: unknown) => Promise> { + const wdm = require('webpack-dev-middleware') const [clientConfig, adminConfig, serverConfig] = await Promise.all([ import('./webpack/webpack.conf').then((m) => m.default), import('./webpack/webpack.admin').then((m) => m.default), @@ -38,7 +38,7 @@ export async function setupDevServer(app: Application): Promise<(args: unknown) statJson?.warnings?.forEach((err) => console.warn(err)) if (statJson?.errors?.length) return reject(statJson.errors) - import(path.join(clientConfig.output?.path, 'server/server.js')) + import(join(clientConfig.output?.path ?? '', 'server/server.js')) .then((e) => resolve(e.default)) .catch(reject) })