mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
ci: 🎨 Make CI Docker build more traditional, and probably work again too
This commit is contained in:
parent
7e0cc9e0a8
commit
ebcd38870f
230
.github/workflows/docker-publish.yml
vendored
230
.github/workflows/docker-publish.yml
vendored
|
|
@ -1,158 +1,102 @@
|
||||||
name: Docker
|
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:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["main"]
|
branches: [ "main" ]
|
||||||
tags: ["v*.*.*"]
|
# Publish semver tags as releases.
|
||||||
pull_request:
|
tags: [ 'v*.*.*' ]
|
||||||
branches: ["*"]
|
pull_request:
|
||||||
workflow_dispatch:
|
branches: [ "main" ]
|
||||||
inputs:
|
|
||||||
tag:
|
|
||||||
description: "Tag"
|
|
||||||
required: false
|
|
||||||
default: "v0.0.0"
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: ghcr.io
|
# Use docker.io for Docker Hub if empty
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
# github.repository as <account>/<repo>
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Build for ${{ matrix.platform }}
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
environment:
|
|
||||||
name: Production
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- os: ubuntu-latest #[self-hosted]
|
|
||||||
platform: linux/arm64
|
|
||||||
- os: ubuntu-latest
|
|
||||||
platform: linux/amd64
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
packages: write
|
|
||||||
id-token: write
|
|
||||||
|
|
||||||
steps:
|
runs-on: ubuntu-latest
|
||||||
- name: Prepare
|
permissions:
|
||||||
run: |
|
contents: read
|
||||||
platform=${{ matrix.platform }}
|
packages: write
|
||||||
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
|
# This is used to complete the identity challenge
|
||||||
echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}" >> $GITHUB_ENV
|
# with sigstore/fulcio when running outside of PRs.
|
||||||
|
id-token: write
|
||||||
|
|
||||||
- name: Checkout repository
|
steps:
|
||||||
uses: actions/checkout@v4
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set up QEMU
|
# Install the cosign tool except on PR
|
||||||
uses: docker/setup-qemu-action@v3
|
# 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'
|
||||||
|
|
||||||
|
- name: Setup QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
with:
|
||||||
|
platforms: all
|
||||||
|
|
||||||
- name: Setup Docker buildx
|
# Set up BuildKit Docker container builder to be able to build
|
||||||
uses: docker/setup-buildx-action@v3
|
# multi-platform images and export cache
|
||||||
|
# https://github.com/docker/setup-buildx-action
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3 # v3.0.0
|
||||||
|
|
||||||
- name: Log into registry ${{ env.REGISTRY }}
|
# Login against a Docker registry except on PR
|
||||||
if: github.event_name != 'pull_request'
|
# https://github.com/docker/login-action
|
||||||
uses: docker/login-action@v3
|
- name: Log into registry ${{ env.REGISTRY }}
|
||||||
with:
|
if: github.event_name != 'pull_request'
|
||||||
registry: ${{ env.REGISTRY }}
|
uses: docker/login-action@v3 # v3.0.0
|
||||||
username: ${{ github.actor }}
|
with:
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Extract Docker metadata
|
# Extract metadata (tags, labels) for Docker
|
||||||
id: meta
|
# https://github.com/docker/metadata-action
|
||||||
uses: docker/metadata-action@v5
|
- name: Extract Docker metadata
|
||||||
with:
|
id: meta
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
uses: docker/metadata-action@v5 # v5.0.0
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
|
||||||
- name: Build and push Docker image
|
# Build and push Docker image with Buildx (don't push on PR)
|
||||||
id: build
|
# https://github.com/docker/build-push-action
|
||||||
uses: docker/build-push-action@v5
|
- name: Build and push Docker image
|
||||||
with:
|
id: build-and-push
|
||||||
context: .
|
uses: docker/build-push-action@v5 # v5.0.0
|
||||||
file: Dockerfile
|
with:
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
context: .
|
||||||
cache-from: type=gha
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
cache-to: type=gha,mode=max
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
platforms: ${{ matrix.platform }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
|
platforms: linux/amd64,linux/arm64
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
- name: Export digest
|
# Sign the resulting Docker image digest except on PRs.
|
||||||
run: |
|
# This will only write to the public Rekor transparency log when the Docker
|
||||||
mkdir -p /tmp/digests
|
# repository is public to avoid leaking data. If you would like to publish
|
||||||
digest="${{ steps.build.outputs.digest }}"
|
# transparency data even for private images, pass --force to cosign below.
|
||||||
touch "/tmp/digests/${digest#sha256:}"
|
# https://github.com/sigstore/cosign
|
||||||
- name: Upload digest
|
- name: Sign the published Docker image
|
||||||
uses: actions/upload-artifact@v4
|
if: ${{ github.event_name != 'pull_request' }}
|
||||||
with:
|
env:
|
||||||
name: digests-${{ env.PLATFORM_PAIR }}
|
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
|
||||||
path: /tmp/digests/*
|
TAGS: ${{ steps.meta.outputs.tags }}
|
||||||
if-no-files-found: error
|
DIGEST: ${{ steps.build-and-push.outputs.digest }}
|
||||||
retention-days: 1
|
# This step uses the identity token to provision an ephemeral certificate
|
||||||
|
# against the sigstore community Fulcio instance.
|
||||||
merge:
|
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
|
||||||
name: Merge digests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
environment:
|
|
||||||
name: Production
|
|
||||||
needs:
|
|
||||||
- build
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
packages: write
|
|
||||||
id-token: write
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Prepare
|
|
||||||
run: |
|
|
||||||
echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Download digests
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
path: /tmp/digests
|
|
||||||
pattern: digests-*
|
|
||||||
merge-multiple: true
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Docker meta
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Create manifest list and push
|
|
||||||
working-directory: /tmp/digests
|
|
||||||
run: |
|
|
||||||
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
|
|
||||||
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
|
|
||||||
|
|
||||||
- name: Inspect image
|
|
||||||
run: |
|
|
||||||
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
|
|
||||||
# deploy:
|
|
||||||
# name: Deploy
|
|
||||||
# runs-on: ubuntu-latest
|
|
||||||
# environment:
|
|
||||||
# name: Production
|
|
||||||
# needs:
|
|
||||||
# - merge
|
|
||||||
# steps:
|
|
||||||
# - name: Pull and restart container
|
|
||||||
# uses: appleboy/ssh-action@v1.0.3
|
|
||||||
# with:
|
|
||||||
# host: ${{ secrets.HOST }}
|
|
||||||
# username: ${{ secrets.USERNAME }}
|
|
||||||
# key: ${{ secrets.KEY }}
|
|
||||||
# passphrase: ${{ secrets.PASSPHRASE }}
|
|
||||||
# script: docker compose -f /home/jessew/docker/lysand/docker-compose.yml pull && docker compose -f /home/jessew/docker/lysand/docker-compose.yml down && docker compose -f /home/jessew/docker/lysand/docker-compose.yml up -d
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue