Skip to content

Commit ce2630d

Browse files
committed
workflow update
1 parent 64200fb commit ce2630d

18 files changed

+1092
-1712
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# .github/actions/docker-setup/action.yml
2+
name: 'Docker setup [EXPANDED]'
3+
description: Docker Setup (install, qemu, buildx and login)
4+
5+
inputs:
6+
git_url:
7+
description: "Git-URL from Workflow"
8+
required: false
9+
github_token:
10+
description: "secrets.GITHUB_TOKEN from Workflow"
11+
required: false
12+
docker_username:
13+
description: "secrets.DOCKER_USERNAME from Workflow"
14+
required: false
15+
docker_password:
16+
description: "secrets.DOCKER_PASSWORD from Workflow"
17+
required: false
18+
quay_username:
19+
description: "secrets.REDHAT_QUAY_USERNAME from Workflow"
20+
required: false
21+
quay_password:
22+
description: "secrets.REDHAT_QUAY_PASSWORD from Workflow"
23+
required: false
24+
25+
outputs:
26+
builder_name:
27+
description: "Name of Buildx Builders for Workflow"
28+
value: ${{ steps.buildx.outputs.name }}
29+
30+
runs:
31+
using: composite
32+
steps:
33+
34+
- name: Set git_url when empty to ghcr.io registry
35+
id: set_git_url
36+
shell: bash
37+
run: |
38+
GIT_URL="${{ inputs.git_url }}"
39+
if [[ -z "$GIT_URL" ]]; then
40+
GIT_URL="ghcr.io"
41+
fi
42+
echo "GIT_URL=$GIT_URL" >> "$GITHUB_ENV"
43+
44+
- name: Debug Variables
45+
id: debug
46+
shell: bash
47+
run: |
48+
echo "GIT_URL=${{ env.GIT_URL }}"
49+
echo "\"GITHUB_USERNAME\"=${{ github.repository_owner }}"
50+
echo "DOCKER_USERNAME=${{ inputs.docker_username }}"
51+
echo "QUAY_USERNAME=${{ inputs.quay_username }}"
52+
53+
#- name: Install Docker
54+
# id: install
55+
# shell: bash
56+
# run: |
57+
# if ! command -v docker &> /dev/null; then
58+
# curl -fsSL https://get.docker.com | sh
59+
# else
60+
# echo "skip -> Docker is already installed!"
61+
# fi
62+
63+
- name: Set up QEMU
64+
id: qemu
65+
uses: docker/setup-qemu-action@v3
66+
with:
67+
image: tonistiigi/binfmt:latest
68+
platforms: all
69+
70+
- name: Set up Docker Buildx
71+
id: buildx
72+
uses: docker/setup-buildx-action@v3
73+
#with:
74+
# config-inline: |
75+
# [registry."${{ env.GIT_URL }}"]
76+
# #insecure = true
77+
# ca=["/etc/ssl/certs/ca-certificates.crt"]
78+
79+
- name: Login to GIT Container Registry
80+
if: env.GIT_URL != '' && github.repository_owner != '' && inputs.github_token != ''
81+
uses: docker/login-action@v3
82+
with:
83+
registry: ${{ inputs.git_url }}
84+
username: ${{ github.repository_owner }}
85+
password: ${{ inputs.github_token }}
86+
87+
- name: Login to Docker Hub Container Registry
88+
if: inputs.docker_username != '' && inputs.docker_password != ''
89+
uses: docker/login-action@v3
90+
with:
91+
registry: docker.io
92+
username: ${{ inputs.docker_username }}
93+
password: ${{ inputs.docker_password }}
94+
95+
#- name: Login to Docker Hardened Images Container Registry
96+
# if: inputs.docker_username != '' && inputs.docker_password != ''
97+
# uses: docker/login-action@v3
98+
# with:
99+
# registry: dhi.io
100+
# username: ${{ inputs.docker_username }}
101+
# password: ${{ inputs.docker_password }}
102+
103+
- name: Login to RED HAT Quay.io Container Registry
104+
if: inputs.quay_username != '' && inputs.quay_password != ''
105+
uses: docker/login-action@v3
106+
with:
107+
registry: quay.io
108+
username: ${{ inputs.quay_username }}
109+
password: ${{ inputs.quay_password }}
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
name: 'docker: Alpine + PHP-FPM'
2+
3+
on:
4+
#push:
5+
# branches:
6+
# - 'main'
7+
# - 'master'
8+
# paths:
9+
# - 'alpine.fpm.slim.Dockerfile'
10+
# - 'alpine.fpm.Dockerfile'
11+
# - '.github/workflows/build_docker-alpine_fpm.yml'
12+
workflow_dispatch:
13+
schedule:
14+
- cron: '45 2 24 * *' # At 02:45 on day-of-month 24.
15+
16+
defaults:
17+
run:
18+
shell: bash
19+
20+
jobs:
21+
22+
# --------------------------------------------------
23+
# JOB: PREPARE (Variables)
24+
# --------------------------------------------------
25+
prepare:
26+
name: Prepare build variables
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
#- name: Checkout
31+
# uses: actions/checkout@v6
32+
33+
- name: Define PHP matrix
34+
id: matrix
35+
shell: bash
36+
run: |
37+
echo 'php_matrix=["8.3","8.4","8.5"]' >> "$GITHUB_OUTPUT"
38+
39+
- name: Generate build variables
40+
id: vars
41+
shell: bash
42+
run: |
43+
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
44+
BUILD_DATE_NUMERIC="${BUILD_DATE//[^[:digit:]]/}"
45+
#COMMIT_HASH=$(git rev-parse --short "$GITHUB_SHA")
46+
COMMIT_HASH=${GITHUB_SHA::7}
47+
GIT_URL=$(echo "${GITHUB_SERVER_URL}" | awk -F/ '{print $3}' | sed 's/\/*$//')
48+
GIT_URL=$(echo "$GIT_URL" | sed 's/github\.com/ghcr\.io/g') # GIT_URL switch to ghcr.io registry for GitHub
49+
GIT_REPO=${GITHUB_REPOSITORY,,}
50+
GIT_REPO_SHORT=${GIT_REPO#*/}
51+
GIT_REPO_SHORT=${GIT_REPO_SHORT#"docker-"}
52+
DOCKER_REPO=${{ secrets.DOCKER_USERNAME }}/${GIT_REPO_SHORT}
53+
REDHAT_QUAY_REPO=${{ secrets.REDHAT_QUAY_USERNAME }}/${GIT_REPO_SHORT}
54+
55+
#echo "ENVs: BUILD_DATE=${BUILD_DATE}, BUILD_DATE_NUMERIC=${BUILD_DATE_NUMERIC}, COMMIT_HASH=${COMMIT_HASH}, GIT_URL=${GIT_URL}, GIT_REPO=${GIT_REPO}, DOCKER_REPO=${DOCKER_REPO}, REDHAT_QUAY_REPO=${REDHAT_QUAY_REPO}"
56+
57+
# Set output parameters to action.
58+
echo "build_date=${BUILD_DATE}" >> "$GITHUB_OUTPUT"
59+
echo "build_date_numeric=${BUILD_DATE_NUMERIC}" >> "$GITHUB_OUTPUT"
60+
echo "commit_hash=${COMMIT_HASH}" >> "$GITHUB_OUTPUT"
61+
echo "git_url=${GIT_URL}" >> "$GITHUB_OUTPUT"
62+
echo "git_repo=${GIT_REPO}" >> "$GITHUB_OUTPUT"
63+
echo "git_repo_short=${GIT_REPO_SHORT}" >> "$GITHUB_OUTPUT"
64+
echo "docker_repo=${DOCKER_REPO}" >> "$GITHUB_OUTPUT"
65+
echo "redhat_quay_repo=${REDHAT_QUAY_REPO}" >> "$GITHUB_OUTPUT"
66+
67+
outputs:
68+
build_date: ${{ steps.vars.outputs.build_date }}
69+
build_date_numeric: ${{ steps.vars.outputs.build_date_numeric }}
70+
commit_hash: ${{ steps.vars.outputs.commit_hash }}
71+
git_url: ${{ steps.vars.outputs.git_url }}
72+
git_repo: ${{ steps.vars.outputs.git_repo }}
73+
git_repo_short: ${{ steps.vars.outputs.git_repo_short }}
74+
#docker_repo: ${{ steps.vars.outputs.docker_repo }} # emtpy because contains secret
75+
#quay_repo: ${{ steps.vars.outputs.redhat_quay_repo }} # emtpy because contains secret
76+
php_matrix: ${{ steps.matrix.outputs.php_matrix }}
77+
78+
79+
# --------------------------------------------------
80+
# JOB: Base-Image: php-slim
81+
# --------------------------------------------------
82+
build-php-slim:
83+
name: Build php-slim (PHP ${{ matrix.php }})
84+
runs-on: ubuntu-latest
85+
needs: prepare
86+
87+
strategy:
88+
fail-fast: false
89+
matrix:
90+
php: ${{ fromJson(needs.prepare.outputs.php_matrix) }}
91+
92+
env:
93+
BUILD_DATE: ${{ needs.prepare.outputs.build_date }}
94+
BUILD_DATE_NUMERIC: ${{ needs.prepare.outputs.build_date_numeric}}
95+
COMMIT_HASH: ${{ needs.prepare.outputs.commit_hash }}
96+
GIT_URL: ${{ needs.prepare.outputs.git_url }}
97+
GIT_REPO: ${{ needs.prepare.outputs.git_repo }}
98+
GIT_REPO_SHORT: ${{ needs.prepare.outputs.git_repo_short }}
99+
DOCKER_REPO: "${{ secrets.DOCKER_USERNAME }}/${{ needs.prepare.outputs.git_repo_short }}"
100+
QUAY_REPO: "${{ secrets.REDHAT_QUAY_USERNAME }}/${{ needs.prepare.outputs.git_repo_short }}"
101+
PHP_VERSION: ${{ matrix.php }}
102+
103+
steps:
104+
- name: Checkout
105+
uses: actions/checkout@v6
106+
107+
- name: Debug Variables
108+
run: |
109+
echo "BUILD_DATE=${BUILD_DATE}"
110+
echo "BUILD_DATE_NUMERIC=${BUILD_DATE_NUMERIC}"
111+
echo "COMMIT_HASH=${COMMIT_HASH}"
112+
echo "GIT_URL=${GIT_URL}"
113+
echo "GIT_REPO=${GIT_REPO}"
114+
echo "GIT_REPO_SHORT=${GIT_REPO_SHORT}"
115+
echo "DOCKER_REPO=${DOCKER_REPO}"
116+
echo "QUAY_REPO=${QUAY_REPO}"
117+
echo "PHP_VERSION=${PHP_VERSION}"
118+
119+
- name: Execute Docker Setup
120+
id: docker-setup
121+
uses: ./.github/actions/docker-setup
122+
#uses: tob1as/docker-build-example/.github/actions/docker-setup@main
123+
with:
124+
git_url: ${{ env.GIT_URL }}
125+
github_token: ${{ secrets.GITHUB_TOKEN }}
126+
docker_username: ${{ secrets.DOCKER_USERNAME }}
127+
docker_password: ${{ secrets.DOCKER_PASSWORD }}
128+
quay_username: ${{ secrets.REDHAT_QUAY_USERNAME }}
129+
quay_password: ${{ secrets.REDHAT_QUAY_PASSWORD }}
130+
131+
- name: Build
132+
uses: docker/build-push-action@v6
133+
with:
134+
builder: ${{ steps.docker-setup.outputs.builder_name }}
135+
context: .
136+
file: ./alpine.fpm.slim.Dockerfile
137+
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/ppc64le,linux/riscv64,linux/s390x,linux/386
138+
pull: true
139+
push: true
140+
#target: runtime
141+
build-args: |
142+
BUILD_DATE=${{ env.BUILD_DATE }}
143+
VCS_REF=${{ env.COMMIT_HASH }}
144+
PHP_VERSION=${{ env.PHP_VERSION }}
145+
tags: |
146+
docker.io/${{env.DOCKER_REPO}}:${{env.PHP_VERSION}}-fpm-alpine-slim
147+
docker.io/${{env.DOCKER_REPO}}:${{env.PHP_VERSION}}-fpm-alpine-slim-${{env.COMMIT_HASH}}
148+
# ${{env.GIT_URL}}/${{env.GIT_REPO}}:${{env.PHP_VERSION}}-fpm-alpine-slim
149+
# quay.io/${{env.QUAY_REPO}}:${{env.PHP_VERSION}}-fpm-alpine-slim
150+
151+
152+
# --------------------------------------------------
153+
# JOB: Derived-Image: php
154+
# --------------------------------------------------
155+
build-php:
156+
name: Build php (PHP ${{ matrix.php }})
157+
runs-on: ubuntu-latest
158+
needs:
159+
- prepare
160+
- build-php-slim
161+
162+
strategy:
163+
fail-fast: false
164+
matrix:
165+
php: ${{ fromJson(needs.prepare.outputs.php_matrix) }}
166+
167+
env:
168+
BUILD_DATE: ${{ needs.prepare.outputs.build_date }}
169+
BUILD_DATE_NUMERIC: ${{ needs.prepare.outputs.build_date_numeric}}
170+
COMMIT_HASH: ${{ needs.prepare.outputs.commit_hash }}
171+
GIT_URL: ${{ needs.prepare.outputs.git_url }}
172+
GIT_REPO: ${{ needs.prepare.outputs.git_repo }}
173+
GIT_REPO_SHORT: ${{ needs.prepare.outputs.git_repo_short }}
174+
DOCKER_REPO: "${{ secrets.DOCKER_USERNAME }}/${{ needs.prepare.outputs.git_repo_short }}"
175+
QUAY_REPO: "${{ secrets.REDHAT_QUAY_USERNAME }}/${{ needs.prepare.outputs.git_repo_short }}"
176+
PHP_VERSION: ${{ matrix.php }}
177+
178+
steps:
179+
- name: Checkout
180+
uses: actions/checkout@v6
181+
182+
- name: Execute Docker Setup
183+
id: docker-setup
184+
uses: ./.github/actions/docker-setup
185+
#uses: tob1as/docker-build-example/.github/actions/docker-setup@main
186+
with:
187+
git_url: ${{ env.GIT_URL }}
188+
github_token: ${{ secrets.GITHUB_TOKEN }}
189+
docker_username: ${{ secrets.DOCKER_USERNAME }}
190+
docker_password: ${{ secrets.DOCKER_PASSWORD }}
191+
quay_username: ${{ secrets.REDHAT_QUAY_USERNAME }}
192+
quay_password: ${{ secrets.REDHAT_QUAY_PASSWORD }}
193+
194+
- name: Build
195+
uses: docker/build-push-action@v6
196+
with:
197+
builder: ${{ steps.docker-setup.outputs.builder_name }}
198+
context: .
199+
file: ./alpine.fpm.Dockerfile
200+
platforms: linux/amd64,linux/arm64,linux/arm/v7
201+
pull: true
202+
push: true
203+
#target: runtime
204+
build-args: |
205+
BUILD_DATE=${{ env.BUILD_DATE }}
206+
VCS_REF=${{ env.COMMIT_HASH }}
207+
PHP_VERSION=${{ env.PHP_VERSION }}
208+
tags: |
209+
docker.io/${{env.DOCKER_REPO}}:${{env.PHP_VERSION}}-fpm-alpine
210+
docker.io/${{env.DOCKER_REPO}}:${{env.PHP_VERSION}}-fpm-alpine-${{env.COMMIT_HASH}}
211+
# ${{env.GIT_URL}}/${{env.GIT_REPO}}:${{env.PHP_VERSION}}-fpm-alpine
212+
# quay.io/${{env.QUAY_REPO}}:${{env.PHP_VERSION}}-fpm-alpine

0 commit comments

Comments
 (0)