Build Docker images #353
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
name: Build Docker images | |
on: | |
pull_request: | |
paths: | |
- .github/workflows/build.yml | |
- .github/workflows/generate-matrix | |
- "base/**" | |
- "installed/**" | |
- data/versions.json | |
push: | |
branches: | |
- main | |
tags-ignore: | |
- "**" | |
paths: | |
- .github/workflows/build.yml | |
- .github/workflows/generate-matrix | |
- "base/**" | |
- "installed/**" | |
- data/versions.json | |
repository_dispatch: | |
types: | |
- build | |
- publish | |
workflow_dispatch: | |
inputs: | |
operation: | |
description: Operation | |
required: true | |
default: build | |
type: choice | |
options: | |
- build | |
- publish | |
- update-data-matrix-only | |
jobs: | |
check_envoronment: | |
name: Check environment | |
runs-on: ubuntu-latest | |
outputs: | |
action: ${{ steps.inspect.outputs.action }} | |
steps: | |
- | |
name: Inspect environment | |
id: inspect | |
run: | | |
action=none | |
case ${{ github.event_name }} in | |
repository_dispatch) | |
case "${{ github.event.event_type }}" in | |
build) | |
action=build | |
;; | |
publish) | |
action=publish | |
;; | |
*) | |
echo 'Unrecognized event type: ${{ github.event.event_type }}' | |
exit 1 | |
;; | |
esac | |
;; | |
push) | |
case "${{ github.event.head_commit.message }}" in | |
\[skip\ ci\]*) | |
;; | |
*) | |
action=publish | |
;; | |
esac | |
;; | |
pull_request) | |
action=build | |
;; | |
workflow_dispatch) | |
action='${{ inputs.operation }}' | |
;; | |
esac | |
echo "action=$action" >> $GITHUB_OUTPUT | |
- | |
name: Print environment info | |
run: | | |
printf 'github.event_name: %s\n' "${{ github.event_name }}" | |
printf 'github.ref: %s\n' "${{ github.ref }}" | |
printf 'Action to be performed: %s\n' "${{ steps.inspect.outputs.action }}" | |
build_base: | |
name: Build base image | |
needs: | |
- check_envoronment | |
runs-on: ubuntu-latest | |
if: needs.check_envoronment.outputs.action == 'build' || needs.check_envoronment.outputs.action == 'publish' | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v4 | |
- | |
name: Build | |
run: docker build --force-rm --rm --tag ghcr.io/concrete5-community/docker5:base ./base | |
- | |
name: Save base Docker image | |
if: needs.check_envoronment.outputs.action == 'build' | |
run: docker save ghcr.io/concrete5-community/docker5:base | gzip > /tmp/base-image.tgz | |
- | |
name: Upload artifact | |
if: needs.check_envoronment.outputs.action == 'build' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: base-image | |
path: /tmp/base-image.tgz | |
- | |
name: Login to the Docker container registry | |
if: needs.check_envoronment.outputs.action == 'publish' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- | |
name: Publish image | |
if: needs.check_envoronment.outputs.action == 'publish' | |
run: docker push ghcr.io/concrete5-community/docker5:base | |
generate_matrix: | |
name: Generate matrix | |
runs-on: ubuntu-latest | |
outputs: | |
generated-matrix: ${{ steps.generate-matrix.outputs.generated-matrix }} | |
steps: | |
- | |
name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.2' | |
extensions: none | |
tools: none | |
coverage: none | |
- | |
name: Checkout | |
uses: actions/checkout@v4 | |
- | |
name: Generate matrix | |
id: generate-matrix | |
run: ./.github/workflows/generate-matrix build.yml "$GITHUB_OUTPUT" | |
build: | |
name: Build ${{ matrix.data.image_tag }} | |
runs-on: ubuntu-latest | |
needs: | |
- check_envoronment | |
- build_base | |
- generate_matrix | |
if: needs.check_envoronment.outputs.action == 'build' || needs.check_envoronment.outputs.action == 'publish' | |
strategy: | |
matrix: | |
data: ${{ fromJSON(needs.generate_matrix.outputs.generated-matrix) }} | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v4 | |
- | |
name: Download base image | |
if: needs.check_envoronment.outputs.action == 'build' | |
uses: actions/download-artifact@v4 | |
with: | |
name: base-image | |
path: /tmp/ | |
- | |
name: Load base image | |
if: needs.check_envoronment.outputs.action == 'build' | |
run: docker load --input /tmp/base-image.tgz | |
- | |
name: Build with starting point ${{ matrix.data.c5_startingpoint }} | |
run: | | |
docker build \ | |
--build-arg CCM_PHP_VERSION=${{ matrix.data.php_version }} \ | |
--build-arg CCM_COMPOSER_VERSION=${{ matrix.data.composer_version }} \ | |
--build-arg CCM_PHPUNIT_VERSION=${{ matrix.data.phpunit_version }} \ | |
--build-arg CCM_C5_ARCHIVE=${{ matrix.data.c5_archive }} \ | |
--build-arg CCM_STARTING_POINT=${{ matrix.data.c5_startingpoint }} \ | |
--build-arg CCM_PATCH_ENVIRONMENT_ONLY=${{ matrix.data.patch_environment_only }} \ | |
--tag ghcr.io/concrete5-community/docker5:${{ matrix.data.image_tag }} \ | |
./installed | |
for additional_tag in ${{ matrix.data.additional_tags }}; do | |
docker tag ghcr.io/concrete5-community/docker5:${{ matrix.data.image_tag }} ghcr.io/concrete5-community/docker5:$additional_tag | |
done | |
- | |
name: Check that MariaDB works | |
run: docker run --rm --entrypoint='' ghcr.io/concrete5-community/docker5:${{ matrix.data.image_tag }} ccm-service start db | |
- | |
name: Remove base Docker image | |
if: needs.check_envoronment.outputs.action == 'publish' | |
run: docker rmi ghcr.io/concrete5-community/docker5:base || true | |
- | |
name: Login to the Docker container registry | |
if: needs.check_envoronment.outputs.action == 'publish' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- | |
name: Publish image | |
if: needs.check_envoronment.outputs.action == 'publish' | |
run: docker push --all-tags ghcr.io/concrete5-community/docker5 | |
store-data-matrix: | |
name: Store data matrix | |
runs-on: ubuntu-latest | |
needs: | |
- check_envoronment | |
- generate_matrix | |
if: needs.check_envoronment.outputs.action == 'publish' || needs.check_envoronment.outputs.action == 'update-data-matrix-only' | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v4 | |
- | |
name: Store data matrix | |
env: | |
GENERATED_MATRIX: ${{ needs.generate_matrix.outputs.generated-matrix }} | |
run: printf '%s' "$GENERATED_MATRIX" >data/matrix.json | |
- | |
name: Commit data matrix | |
run: | | |
git add data/matrix.json | |
if git diff --cached --color=always --exit-code data/matrix.json; then | |
echo 'No changes' | |
else | |
git config --local user.name 'GitHub Actions' | |
git config --local user.email [email protected] | |
git add data/matrix.json | |
git commit -m 'Update data matrix' | |
git push | |
fi |