Skip to content

Commit

Permalink
Merge pull request #22 from ManoManoTech/chore-docker-workflow
Browse files Browse the repository at this point in the history
chore(docker): Add Github Actions to build and push Docker image
  • Loading branch information
greg0ire authored Jun 21, 2024
2 parents df38b9b + 1e10168 commit 58192c9
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Build project, then Docker Image and publish to Github Artifact Registry

on:
push:
# Publish semver tags as releases.
tags: ['v*.*.*']

env:
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
name: Build from source to dist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
- run: yarn install
- run: yarn build
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: dist

docker:
name: Build Docker Image and publish to Github Artifact Registry
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: ↙️ Download build artifact
uses: actions/download-artifact@v4
with:
name: dist
path: dist

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.build-and-push.outputs.digest }}
push-to-registry: true
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:18

RUN mkdir -p /home/node/app \
&& chown -R node:node /home/node/app

WORKDIR /home/node/app

ENV NODE_ENV=production

EXPOSE 3000

USER node

COPY --chown=node:node package.json /home/node/app/package.json
COPY --chown=node:node yarn.lock /home/node/app/yarn.lock
COPY --chown=node:node dist /home/node/app/dist

RUN yarn install

CMD ["node", "dist/src/index.js"]

0 comments on commit 58192c9

Please sign in to comment.