Merge pull request #113 from HideyoshiSolutions/chore/better-docker-build
chore: better docker build
This commit is contained in:
@@ -1,12 +1,34 @@
|
|||||||
node_modules/*
|
# Node and build artifacts
|
||||||
dist/*
|
node_modules
|
||||||
.k8s/*
|
dist
|
||||||
.github/*
|
.DS_Store
|
||||||
|
npm-debug.log
|
||||||
.gitignore
|
yarn-error.log
|
||||||
.dockerignore
|
.lock-wscript
|
||||||
Dockerfile
|
|
||||||
README.md
|
|
||||||
|
|
||||||
|
# Local env files and editor stuff
|
||||||
.env
|
.env
|
||||||
.secret
|
.env.*
|
||||||
|
.secrets
|
||||||
|
.secrets.*
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
*.swp
|
||||||
|
|
||||||
|
# Git
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
|
||||||
|
# Kubernetes manifests, CI, Dockerfiles (if you intentionally want them out of build context)
|
||||||
|
.k8s
|
||||||
|
.github
|
||||||
|
Dockerfile
|
||||||
|
|
||||||
|
# tests and misc
|
||||||
|
coverage
|
||||||
|
tests
|
||||||
|
|
||||||
|
# keep package files
|
||||||
|
!package*.json
|
||||||
|
!package-lock.json
|
||||||
|
|
||||||
|
|||||||
8
.github/workflows/deploy.yml
vendored
8
.github/workflows/deploy.yml
vendored
@@ -80,12 +80,8 @@ jobs:
|
|||||||
tags: |
|
tags: |
|
||||||
${{ env.IMAGE_LATEST }}
|
${{ env.IMAGE_LATEST }}
|
||||||
${{ env.IMAGE_SHA }}
|
${{ env.IMAGE_SHA }}
|
||||||
cache-from: |
|
cache-from: type=gha
|
||||||
type=registry,ref=ghcr.io/hideyoshisolutions/frontend-hideyoshi.com:cache-${{ github.ref_name }}-amd64
|
cache-to: type=gha,mode=max
|
||||||
type=registry,ref=ghcr.io/hideyoshisolutions/frontend-hideyoshi.com:cache-${{ github.ref_name }}-arm64
|
|
||||||
cache-to: |
|
|
||||||
type=registry,ref=ghcr.io/hideyoshisolutions/frontend-hideyoshi.com:cache-${{ github.ref_name }}-amd64,mode=max,platform=linux/amd64
|
|
||||||
type=registry,ref=ghcr.io/hideyoshisolutions/frontend-hideyoshi.com:cache-${{ github.ref_name }}-arm64,mode=max,platform=linux/arm64
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
needs: [docker]
|
needs: [docker]
|
||||||
|
|||||||
28
Dockerfile
28
Dockerfile
@@ -1,27 +1,37 @@
|
|||||||
FROM node:22.12-alpine AS base
|
FROM node:22.12-alpine AS base
|
||||||
|
|
||||||
FROM base AS build
|
# set a working dir in the base image so all stages inherit it
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
ENV PATH=/app/node_modules/.bin:$PATH
|
||||||
|
|
||||||
|
# Dependency stage: cache node_modules by only copying package files first
|
||||||
|
FROM base AS deps
|
||||||
|
# copy package manifests first so this layer is cached when source files change
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm install
|
# if you have a lockfile, copy it too (better reproducibility & cacheability)
|
||||||
|
COPY package-lock.json ./
|
||||||
|
# Use npm ci for deterministic installs and faster caching
|
||||||
|
RUN npm ci --prefer-offline --no-audit --no-fund
|
||||||
|
|
||||||
|
# Build stage: only run the build after deps layer is ready
|
||||||
|
FROM deps AS build
|
||||||
|
# copy the rest of the source
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN npm run build:prod
|
RUN npm run build:prod
|
||||||
|
|
||||||
|
# Production stage: keep the final image small and only include what's necessary
|
||||||
FROM base AS prod
|
FROM node:22.12-alpine AS prod
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
COPY --from=build /app/node_modules ./node_modules
|
# copy production node_modules from the deps stage (they include prod + dev if needed for build)
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY --from=build /app/dist ./dist
|
COPY --from=build /app/dist ./dist
|
||||||
COPY --from=build /app/server.js ./
|
COPY --from=build /app/server.js ./
|
||||||
COPY --from=build /app/set_env.js ./
|
COPY --from=build /app/set_env.js ./
|
||||||
COPY --from=build /app/package*.json ./
|
COPY --from=build /app/package*.json ./
|
||||||
|
|
||||||
|
# expose single well-known port instead of a wide range
|
||||||
EXPOSE 5000-7000
|
EXPOSE 5000
|
||||||
|
|
||||||
CMD ["npm", "run", "start:prod"]
|
CMD ["npm", "run", "start:prod"]
|
||||||
|
|||||||
Reference in New Issue
Block a user