Skip to content

Commit

Permalink
feat: add docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Vann-Dev committed May 5, 2024
1 parent 580ff6a commit 4947359
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build and Push Docker Image
on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@8459bc0c7e3759cdf591f513d9f141a95fef0a8f

- name: Lowercase repository
id: repository
uses: ASzc/change-string-case-action@ccb130a4e483d3e86287289183704dc9bf53e77e
with:
string: ${{ github.repository }}

- name: Create Tags
id: tags
uses: ASzc/change-string-case-action@ccb130a4e483d3e86287289183704dc9bf53e77e
with:
string: ${{ github.event_name == 'release' && 'latest' || github.ref_name }}

- name: Log in to GitHub Container Registry
uses: docker/login-action@5f4866a30a54f16a52d2ecb4a3898e9e424939cf
if: ${{ github.event_name != 'pull_request' }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@eb539f44b153603ccbfbd98e2ab9d4d0dcaf23a4
with:
context: .
push: true
tags: ghcr.io/${{ steps.repository.outputs.lowercase }}:${{ steps.tags.outputs.lowercase }}
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ghcr.io/hazmi35/node:21-alpine as build-stage

WORKDIR /tmp/build

RUN corepack enable && corepack prepare pnpm@latest

COPY . .

RUN pnpm install --frozen-lockfile

RUN pnpm run build

RUN pnpm prune --production

FROM ghcr.io/hazmi35/node:21-alpine

RUN corepack enable && corepack prepare pnpm@latest

COPY --from=build-stage /tmp/build/package.json .
COPY --from=build-stage /tmp/build/pnpm-lock.yaml .
COPY --from=build-stage /tmp/build/node_modules ./node_modules
COPY --from=build-stage /tmp/build/.next .next
COPY --from=build-stage /tmp/build/next.config.mjs ./next.config.mjs
COPY --from=build-stage /tmp/build/public ./public

CMD ["pnpm", "run", "start"]

0 comments on commit 4947359

Please sign in to comment.