Skip to content

Commit

Permalink
build: add docker build in actions (#33)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexandre Chau <accounts@chau.moe>
  • Loading branch information
Thechi2000 and codeofmochi authored Aug 17, 2023
1 parent 6db75ca commit 33edb97
Show file tree
Hide file tree
Showing 18 changed files with 6,050 additions and 21,236 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Docker

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
push:
branches: ["main"]
# Publish semver tags as releases.
tags: ["v*.*.*"]
pull_request:
branches: ["main"]

# abort running jobs if newer version is detected on same branch
concurrency:
group: ${{ github.head_ref || github.ref }}
cancel-in-progress: true

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
BASE_IMAGE_NAME: ${{ github.repository }}

jobs:
build:
strategy:
matrix:
directory: [strapi, app]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
with:
cosign-release: "v2.1.1"

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}-${{ matrix.directory }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: ${{ matrix.directory }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"path": "docker",
"args": ["exec", "-it", "clic-postgres", "/bin/bash"],
"overrideName": true
},
"app": {
"path": "docker",
"args": ["exec", "-it", "clic-app", "/bin/bash"],
"overrideName": true
}
},
"terminal.integrated.profiles.windows": {
Expand All @@ -39,6 +44,11 @@
"path": "docker",
"args": ["exec", "-it", "clic-postgres", "/bin/bash"],
"overrideName": true
},
"app": {
"path": "docker",
"args": ["exec", "-it", "clic-app", "/bin/bash"],
"overrideName": true
}
},
"terminal.integrated.profiles.osx": {
Expand All @@ -51,6 +61,11 @@
"path": "docker",
"args": ["exec", "-it", "clic-postgres", "/bin/bash"],
"overrideName": true
},
"app": {
"path": "docker",
"args": ["exec", "-it", "clic-app", "/bin/bash"],
"overrideName": true
}
},
"[jsonc]": {
Expand Down
2 changes: 2 additions & 0 deletions app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.next/**
node_modules/**
1 change: 0 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local
Expand Down
18 changes: 18 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:18-alpine

RUN apk update
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /app
COPY package.json package-lock.json ./
RUN npm config set fetch-retry-maxtimeout 600000 -g && npm ci

COPY . .
RUN npm run build

# switch to unprivileged user from node base image
RUN chown -R node .
USER node

CMD [ "npm", "start" ]
Loading

0 comments on commit 33edb97

Please sign in to comment.