V2bX/.github/workflows/Publish Docker image.yml

113 lines
3.2 KiB
YAML
Raw Normal View History

2023-12-17 01:01:52 -05:00
name: Publish Docker image
2025-03-04 07:28:24 -05:00
2023-12-17 01:01:52 -05:00
on:
workflow_dispatch:
2024-07-29 12:28:39 -04:00
release:
types: [published]
2023-12-17 01:01:52 -05:00
pull_request:
branches:
- 'dev_new'
2025-03-04 07:28:24 -05:00
2023-12-17 01:01:52 -05:00
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/v2bx
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
2025-03-04 07:53:05 -05:00
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
2023-12-17 01:01:52 -05:00
- name: Checkout
uses: actions/checkout@v4
2025-03-04 07:28:24 -05:00
2023-12-17 01:01:52 -05:00
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
2025-03-04 07:28:24 -05:00
2023-12-17 01:01:52 -05:00
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
2025-03-04 07:53:05 -05:00
2023-12-17 01:01:52 -05:00
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
2025-03-04 07:53:05 -05:00
2023-12-17 01:01:52 -05:00
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
2025-03-04 07:53:05 -05:00
2023-12-17 01:01:52 -05:00
- name: Build and push by digest
id: build
2025-03-04 07:53:05 -05:00
uses: docker/build-push-action@v6
2023-12-17 01:01:52 -05:00
with:
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
2025-03-04 07:53:05 -05:00
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
2023-12-17 01:01:52 -05:00
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
echo "${digest#sha256:}" > "/tmp/digests/${digest#sha256:}"
2025-03-04 07:53:05 -05:00
2023-12-17 01:01:52 -05:00
- name: Upload digest
2025-03-04 07:28:24 -05:00
uses: actions/upload-artifact@v4
2023-12-17 01:01:52 -05:00
with:
2025-03-04 07:53:05 -05:00
name: digests-${{ env.PLATFORM_PAIR }}
2023-12-17 01:01:52 -05:00
path: /tmp/digests/*
if-no-files-found: error
2025-03-04 07:53:05 -05:00
retention-days: 1
2023-12-17 01:01:52 -05:00
merge:
runs-on: ubuntu-latest
2025-03-04 07:53:05 -05:00
needs:
- build
2023-12-17 01:01:52 -05:00
steps:
2025-03-04 07:53:05 -05:00
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
2023-12-17 01:01:52 -05:00
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
2025-03-04 07:28:24 -05:00
2023-12-17 01:01:52 -05:00
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
2025-03-04 07:28:24 -05:00
2023-12-17 01:01:52 -05:00
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
2025-03-04 07:28:24 -05:00
2023-12-17 01:01:52 -05:00
- name: Create manifest list and push
run: |
2025-03-04 07:28:24 -05:00
cd /tmp/digests
tags=$(echo '${{ steps.meta.outputs.json }}' | jq -cr '.tags | map("-t " + .) | join(" ")')
images=$(printf "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s " $(find . -type f -exec cat {} \;))
echo "Creating manifest with tags: $tags"
echo "Using images: $images"
docker buildx imagetools create $tags $images
2023-12-17 01:01:52 -05:00
- name: Inspect image
run: |
2025-03-04 07:28:24 -05:00
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}