167 lines
6.9 KiB
YAML
167 lines
6.9 KiB
YAML
name: Test, publish phpPgAdmin image and chart
|
|
|
|
on:
|
|
push:
|
|
pull_request:
|
|
|
|
env:
|
|
IMAGE: registry.brunner.ninja/feedc0de/phppgadmin
|
|
|
|
jobs:
|
|
validate:
|
|
runs-on: linux_amd64
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Install Helm
|
|
run: |
|
|
curl --fail --silent --show-error --location \
|
|
--output "${RUNNER_TEMP}/helm.tar.gz" \
|
|
https://get.helm.sh/helm-v4.2.2-linux-amd64.tar.gz
|
|
tar -xzf "${RUNNER_TEMP}/helm.tar.gz" -C "${RUNNER_TEMP}" linux-amd64/helm
|
|
mv "${RUNNER_TEMP}/linux-amd64/helm" "${RUNNER_TEMP}/helm"
|
|
chmod 0700 "${RUNNER_TEMP}/helm"
|
|
echo "${RUNNER_TEMP}" >> "$GITHUB_PATH"
|
|
- name: Validate and render chart
|
|
run: |
|
|
sh -n chart/install.sh
|
|
sh -n test.sh
|
|
./chart/test.sh
|
|
|
|
publish-image:
|
|
if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main'
|
|
needs: validate
|
|
runs-on: linux_amd64
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Configure isolated registry access
|
|
env:
|
|
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }}
|
|
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
authfile="${RUNNER_TEMP}/quay-auth.json"
|
|
printf '{"auths":{}}' > "$authfile"
|
|
chmod 0600 "$authfile"
|
|
printf '%s' "$QUAY_TOKEN" | podman login registry.brunner.ninja \
|
|
--authfile "$authfile" --username "$QUAY_USERNAME" --password-stdin
|
|
echo "REGISTRY_AUTH_FILE=$authfile" >> "$GITHUB_ENV"
|
|
- name: Build and smoke-test image
|
|
env:
|
|
COMMIT_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
podman build --pull \
|
|
--label "org.opencontainers.image.source=https://code.brunner.ninja/feedc0de/phppgadmin-kubernetes" \
|
|
--label "org.opencontainers.image.revision=${COMMIT_SHA}" \
|
|
--tag "${IMAGE}:${COMMIT_SHA}" .
|
|
podman run --rm --entrypoint httpd "${IMAGE}:${COMMIT_SHA}" -t
|
|
podman run --rm --entrypoint php "${IMAGE}:${COMMIT_SHA}" -r '
|
|
if (ini_get("session.upload_progress.enabled")) {
|
|
fwrite(STDERR, "PHP session upload progress must be disabled.\n");
|
|
exit(1);
|
|
}
|
|
foreach (["pgsql", "pdo_pgsql", "mbstring", "Zend OPcache"] as $extension) {
|
|
if (!extension_loaded($extension)) { fwrite(STDERR, "Missing PHP extension: {$extension}\n"); exit(1); }
|
|
}
|
|
'
|
|
container_id=$(podman run --detach --publish 127.0.0.1::80 "${IMAGE}:${COMMIT_SHA}")
|
|
trap 'podman rm --force "$container_id" >/dev/null 2>&1 || true' EXIT
|
|
port=$(podman inspect --format '{{ (index (index .NetworkSettings.Ports "80/tcp") 0).HostPort }}' "$container_id")
|
|
for attempt in {1..30}; do
|
|
if curl --fail --silent --show-error "http://127.0.0.1:${port}/phppgadmin/" -o "${RUNNER_TEMP}/page.html" \
|
|
&& grep -Fq phpPgAdmin "${RUNNER_TEMP}/page.html"; then exit 0; fi
|
|
sleep 1
|
|
done
|
|
podman logs "$container_id"
|
|
exit 1
|
|
- name: Push immutable image and latest
|
|
env:
|
|
COMMIT_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
app_version=$(./chart/version.sh)
|
|
podman tag "${IMAGE}:${COMMIT_SHA}" "${IMAGE}:${app_version}"
|
|
podman push "${IMAGE}:${app_version}"
|
|
podman tag "${IMAGE}:${COMMIT_SHA}" "${IMAGE}:latest"
|
|
podman push "${IMAGE}:latest"
|
|
- if: always()
|
|
run: rm -f "${RUNNER_TEMP}/quay-auth.json"
|
|
|
|
publish-chart:
|
|
if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main'
|
|
needs:
|
|
- validate
|
|
- publish-image
|
|
runs-on: linux_amd64
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Install Helm
|
|
run: |
|
|
curl --fail --silent --show-error --location \
|
|
--output "${RUNNER_TEMP}/helm.tar.gz" \
|
|
https://get.helm.sh/helm-v4.2.2-linux-amd64.tar.gz
|
|
tar -xzf "${RUNNER_TEMP}/helm.tar.gz" -C "${RUNNER_TEMP}" linux-amd64/helm
|
|
mv "${RUNNER_TEMP}/linux-amd64/helm" "${RUNNER_TEMP}/helm"
|
|
chmod 0700 "${RUNNER_TEMP}/helm"
|
|
echo "${RUNNER_TEMP}" >> "$GITHUB_PATH"
|
|
- id: chart
|
|
name: Derive chart version
|
|
env:
|
|
COMMIT_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
git fetch --tags origin main
|
|
test "$(git rev-parse origin/main)" = "$COMMIT_SHA"
|
|
version=$(./chart/version.sh)
|
|
echo "version=${version}" >> "$GITHUB_OUTPUT"
|
|
- name: Package and publish chart
|
|
env:
|
|
PACKAGE_USERNAME: ${{ secrets.PACKAGE_USERNAME }}
|
|
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
|
|
CHART_VERSION: ${{ steps.chart.outputs.version }}
|
|
COMMIT_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
test -n "$PACKAGE_USERNAME" && test -n "$PACKAGE_TOKEN"
|
|
helm lint chart
|
|
helm template phppgadmin chart --namespace default >/dev/null
|
|
helm package chart --version "$CHART_VERSION" --app-version "$CHART_VERSION" --destination "$RUNNER_TEMP"
|
|
curl --fail --silent --show-error \
|
|
--user "${PACKAGE_USERNAME}:${PACKAGE_TOKEN}" \
|
|
--request POST --upload-file "${RUNNER_TEMP}/phppgadmin-${CHART_VERSION}.tgz" \
|
|
https://code.brunner.ninja/api/packages/feedc0de/helm/api/charts
|
|
- name: Promote GitOps chart version
|
|
env:
|
|
GITOPS_TOKEN: ${{ secrets.GITOPS_TOKEN }}
|
|
CHART_VERSION: ${{ steps.chart.outputs.version }}
|
|
COMMIT_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
test -n "$GITOPS_TOKEN"
|
|
test "$(git rev-parse origin/main)" = "$COMMIT_SHA"
|
|
auth=$(printf 'feedc0de:%s' "$GITOPS_TOKEN" | base64 | tr -d '\n')
|
|
git -c "http.extraheader=AUTHORIZATION: basic ${auth}" clone --depth=1 \
|
|
https://code.brunner.ninja/feedc0de/homelab-gitops.git "$RUNNER_TEMP/gitops"
|
|
unset auth
|
|
cd "$RUNNER_TEMP/gitops"
|
|
gitops_auth=$(printf 'feedc0de:%s' "$GITOPS_TOKEN" | base64 | tr -d '\n')
|
|
unset GITOPS_TOKEN
|
|
git config user.name feedc0de
|
|
git config user.email feedc0de@users.noreply.code.brunner.ninja
|
|
sed -i -E "0,/targetRevision: [^ ]+/s//targetRevision: ${CHART_VERSION}/" bootstrap/phppgadmin.yaml
|
|
if git diff --quiet; then exit 0; fi
|
|
git add bootstrap/phppgadmin.yaml
|
|
git commit -m "Deploy phpPgAdmin chart ${CHART_VERSION}"
|
|
for attempt in 1 2 3; do
|
|
if git -c "http.extraheader=AUTHORIZATION: basic ${gitops_auth}" push origin HEAD:main; then exit 0; fi
|
|
git -c "http.extraheader=AUTHORIZATION: basic ${gitops_auth}" fetch origin main
|
|
git rebase origin/main
|
|
done
|
|
exit 1
|