-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
96 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,112 @@ | ||
--- | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: # yamllint disable-line rule:truthy | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
env: | ||
DOCKER_NAMESPACE: wayofdev/php-base | ||
GHCR_NAMESPACE: ghcr.io/wayofdev/php-base | ||
|
||
name: 🚀 Build docker images with latest tag | ||
|
||
jobs: | ||
# https://docs.github.com/en/enterprise-cloud@latest/actions/learn-github-actions/expressions#example-returning-a-json-object | ||
prepare: | ||
runs-on: "ubuntu-latest" | ||
outputs: | ||
matrix: ${{ steps.matrix.outputs.matrix }} | ||
build: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os_name: ["alpine"] | ||
php_version: ["8.1", "8.2", "8.3"] | ||
php_type: ["fpm", "cli", "supervisord"] | ||
builder: [{arch: "amd64", os: "ubuntu-latest"}, {arch: "arm64", os: "ubuntu-latest"}] | ||
runs-on: ${{ matrix.builder.os }} | ||
steps: | ||
- name: ⚙️ Generate matrix | ||
id: matrix | ||
- name: 📦 Check out the codebase | ||
uses: actions/checkout@v4 | ||
|
||
- name: 🤖 Generate dist files | ||
run: make generate | ||
|
||
- name: 🐳 Extract docker meta data | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
${{ env.DOCKER_NAMESPACE }} | ||
${{ env.GHCR_NAMESPACE }} | ||
tags: | | ||
type=raw,event=branch,value=latest | ||
type=ref,event=pr | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
flavor: | | ||
latest=false | ||
prefix=${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}- | ||
- name: Rename meta bake definition file | ||
run: | | ||
echo 'matrix={ | ||
"os_name": ["alpine"], | ||
"php_version": ["8.1", "8.2", "8.3"], | ||
"php_platform": ["linux/amd64", "linux/arm64"], | ||
"php_type": ["fpm", "cli", "supervisord"] | ||
}' | tr -d '\n' >> $GITHUB_OUTPUT | ||
mv "${{ steps.meta.outputs.bake-file }}" "/tmp/bake-meta.json" | ||
build: | ||
needs: prepare | ||
strategy: | ||
matrix: ${{ fromJson(needs.prepare.outputs.matrix )}} | ||
uses: wayofdev/gh-actions/.github/workflows/build-image.yml@master | ||
with: | ||
os: "ubuntu-latest" | ||
push-to-hub: true | ||
image-namespace: "wayofdev/php-base" | ||
image-template-path: "./dist/base" | ||
image-template: ${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }} | ||
image-version: latest | ||
image-platform: ${{ matrix.php_platform }} | ||
secrets: | ||
docker-username: ${{ secrets.DOCKER_USERNAME }} | ||
docker-password: ${{ secrets.DOCKER_TOKEN }} | ||
- name: Upload meta bake definition | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: bake-meta | ||
path: /tmp/bake-meta.json | ||
if-no-files-found: error | ||
retention-days: 1 | ||
|
||
- name: 🛠️ Setup docker BuildX | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
with: | ||
buildkitd-flags: "--debug" | ||
|
||
- name: 🔑 Login to docker-hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_TOKEN }} | ||
|
||
- name: Login to GHCR | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: 🚀 Build image and push to docker-hub and GHCR | ||
id: bake | ||
uses: docker/bake-action@v3 | ||
with: | ||
files: | | ||
./docker-bake.hcl | ||
/tmp/bake-meta.json | ||
set: | | ||
*.tags=${{ steps.meta.outputs.tags }} | ||
*.platform=linux/${{ matrix.builder.arch }} | ||
*.output=type=image,"name=${{ env.DOCKERHUB_SLUG }},${{ env.GHCR_SLUG }}",push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }} | ||
- name: Export digest | ||
run: | | ||
mkdir -p /tmp/digests | ||
digest="${{ fromJSON(steps.bake.outputs.metadata).image['containerimage.digest'] }}" | ||
touch "/tmp/digests/${digest#sha256:}" | ||
- name: Upload digest | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: digests | ||
path: /tmp/digests/* | ||
if-no-files-found: error | ||
retention-days: 1 | ||
|
||
... |