151 lines
5.5 KiB
YAML
151 lines
5.5 KiB
YAML
name: Publish PHP Apache image
|
|
|
|
on:
|
|
push:
|
|
workflow_dispatch:
|
|
schedule:
|
|
# Refresh the rolling Arch Linux base weekly.
|
|
- cron: "13 3 * * 1"
|
|
|
|
env:
|
|
IMAGE: registry.brunner.ninja/feedc0de/php-apache
|
|
|
|
jobs:
|
|
publish:
|
|
name: Build, test and push
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 30
|
|
|
|
steps:
|
|
- name: Check out source
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Validate Helm chart
|
|
run: |
|
|
set -euo pipefail
|
|
docker run --rm \
|
|
--volume "${PWD}:/source" \
|
|
--workdir /source \
|
|
alpine/helm:4.2.2@sha256:ee6fe3e96d9f8ea8dd1af9ecd7bbb3e233616a25f145392376f020fd2a51eb33 \
|
|
lint helm/php-homepage
|
|
docker run --rm \
|
|
--volume "${PWD}:/source" \
|
|
--workdir /source \
|
|
alpine/helm:4.2.2@sha256:ee6fe3e96d9f8ea8dd1af9ecd7bbb3e233616a25f145392376f020fd2a51eb33 \
|
|
template ci-test helm/php-homepage > /dev/null
|
|
|
|
- name: Log in to Quay
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: registry.brunner.ninja
|
|
username: ${{ secrets.QUAY_USERNAME }}
|
|
password: ${{ secrets.QUAY_TOKEN }}
|
|
|
|
- name: Build image
|
|
env:
|
|
COMMIT_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
docker build \
|
|
--pull \
|
|
--load \
|
|
--label "org.opencontainers.image.revision=${COMMIT_SHA}" \
|
|
--label "org.opencontainers.image.source=https://code.brunner.ninja/feedc0de/php-apache" \
|
|
--tag "${IMAGE}:${COMMIT_SHA}" \
|
|
.
|
|
|
|
- name: Test Apache and PHP extensions
|
|
env:
|
|
COMMIT_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
docker run --rm --entrypoint httpd "${IMAGE}:${COMMIT_SHA}" -t
|
|
docker run --rm --entrypoint php "${IMAGE}:${COMMIT_SHA}" -r '
|
|
foreach (["exif", "gd", "intl", "Zend OPcache", "pgsql", "pdo_pgsql"] as $extension) {
|
|
if (!extension_loaded($extension)) {
|
|
fwrite(STDERR, "Missing PHP extension: {$extension}\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
$info = gd_info();
|
|
foreach (["JPEG Support", "PNG Support", "WebP Support"] as $feature) {
|
|
if (empty($info[$feature])) {
|
|
fwrite(STDERR, "Missing GD feature: {$feature}\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
$image = imagecreatetruecolor(8, 8);
|
|
$scaled = imagescale($image, 4, 4);
|
|
if ($scaled === false || imagesx($scaled) !== 4 || imagesy($scaled) !== 4) {
|
|
fwrite(STDERR, "GD resize smoke test failed.\n");
|
|
exit(1);
|
|
}
|
|
echo "GD resize smoke test passed.\n";
|
|
'
|
|
|
|
- name: Determine version tag
|
|
env:
|
|
COMMIT_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
version_tag="$(
|
|
docker run --rm --entrypoint sh "${IMAGE}:${COMMIT_SHA}" -ec '
|
|
apache_version="$(httpd -v | sed -n "s#^Server version: Apache/\([0-9.]*\).*$#\1#p")"
|
|
php_version="$(php -r "echo PHP_VERSION;")"
|
|
test -n "${apache_version}"
|
|
test -n "${php_version}"
|
|
printf "%s-%s" "${apache_version}" "${php_version}"
|
|
'
|
|
)"
|
|
printf 'VERSION_TAG=%s\n' "${version_tag}" >> "${GITHUB_ENV}"
|
|
run_attempt="${GITHUB_RUN_ATTEMPT:-1}"
|
|
test -n "${GITHUB_RUN_NUMBER}"
|
|
chart_version="0.${GITHUB_RUN_NUMBER}.${run_attempt}"
|
|
printf 'CHART_VERSION=%s\n' "${chart_version}" >> "${GITHUB_ENV}"
|
|
printf 'BUILD_TAG=chart-%s\n' "${chart_version}" >> "${GITHUB_ENV}"
|
|
|
|
- name: Push commit tag
|
|
if: gitea.event_name == 'push'
|
|
env:
|
|
COMMIT_SHA: ${{ gitea.sha }}
|
|
run: docker push "${IMAGE}:${COMMIT_SHA}"
|
|
|
|
- name: Push main tags
|
|
if: gitea.ref == 'refs/heads/main' || gitea.event_name == 'schedule'
|
|
env:
|
|
COMMIT_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
docker tag "${IMAGE}:${COMMIT_SHA}" "${IMAGE}:${BUILD_TAG}"
|
|
docker tag "${IMAGE}:${COMMIT_SHA}" "${IMAGE}:${VERSION_TAG}"
|
|
docker tag "${IMAGE}:${COMMIT_SHA}" "${IMAGE}:latest"
|
|
docker push "${IMAGE}:${BUILD_TAG}"
|
|
docker push "${IMAGE}:${VERSION_TAG}"
|
|
docker push "${IMAGE}:latest"
|
|
|
|
- name: Publish Helm chart
|
|
if: gitea.ref == 'refs/heads/main' || gitea.event_name == 'schedule'
|
|
env:
|
|
PACKAGE_USERNAME: ${{ secrets.PACKAGE_USERNAME }}
|
|
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
test -n "${PACKAGE_USERNAME}"
|
|
test -n "${PACKAGE_TOKEN}"
|
|
install -d .chart-packages
|
|
docker run --rm \
|
|
--volume "${PWD}:/source" \
|
|
--workdir /source \
|
|
alpine/helm:4.2.2@sha256:ee6fe3e96d9f8ea8dd1af9ecd7bbb3e233616a25f145392376f020fd2a51eb33 \
|
|
package helm/php-homepage \
|
|
--destination .chart-packages \
|
|
--version "${CHART_VERSION}" \
|
|
--app-version "${BUILD_TAG}"
|
|
chart_file=".chart-packages/php-homepage-${CHART_VERSION}.tgz"
|
|
test -f "${chart_file}"
|
|
curl --fail --silent --show-error \
|
|
--user "${PACKAGE_USERNAME}:${PACKAGE_TOKEN}" \
|
|
--request POST \
|
|
--upload-file "${chart_file}" \
|
|
https://code.brunner.ninja/api/packages/feedc0de/helm/api/charts
|