mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
improved github action for container image builds
This commit is contained in:
parent
bb7b59c244
commit
bae1f99e4a
58
.github/workflows/container-base-image-release.yml
vendored
Normal file
58
.github/workflows/container-base-image-release.yml
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
name: Container Base Image Release
|
||||
concurrency: production
|
||||
on:
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
release-base-image:
|
||||
runs-on: ubuntu-latest
|
||||
name: Release base container image
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up qemu
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up docker buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
with:
|
||||
platforms: linux/amd64,linux/arm64
|
||||
|
||||
- name: Read metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v4
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/jikan-me/jikan-rest-php
|
||||
jikanme/jikan-rest-php
|
||||
tags: |
|
||||
type=raw,value=latest
|
||||
type=sha
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
push: true
|
||||
context: ./docker/base_image/php-8.0
|
||||
# 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 }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
95
.github/workflows/container-image-release.yml
vendored
95
.github/workflows/container-image-release.yml
vendored
@ -1,65 +1,25 @@
|
||||
name: Container Image Release
|
||||
concurrency: production
|
||||
on:
|
||||
workflow_dispatch:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
release-base-image:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
baseImagePhpVersion: ['8.0', '8.1']
|
||||
name: Release base container image / PHP ${{ matrix.baseImagePhpVersion }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up qemu
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up docker buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
with:
|
||||
platforms: linux/amd64,linux/arm64
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
push: true
|
||||
context: ./docker/base_image/php-${{ matrix.baseImagePhpVersion }}
|
||||
cache-from: type=registry,ref=ghcr.io/jikan-me/jikan-rest-php:${{ matrix.baseImagePhpVersion }}-${{ github.sha }}
|
||||
cache-to: type=inline
|
||||
build-args: |
|
||||
GITHUB_PERSONAL_TOKEN=${{ secrests.GITHUB_TOKEN }}
|
||||
tags: |
|
||||
ghcr.io/jikan-me/jikan-rest-php:${{ matrix.baseImagePhpVersion }}
|
||||
ghcr.io/jikan-me/jikan-rest-php:${{ matrix.baseImagePhpVersion }}-${{ github.sha }}
|
||||
jikanme/jikan-rest-php:${{ matrix.baseImagePhpVersion }}
|
||||
jikanme/jikan-rest-php:${{ matrix.baseImagePhpVersion }}-${{ github.sha }}
|
||||
|
||||
release-app-image:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
baseImagePhpVersion: [ '8.0', '8.1' ]
|
||||
needs: Release base container image / PHP ${{ matrix.baseImagePhpVersion }}
|
||||
name: Release App container image / PHP ${{ matrix.baseImagePhpVersion }}
|
||||
needs: Release base container image
|
||||
name: Release 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@v3
|
||||
with:
|
||||
@ -73,6 +33,17 @@ jobs:
|
||||
with:
|
||||
platforms: linux/amd64,linux/arm64
|
||||
|
||||
- name: Read metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v4
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/jikan-me/jikan-rest
|
||||
jikanme/jikan-rest
|
||||
tags: |
|
||||
type=raw,value=${{ github.ref_name }}
|
||||
type=sha
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
@ -91,13 +62,11 @@ jobs:
|
||||
with:
|
||||
push: true
|
||||
context: .
|
||||
cache-from: type=registry,ref=ghcr.io/jikan-me/jikan-rest:${{ matrix.baseImagePhpVersion }}-${{ github.sha }}
|
||||
cache-to: type=inline
|
||||
# let's use github action cache storage
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
build-args: |
|
||||
GITHUB_PERSONAL_TOKEN=${{ secrests.GITHUB_TOKEN }}
|
||||
BASE_IMAGE_VERSION=${{ matrix.baseImagePhpVersion }}
|
||||
tags: |
|
||||
ghcr.io/jikan-me/jikan-rest:latest
|
||||
ghcr.io/jikan-me/jikan-rest:${{ github.sha }}
|
||||
jikanme/jikan-rest:latest
|
||||
jikanme/jikan-rest:${{ github.sha }}
|
||||
GITHUB_PERSONAL_TOKEN=${{ secrets.GITHUB_TOKEN }}
|
||||
BASE_IMAGE_VERSION=latest
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
@ -1,4 +1,4 @@
|
||||
ARG BASE_IMAGE_VERSION="8.1"
|
||||
ARG BASE_IMAGE_VERSION="latest"
|
||||
FROM jikanme/jikan-rest-php:${BASE_IMAGE_VERSION}
|
||||
ARG GITHUB_PERSONAL_TOKEN
|
||||
LABEL org.opencontainers.image.source=https://github.com/jikan-me/jikan-rest
|
||||
|
Loading…
x
Reference in New Issue
Block a user