Skip to content

Build image

Build image #10

Workflow file for this run

name: Build image
on:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
packages: write
jobs:
build_base:
runs-on: ubuntu-latest
strategy:
max-parallel: 3
matrix:
archs: ["amd64/v3"]
versions: ["8.2", "8.3"]
options: ["", "-debug", "-opt"]
include:
- options: ""
configure_append: ""
optimize_options_c_cpp: "-O2"
optimize_options_ld: "-O1"
- options: "-debug"
configure_append: "--enable-debug"
optimize_options_c_cpp: "-O0"
optimize_options_ld: "-O0"
- options: "-opt"
configure_append: ""
optimize_options_c_cpp: "-O3"
optimize_options_ld: "-O2"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Checkout latest PHP version
if: '!startsWith(github.ref, ''refs/tags/'')'
run: |
cd "third_party/php/php-src"
git checkout "$(git tag | grep -E "^php-${{ matrix.versions }}.[0-9]+$" | sort -V | tail -n1)"
- name: Determine tags
id: container_tags
run: |
cd "third_party/php/php-src"
echo full="ghcr.io/${{ github.repository }}:$(git describe --tags --abbrev=0 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+")${{ matrix.options }}" >> $GITHUB_OUTPUT
echo short="ghcr.io/${{ github.repository }}:$(git describe --tags --abbrev=0 | grep -oE "[0-9]+\.[0-9]+")${{ matrix.options }}" >> $GITHUB_OUTPUT
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: "arm64"
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Packages Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push image
uses: docker/build-push-action@v6
with:
context: .
push: true
pull: true
github-token: ${{ secrets.GITHUB_TOKEN }}
tags: "${{ steps.container_tags.outputs.full }}-base${{ !startsWith(github.ref, 'refs/tags/') && format(',{0}-base', steps.container_tags.outputs.short) || '' }}"
build-args: |
ARCH=${{ matrix.archs }}
DP_CFLAGS_OPTIMIZE=${{ matrix.optimize_options_c_cpp }}
DP_CPPFLAGS_OPTIMIZE=${{ matrix.optimize_options_c_cpp }}
DP_LDFLAGS_OPTIMIZE=${{ matrix.optimize_options_ld }}
DP_PHP_CONFIGURE_OPTIONS_APPEND=${{ matrix.configure_append }}
- name: Describe infomations
id: describe_infos
run: |
echo "directories=$(ls "variants/" | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
echo "id=$(docker run --rm -i "${{ steps.container_tags.outputs.full }}-base" sh -c '. /etc/os-release && echo ${VERSION_ID}')" >> $GITHUB_OUTPUT
echo "arch=${{ matrix.archs }}" >> $GITHUB_OUTPUT
echo "full=${{ steps.container_tags.outputs.full }}" >> $GITHUB_OUTPUT
echo "short=${{ steps.container_tags.outputs.short }}" >> $GITHUB_OUTPUT
outputs:
variant_directories: ${{ steps.describe_infos.outputs.directories }}
debian_version: ${{ steps.describe_infos.outputs.id }}
arch: ${{ steps.describe_infos.outputs.arch }}
tag_full: ${{ steps.describe_infos.outputs.full }}
tag_short: ${{ steps.describe_infos.outputs.short }}
build_variants:
needs: build_base
runs-on: ubuntu-latest
strategy:
matrix:
directory: ${{ fromJson(needs.build_base.outputs.variant_directories) }}
steps:
- name: Checkout without submodules
uses: actions/checkout@v4
with:
submodules: false
fetch-depth: 0
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: "arm64"
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Packages Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push image
uses: docker/build-push-action@v6
with:
context: "variants/${{ matrix.directory }}"
push: true
pull: true
github-token: ${{ secrets.GITHUB_TOKEN }}
tags: "${{ needs.build_base.outputs.tag_full }}-${{ matrix.directory }}${{ !startsWith(github.ref, 'refs/tags/') && format(',{0}-{1}', needs.build_base.outputs.tag_short, matrix.directory) || '' }}"
build-args: |
ARCH=${{ needs.build_base.outputs.arch }}
BASE_IMAGE=${{ needs.build_base.outputs.tag_full }}-base
DEBIAN_VERSION=${{ needs.build_base.outputs.debian_version }}