mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
improved container image release workflow
This commit is contained in:
parent
cd94c07232
commit
8561ddb043
121
.github/workflows/container-image-release.yml
vendored
121
.github/workflows/container-image-release.yml
vendored
@ -1,24 +1,34 @@
|
||||
name: Container Image Release
|
||||
concurrency: production
|
||||
concurrency:
|
||||
group: ${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
permissions:
|
||||
packages: write
|
||||
contents: read
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
image_tag:
|
||||
description: 'Image tag'
|
||||
required: true
|
||||
default: 'nightly-<put_date_here>'
|
||||
|
||||
env:
|
||||
REGISTRY_IMAGE: ghcr.io/jikan-me/jikan-rest
|
||||
|
||||
jobs:
|
||||
release-app-image:
|
||||
build-app-image:
|
||||
runs-on: ubuntu-latest
|
||||
name: Release App container image
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
platform:
|
||||
- linux/amd64
|
||||
- linux/arm64
|
||||
name: Build App container image
|
||||
steps:
|
||||
- name: Check if base container image exists
|
||||
id: baseImageExists
|
||||
run: |
|
||||
GHCR_TOKEN=$(echo ${{ secrets.GITHUB_TOKEN }} | base64)
|
||||
curl --fail -H "Authorization: Bearer ${GHCR_TOKEN}" https://ghcr.io/v2/jikan-me/jikan-rest-php/tags/list | grep -q latest
|
||||
|
||||
- name: Base image existance check failed
|
||||
if: ${{ always() && steps.baseImageExists.outcome == 'failure' }}
|
||||
run: echo "Base image doesn't exist yet. Please run the base image creation workflow first."
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
@ -29,18 +39,75 @@ jobs:
|
||||
|
||||
- name: Set up docker buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
platforms: linux/amd64,linux/arm64
|
||||
|
||||
- name: Read metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY_IMAGE }}
|
||||
labels: |
|
||||
org.opencontainers.image.title=Jikan REST API
|
||||
org.opencontainers.image.description=REST API for Jikan
|
||||
org.opencontainers.image.url=https://jikan.moe
|
||||
org.opencontainers.image.source=https://github.com/jikan-me/jikan-rest
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push by digest
|
||||
id: build
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
platforms: ${{ matrix.platform }}
|
||||
# let's use github action cache storage
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
|
||||
|
||||
- name: Export digest
|
||||
run: |
|
||||
mkdir -p /tmp/digests
|
||||
digest="${{ steps.build.outputs.digest }}"
|
||||
touch "/tmp/digests/${digest#sha256:}"
|
||||
|
||||
- name: Upload digest
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: digests
|
||||
path: /tmp/digests/*
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
|
||||
publish-app-image:
|
||||
runs-on: ubuntu-latest
|
||||
name: Publish app container image
|
||||
needs:
|
||||
- build-app-image
|
||||
steps:
|
||||
- name: Download digests
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: digests
|
||||
path: /tmp/digests
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Read metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v4
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/jikan-me/jikan-rest
|
||||
${{ env.REGISTRY_IMAGE }}
|
||||
jikanme/jikan-rest
|
||||
tags: |
|
||||
type=raw,value=${{ github.ref_name }}
|
||||
type=raw,value=${{ inputs.image_tag || github.ref_name }}
|
||||
type=sha
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
@ -56,16 +123,10 @@ jobs:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
push: true
|
||||
context: .
|
||||
# let's use github action cache storage
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
build-args: |
|
||||
GITHUB_PERSONAL_TOKEN=${{ secrets.GITHUB_TOKEN }}
|
||||
BASE_IMAGE_VERSION=latest
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
- 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_IMAGE }}@sha256:%s ' *)
|
||||
- name: Inspect image
|
||||
run: |
|
||||
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user