From 15cfad7ebd67fbaa4bfbf085e14efe3303c0b3b4 Mon Sep 17 00:00:00 2001 From: mzrtamp Date: Thu, 7 Mar 2024 14:05:41 +0700 Subject: [PATCH] feat: dockerize this project --- .github/workflows/docker-build.yml | 18 +++++++++++++ Dockerfile | 43 ++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 .github/workflows/docker-build.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..f9ccfc8 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,18 @@ +name: Build & Push Docker Image to container image registry + +on: + release: + types: [created] + push: + branches: + - main + pull_request: + branches: + - main + paths: + - "Dockerfile" + +jobs: + docker: + uses: stegripe/workflows/.github/workflows/docker-build.yml@main + secrets: inherit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a068b3f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +FROM ghcr.io/hazmi35/node:21-dev-alpine as build-stage + +# Prepare pnpm with corepack (experimental feature) +RUN corepack enable && corepack prepare pnpm@latest + +# Copy package.json, lockfile and npm config files +COPY package.json pnpm-lock.yaml *.npmrc ./ + +# Fetch dependencies to virtual store +RUN pnpm fetch + +# Install dependencies +RUN pnpm install --offline --frozen-lockfile + +# Copy Project files +COPY . . + +# Build TypeScript Project +RUN pnpm run build + +# Prune devDependencies +RUN pnpm prune --production + +# Get ready for production +FROM ghcr.io/hazmi35/node:21-alpine + +LABEL name "linkbio" +LABEL maintainer "Stegripe " + +# Copy needed files +COPY --from=build-stage /tmp/build/package.json . +COPY --from=build-stage /tmp/build/.next/ ./.next +COPY --from=build-stage /tmp/build/node_modules ./node_modules +COPY --from=build-stage /tmp/build/next.config.js ./ + +# Additional Environment Variables +ENV NODE_ENV production + +# Expose the port the app runs on +EXPOSE 3000 + +# Start the app with node +CMD ["npm", "run", "start"]