Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/_node-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Common CI for Node.js projects

on:
workflow_call:
inputs:
image_name:
description: The name of the image to build
required: true
type: string

image_registry:
description: The registry to push the image to
required: true
type: string

image_push:
description: Whether to push the image to the registry
required: true
type: boolean

release_version:
description: Release version
default: dev
type: string

jobs:
build-image:
name: Build Image
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
with:
platforms: linux/amd64,linux/arm64

- name: Login Container Registry
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1

- name: Docker meta
id: meta
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
with:
images: ${{ inputs.image_registry }}/${{ inputs.image_name }}
tags: |
type=ref,event=pr
type=raw,value=${{ inputs.release_version }},enable=${{ inputs.image_push && inputs.release_version != 'dev' }}

- name: Build and push
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ inputs.image_push }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
43 changes: 8 additions & 35 deletions .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- main
- feat/ci-pr
types:
- opened
- synchronize
Expand All @@ -20,38 +21,10 @@ concurrency:

jobs:
# build:
build-image:
name: Build Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
with:
platforms: linux/amd64,linux/arm64

- name: Login Container Registry
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1

- name: Build image
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
platforms: linux/amd64,linux/arm64
push: false
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=XXX
COMMIT_ID=${{ github.sha }}
secrets: |
NPM_TOKEN=${{ secrets.NPM_TOKEN }}
call-node-ci:
name: Call Node CI
uses: ./.github/workflows/_node-ci.yml
with:
image_name: ${{ github.repository }}
image_registry: ghcr.io
image_push: false
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ WORKDIR /app

# Copy only the production dependencies
COPY --from=build /app/dist /app/dist
COPY --from=build /app/package.json /app/package.json
COPY --from=build /app/package-lock.json /app/package-lock.json
COPY --from=build /app/node_modules /app/node_modules

# Set environment variables
ENV NODE_ENV=production

# Set port
ARG PORT=4242
ENV PORT=${PORT}

# Default command for production
CMD ["/nodejs/bin/node", "/app/dist/app.js"]
CMD ["dist/app.js"]
Loading