755a966541
Build and push CoqDecks / build (push) Has been cancelled
Skip --import-cache when the cache tag doesn't yet exist in the registry. Some registries time out on missing tags rather than returning 404, causing buildctl to exit non-zero even after a successful build and push, which aborted the client build. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
109 lines
4.2 KiB
YAML
109 lines
4.2 KiB
YAML
name: Build and push CoqDecks
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: native
|
|
timeout-minutes: 120
|
|
|
|
steps:
|
|
- name: Build and push CoqDecks images with BuildKit
|
|
run: |
|
|
kubectl -n ci delete job coqdecks-buildkit --ignore-not-found=true --wait=true
|
|
|
|
BRANCH=${GITEA_REF_NAME:-${GITHUB_REF_NAME:-main}}
|
|
cat <<'EOF' | sed "s|__BRANCH__|${BRANCH}|g" | kubectl apply -f -
|
|
apiVersion: batch/v1
|
|
kind: Job
|
|
metadata:
|
|
name: coqdecks-buildkit
|
|
namespace: ci
|
|
spec:
|
|
backoffLimit: 0
|
|
template:
|
|
spec:
|
|
restartPolicy: Never
|
|
initContainers:
|
|
- name: prepare
|
|
image: alpine/git:latest
|
|
command: ["sh", "-c"]
|
|
args:
|
|
- |
|
|
set -eux
|
|
git clone --depth 1 --branch __BRANCH__ https://git.alocoq.fr/alois/CoqDecks.git /workspace/repo
|
|
volumeMounts:
|
|
- name: workspace
|
|
mountPath: /workspace
|
|
|
|
containers:
|
|
- name: buildkit
|
|
image: moby/buildkit:latest
|
|
securityContext:
|
|
privileged: true
|
|
command: ["sh", "-c"]
|
|
args:
|
|
- |
|
|
set -eux
|
|
|
|
REG=registry.git.svc.cluster.local:5000
|
|
|
|
mkdir -p /etc/buildkit
|
|
printf '[registry."%s"]\n http = true\n insecure = true\n' "$REG" > /etc/buildkit/buildkitd.toml
|
|
|
|
# Only pass --import-cache when the tag already exists in the
|
|
# registry. On first run the tag is absent and some registries
|
|
# time out rather than returning 404, which makes buildctl exit
|
|
# non-zero even though the build and push succeeded.
|
|
cache_flag() {
|
|
local image="$1" tag="$2"
|
|
if wget -qO- "http://$REG/v2/$image/tags/list" 2>/dev/null | grep -q "\"$tag\""; then
|
|
echo "--import-cache type=registry,ref=$REG/$image:$tag"
|
|
fi
|
|
}
|
|
|
|
# Build server image
|
|
buildctl-daemonless.sh build \
|
|
--frontend=dockerfile.v0 \
|
|
--local context=/workspace/repo/server \
|
|
--local dockerfile=/workspace/repo/server \
|
|
$(cache_flag coqdecks-cache server) \
|
|
--export-cache type=registry,ref=$REG/coqdecks-cache:server,mode=max \
|
|
--output type=image,name=$REG/coqdecks-server:latest,push=true,registry.insecure=true
|
|
|
|
# Build client image
|
|
buildctl-daemonless.sh build \
|
|
--frontend=dockerfile.v0 \
|
|
--local context=/workspace/repo/client \
|
|
--local dockerfile=/workspace/repo/client \
|
|
$(cache_flag coqdecks-cache client) \
|
|
--export-cache type=registry,ref=$REG/coqdecks-cache:client,mode=max \
|
|
--output type=image,name=$REG/coqdecks-client:latest,push=true,registry.insecure=true
|
|
volumeMounts:
|
|
- name: workspace
|
|
mountPath: /workspace
|
|
|
|
volumes:
|
|
- name: workspace
|
|
emptyDir: {}
|
|
EOF
|
|
|
|
- name: Wait for build
|
|
run: |
|
|
kubectl -n ci wait --for=condition=complete job/coqdecks-buildkit --timeout=7200s
|
|
|
|
- name: Show build logs
|
|
if: always()
|
|
run: |
|
|
kubectl -n ci logs job/coqdecks-buildkit -c prepare || true
|
|
kubectl -n ci logs job/coqdecks-buildkit -c buildkit || true
|
|
|
|
- name: Cleanup
|
|
if: always()
|
|
run: |
|
|
kubectl -n ci delete job coqdecks-buildkit --ignore-not-found=true --wait=true
|