138 lines
3.8 KiB
YAML
138 lines
3.8 KiB
YAML
name: ci
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- staging
|
|
- dev
|
|
tags:
|
|
- '*'
|
|
|
|
jobs:
|
|
docker:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- service: frontend
|
|
context: frontend
|
|
dockerfile: frontend/Dockerfile
|
|
- service: backend
|
|
context: backend
|
|
dockerfile: backend/Dockerfile
|
|
|
|
steps:
|
|
- name: Checkout with submodules
|
|
uses: actions/checkout@v4
|
|
with:
|
|
submodules: recursive
|
|
|
|
- name: Derive repository metadata
|
|
id: repo_meta
|
|
run: |
|
|
repo="${GITHUB_REPOSITORY}"
|
|
owner="${repo%%/*}"
|
|
name="${repo##*/}"
|
|
echo "repo_owner=$owner" >> "$GITHUB_OUTPUT"
|
|
echo "repo_name=$name" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Compute base tag
|
|
id: compute_tag
|
|
env:
|
|
GITHUB_SHA: ${{ github.sha }}
|
|
GITHUB_REF_TYPE: ${{ github.ref_type }}
|
|
GITHUB_REF_NAME: ${{ github.ref_name }}
|
|
run: |
|
|
sha="${GITHUB_SHA}"
|
|
ref_type="${GITHUB_REF_TYPE}"
|
|
ref_name="${GITHUB_REF_NAME}"
|
|
|
|
short="${sha:0:7}"
|
|
tag="$short"
|
|
|
|
if [ "$ref_type" = "tag" ]; then
|
|
tag="$ref_name"
|
|
elif [ "$ref_name" = "dev" ]; then
|
|
tag="${tag}-dev"
|
|
elif [ "$ref_name" = "staging" ]; then
|
|
tag="${tag}-staging"
|
|
fi
|
|
|
|
echo "base_tag=$tag" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Login to local registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ${{ vars.REGISTRY_URL }}
|
|
username: ${{ vars.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Login to GHCR
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ vars.GHCR_USERNAME }}
|
|
password: ${{ secrets.GHCR_PASSWORD }}
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Determine branch alias tag
|
|
id: branch_alias
|
|
env:
|
|
REF_NAME: ${{ github.ref_name }}
|
|
run: |
|
|
alias=""
|
|
case "${REF_NAME}" in
|
|
dev) alias="latest-dev" ;;
|
|
staging) alias="latest-staging" ;;
|
|
main) alias="latest" ;;
|
|
esac
|
|
echo "alias=$alias" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Assemble image tags
|
|
id: tag_list
|
|
env:
|
|
REGISTRY_URL: ${{ vars.REGISTRY_URL }}
|
|
REPO_NAME: ${{ steps.repo_meta.outputs.repo_name }}
|
|
SERVICE: ${{ matrix.service }}
|
|
BASE_TAG: ${{ steps.compute_tag.outputs.base_tag }}
|
|
GIT_SHA: ${{ github.sha }}
|
|
BRANCH_ALIAS: ${{ steps.branch_alias.outputs.alias }}
|
|
run: |
|
|
if [ -n "${REGISTRY_URL}" ]; then
|
|
repo_tag="${REGISTRY_URL}/${REPO_NAME}-${SERVICE}"
|
|
else
|
|
repo_tag="${REPO_NAME}-${SERVICE}"
|
|
fi
|
|
ghcr_tag="ghcr.io/papercrate-dms/${REPO_NAME}-${SERVICE}"
|
|
|
|
tags="${repo_tag}:${BASE_TAG}\n${repo_tag}:${GIT_SHA}\n${ghcr_tag}:${BASE_TAG}\n${ghcr_tag}:${GIT_SHA}"
|
|
|
|
if [ -n "${BRANCH_ALIAS}" ]; then
|
|
tags="${tags}\n${repo_tag}:${BRANCH_ALIAS}\n${ghcr_tag}:${BRANCH_ALIAS}"
|
|
fi
|
|
|
|
{
|
|
echo "tags<<'EOF'"
|
|
echo "${tags}"
|
|
echo EOF
|
|
} >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build and Push ${{ matrix.service }} Image
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: ${{ matrix.context }}
|
|
file: ${{ matrix.dockerfile }}
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
provenance: false
|
|
tags: ${{ steps.tag_list.outputs.tags }}
|