Skip to content

Commit

Permalink
feat: build docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed Oct 13, 2023
1 parent 02b3594 commit 64eb019
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
43 changes: 43 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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 }}
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 3 additions & 3 deletions src/setup-dev-server.ts
Original file line number Diff line number Diff line change
@@ -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<App>> {
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),
Expand Down Expand Up @@ -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)
})
Expand Down

0 comments on commit 64eb019

Please sign in to comment.