diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml new file mode 100644 index 0000000..a7aea29 --- /dev/null +++ b/.github/workflows/build-image.yaml @@ -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 }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ca401b1 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file