mirror of
https://github.com/Portabase/agent.git
synced 2026-09-10 18:16:55 +00:00
135 lines
3.9 KiB
YAML
135 lines
3.9 KiB
YAML
name: GHCR Publish
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
version:
|
|
required: true
|
|
type: string
|
|
ref:
|
|
required: true
|
|
type: string
|
|
add_latest:
|
|
required: false
|
|
type: boolean
|
|
default: false
|
|
dockerfile:
|
|
required: false
|
|
type: string
|
|
default: "./docker/Dockerfile"
|
|
target:
|
|
required: false
|
|
type: string
|
|
default: "prod"
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
jobs:
|
|
build:
|
|
name: Build ${{ matrix.platform }}
|
|
runs-on: ${{ matrix.platform == 'linux/amd64' && 'ubuntu-latest' || 'ubuntu-24.04-arm' }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
platform: [ linux/amd64, linux/arm64 ]
|
|
steps:
|
|
- name: Prepare vars
|
|
id: prep
|
|
run: |
|
|
ARCH="${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}"
|
|
echo "arch=$ARCH" >> "$GITHUB_OUTPUT"
|
|
echo "image=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/agent" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ inputs.ref }}
|
|
fetch-depth: 1
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push by digest
|
|
id: build
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: ${{ inputs.dockerfile }}
|
|
platforms: ${{ matrix.platform }}
|
|
target: ${{ inputs.target }}
|
|
provenance: false
|
|
outputs: type=image,name=${{ steps.prep.outputs.image }},push-by-digest=true,name-canonical=true,push=true
|
|
cache-from: type=gha,scope=ghcr-${{ steps.prep.outputs.arch }}
|
|
cache-to: type=gha,mode=max,scope=ghcr-${{ steps.prep.outputs.arch }},ignore-error=true
|
|
|
|
- name: Export digest
|
|
env:
|
|
DIGEST: ${{ steps.build.outputs.digest }}
|
|
run: |
|
|
mkdir -p /tmp/digests
|
|
touch "/tmp/digests/${DIGEST#sha256:}"
|
|
|
|
- name: Upload digest
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: digest-${{ steps.prep.outputs.arch }}
|
|
path: /tmp/digests/*
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
merge:
|
|
name: Create multi-arch manifest
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
steps:
|
|
- name: Prepare vars
|
|
id: prep
|
|
run: echo "image=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/agent" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Download digests
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: /tmp/digests
|
|
pattern: digest-*
|
|
merge-multiple: true
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract Docker metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ steps.prep.outputs.image }}
|
|
tags: |
|
|
type=semver,pattern={{version}},value=${{ inputs.version }}
|
|
type=semver,pattern={{major}}.{{minor}},value=${{ inputs.version }}
|
|
type=semver,pattern={{major}},value=${{ inputs.version }}
|
|
type=raw,value=latest,enable=${{ inputs.add_latest }}
|
|
|
|
- name: Create and push manifest list
|
|
working-directory: /tmp/digests
|
|
run: |
|
|
docker buildx imagetools create \
|
|
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
|
|
$(printf '${{ steps.prep.outputs.image }}@sha256:%s ' *)
|
|
|
|
- name: Inspect
|
|
run: docker buildx imagetools inspect ${{ steps.prep.outputs.image }}:${{ inputs.version }}
|