Files
phppgadmin-kubernetes/.gitea/workflows/deploy.yml
T
feedc0de 7db6ae4364
Validate and deploy phpPgAdmin / Build, test and publish image (push) Failing after 2s
Validate and deploy phpPgAdmin / Validate manifests (push) Failing after 10s
Validate and deploy phpPgAdmin / Deploy to Kubernetes (push) Skipped
Fix CI registry isolation and deployment prerequisites
2026-10-14 20:57:54 +02:00

188 lines
7.1 KiB
YAML

name: Validate and deploy phpPgAdmin
on:
push:
pull_request:
env:
IMAGE: registry.brunner.ninja/feedc0de/phppgadmin
KUBECONFORM_VERSION: v0.7.0
KUBECTL_VERSION: v1.36.3
KUBERNETES_API: https://host.containers.internal:6443
KUBERNETES_TLS_SERVER_NAME: 192.168.0.2
NAMESPACE: default
jobs:
image:
name: Build, test and publish image
if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main'
runs-on: linux_amd64
timeout-minutes: 30
steps:
- name: Check out source
uses: actions/checkout@v4
- 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 image
env:
COMMIT_SHA: ${{ gitea.sha }}
run: |
set -euo pipefail
podman build \
--pull \
--label "org.opencontainers.image.base.name=registry.brunner.ninja/feedc0de/php-apache:f76304f1014f15354ec05bba7eaca376993afe72" \
--label "org.opencontainers.image.revision=${COMMIT_SHA}" \
--label "org.opencontainers.image.source=https://code.brunner.ninja/feedc0de/phppgadmin-kubernetes" \
--tag "${IMAGE}:${COMMIT_SHA}" \
.
- name: Smoke-test image
env:
COMMIT_SHA: ${{ gitea.sha }}
run: |
set -euo pipefail
podman run --rm --entrypoint httpd "${IMAGE}:${COMMIT_SHA}" -t
podman run --rm --entrypoint php "${IMAGE}:${COMMIT_SHA}" -r '
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 \
--output "${RUNNER_TEMP}/phppgadmin.html" \
"http://127.0.0.1:${port}/phppgadmin/" \
&& grep -Fq 'phpPgAdmin' "${RUNNER_TEMP}/phppgadmin.html"; then
exit 0
fi
sleep 1
done
podman logs "${container_id}"
exit 1
- name: Push image
if: gitea.ref == 'refs/heads/main'
env:
COMMIT_SHA: ${{ gitea.sha }}
run: |
set -euo pipefail
podman push "${IMAGE}:${COMMIT_SHA}"
podman tag "${IMAGE}:${COMMIT_SHA}" "${IMAGE}:latest"
podman push "${IMAGE}:latest"
- name: Remove registry credentials
if: always()
run: rm -f "${RUNNER_TEMP}/quay-auth.json"
validate:
name: Validate manifests
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@v4
- name: Validate scripts and Kubernetes resources
run: |
sh -n install.sh
bash -n create-ci-kubeconfig.sh
bash -n test.sh
podman run --rm --interactive \
"ghcr.io/yannh/kubeconform:${KUBECONFORM_VERSION}" \
-strict -ignore-missing-schemas -summary < phppgadmin.yaml
podman run --rm --interactive \
"ghcr.io/yannh/kubeconform:${KUBECONFORM_VERSION}" \
-strict -summary < ci-deployer.yaml
deploy:
name: Deploy to Kubernetes
if: gitea.ref == 'refs/heads/main'
needs:
- image
- validate
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@v4
- name: Install kubectl
run: |
curl --fail --silent --show-error --location \
--output "${RUNNER_TEMP}/kubectl" \
"https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl"
chmod 0700 "${RUNNER_TEMP}/kubectl"
- name: Configure Kubernetes access
env:
KUBE_CONFIG_BASE64: ${{ secrets.KUBE_CONFIG_BASE64 }}
run: |
test -n "${KUBE_CONFIG_BASE64}"
printf '%s' "${KUBE_CONFIG_BASE64}" | base64 --decode > "${RUNNER_TEMP}/kubeconfig"
chmod 0600 "${RUNNER_TEMP}/kubeconfig"
export KUBECONFIG="${RUNNER_TEMP}/kubeconfig"
"${RUNNER_TEMP}/kubectl" config set-cluster cluster \
--server="${KUBERNETES_API}" \
--tls-server-name="${KUBERNETES_TLS_SERVER_NAME}"
- name: Apply and verify
env:
COMMIT_SHA: ${{ gitea.sha }}
run: |
export KUBECONFIG="${RUNNER_TEMP}/kubeconfig"
sed \
"s|deployment.brunner.ninja/revision: manual|deployment.brunner.ninja/revision: ${COMMIT_SHA}|" \
phppgadmin.yaml \
| sed \
"s|registry.brunner.ninja/feedc0de/phppgadmin:latest|${IMAGE}:${COMMIT_SHA}|" \
> "${RUNNER_TEMP}/phppgadmin.yaml"
grep -Fq "deployment.brunner.ninja/revision: ${COMMIT_SHA}" \
"${RUNNER_TEMP}/phppgadmin.yaml"
grep -Fq "image: ${IMAGE}:${COMMIT_SHA}" \
"${RUNNER_TEMP}/phppgadmin.yaml"
"${RUNNER_TEMP}/kubectl" apply \
--dry-run=server \
--validate=false \
--filename "${RUNNER_TEMP}/phppgadmin.yaml"
"${RUNNER_TEMP}/kubectl" apply \
--validate=false \
--filename "${RUNNER_TEMP}/phppgadmin.yaml"
for attempt in {1..120}; do
IFS='|' read -r generation observed desired updated ready available unavailable image <<< "$(
"${RUNNER_TEMP}/kubectl" --namespace "${NAMESPACE}" \
get deployment/phppgadmin \
--output=jsonpath='{.metadata.generation}|{.status.observedGeneration}|{.spec.replicas}|{.status.updatedReplicas}|{.status.readyReplicas}|{.status.availableReplicas}|{.status.unavailableReplicas}|{.spec.template.spec.containers[0].image}'
)"
echo "Rollout ${attempt}/120: generation ${observed}/${generation}, replicas ${updated}/${desired} updated, ${ready}/${desired} ready, ${available}/${desired} available, image ${image}"
if [[ "${observed}" == "${generation}" \
&& "${updated}" == "${desired}" \
&& "${ready}" == "${desired}" \
&& "${available}" == "${desired}" \
&& ( -z "${unavailable}" || "${unavailable}" == "0" ) ]]; then
echo "phpPgAdmin deployment successfully rolled out"
exit 0
fi
sleep 5
done
echo "phpPgAdmin rollout did not complete within ten minutes" >&2
exit 1