haproxy/.gitlab-ci.yml

205 lines
7.1 KiB
YAML

stages:
- dependencies
- build
- publish
variables:
TZ: "UTC"
GIT_DEPTH: "1"
.build-job: &build-job
image: registry.gitlab.com/mangadex-pub/debuilder/buster:main
needs: [ ]
before_script:
- apt -qq update
- apt install -y --no-install-recommends -qq build-essential ca-certificates cmake curl git libreadline-dev libsystemd-dev tar
lua:
<<: *build-job
stage: dependencies
script: make -C deps/lua
artifacts:
expire_in: 7 days
paths: [ "deps/lua/lua-dist.tar.gz" ]
pcre2:
<<: *build-job
stage: dependencies
script: make -C deps/pcre2
artifacts:
expire_in: 7 days
paths: [ "deps/pcre2/pcre2-dist.tar.gz" ]
quictls:
<<: *build-job
stage: dependencies
script: make -C deps/quictls
artifacts:
expire_in: 7 days
paths: [ "deps/quictls/quictls-dist.tar.gz" ]
haproxy:
<<: *build-job
stage: build
script:
- apt install -y --no-install-recommends -qq bzip2 git
- mkdir deps/lua/dist && tar -C deps/lua/dist -xf deps/lua/lua-dist.tar.gz
- mkdir deps/pcre2/dist && tar -C deps/pcre2/dist -xf deps/pcre2/pcre2-dist.tar.gz
- mkdir deps/quictls/dist && tar -C deps/quictls/dist -xf deps/quictls/quictls-dist.tar.gz
- make -C haproxy
needs:
- job: lua
artifacts: true
- job: pcre2
artifacts: true
- job: quictls
artifacts: true
artifacts:
expire_in: 7 days
paths: [ "haproxy/dist", "haproxy/haproxy-dist.tar.gz" ]
docker:
stage: publish
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [ "" ]
before_script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"gitlab-ci-token\",\"password\":\"$CI_JOB_TOKEN\"}}}" > /kaniko/.docker/config.json
script: |
set -eu
export DEBIAN_CODENAME="bullseye"
export JOB_TIMESTAMP="$(date -D '%Y-%m-%dT%H:%M:%S%Z' -d "$CI_JOB_STARTED_AT" +'%Y%m%d-%H%M')"
export HAPROXY_VERSION="$(cat haproxy/Makefile | head -n1 | cut -d'=' -f2 | tr -d ' ')"
export HAPROXY_SHORTVER="$(echo "${HAPROXY_VERSION}" | cut -d'.' -f1-2)"
echo "Building image with"
echo " -> haproxy version: $HAPROXY_VERSION ($HAPROXY_SHORTVER)"
echo " -> debian codename: $DEBIAN_CODENAME"
echo " -> git commit hash: $CI_COMMIT_SHORT_SHA"
echo " -> build timestamp: $JOB_TIMESTAMP"
export IMAGE_TAG_UNIQUE="$HAPROXY_VERSION-$DEBIAN_CODENAME-$CI_COMMIT_SHORT_SHA-$JOB_TIMESTAMP"
export IMAGE_TAG_ROLLING_COMMIT="git-$CI_COMMIT_SHORT_SHA"
export IMAGE_TAG_ROLLING_GITREF="$CI_COMMIT_REF_SLUG"
export IMAGE_TAG_VERSIONS="$HAPROXY_VERSION-$DEBIAN_CODENAME"
export IMAGE_TAG_SHORTVER="$HAPROXY_SHORTVER-$DEBIAN_CODENAME"
if [ "$CI_COMMIT_REF_NAME" != "$CI_DEFAULT_BRANCH" ]; then
export IMAGE_TAG_VERSIONS="branch-$CI_COMMIT_REF_SLUG-$IMAGE_TAG_VERSIONS"
export IMAGE_TAG_SHORTVER="branch-$CI_COMMIT_REF_SLUG-$IMAGE_TAG_SHORTVER"
echo "Git reference $CI_COMMIT_REF_NAME is not the default branch. Rewriting git rolling tag as $IMAGE_TAG_VERSIONS / $IMAGE_TAG_SHORTVER"
fi
echo "***"
echo "Will build and push image as:"
echo "- $CI_REGISTRY_IMAGE:$IMAGE_TAG_UNIQUE"
echo "- $CI_REGISTRY_IMAGE:$IMAGE_TAG_ROLLING_COMMIT"
echo "- $CI_REGISTRY_IMAGE:$IMAGE_TAG_ROLLING_GITREF"
echo "- $CI_REGISTRY_IMAGE:$IMAGE_TAG_VERSIONS"
echo "- $CI_REGISTRY_IMAGE:$IMAGE_TAG_SHORTVER"
echo "***"
(
set -x;
/kaniko/executor \
--context . \
--dockerfile Dockerfile \
--build-arg "CANONICAL_VERSION=$IMAGE_TAG_UNIQUE" \
--destination "$CI_REGISTRY_IMAGE:$IMAGE_TAG_UNIQUE" \
--destination "$CI_REGISTRY_IMAGE:$IMAGE_TAG_ROLLING_COMMIT" \
--destination "$CI_REGISTRY_IMAGE:$IMAGE_TAG_ROLLING_GITREF" \
--destination "$CI_REGISTRY_IMAGE:$IMAGE_TAG_VERSIONS" \
--destination "$CI_REGISTRY_IMAGE:$IMAGE_TAG_SHORTVER" \
--single-snapshot
)
needs:
- job: quictls
artifacts: true
- job: haproxy
artifacts: true
pkg:quictls:
image: docker.io/curlimages/curl:latest
stage: publish
needs:
- job: quictls
artifacts: true
script: |
set -eu
PKG_VER="$(cat deps/quictls/Makefile | head -n1 | cut -d'=' -f2 | tr -d ' ')"
if [ "$CI_COMMIT_REF_NAME" != "$CI_DEFAULT_BRANCH" ]; then
export PKG_VER="branch-$CI_COMMIT_REF_SLUG"
echo "Git reference $CI_COMMIT_REF_NAME is not the default branch. Setting version to $PKG_VER"
fi
curl -fsSL \
-H"JOB-TOKEN: $CI_JOB_TOKEN" \
--upload-file "deps/quictls/quictls-dist.tar.gz" \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/quictls/$PKG_VER/quictls.tar.gz"
pkg:haproxy:
image: docker.io/curlimages/curl:latest
stage: publish
needs:
- job: haproxy
artifacts: true
script: |
set -eu
PKG_VER="$(cat haproxy/Makefile | head -n1 | cut -d'=' -f2 | tr -d ' ')"
if [ "$CI_COMMIT_REF_NAME" != "$CI_DEFAULT_BRANCH" ]; then
export PKG_VER="branch-$CI_COMMIT_REF_SLUG"
echo "Git reference $CI_COMMIT_REF_NAME is not the default branch. Setting version to $PKG_VER"
fi
curl -fsSL \
-H"JOB-TOKEN: $CI_JOB_TOKEN" \
--upload-file "haproxy/haproxy-dist.tar.gz" \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/haproxy/$PKG_VER/haproxy.tar.gz"
deb:haproxy:
<<: *build-job
stage: build
script:
- apt install -y --no-install-recommends -qq bzip2 devscripts debhelper pkg-config
- mkdir deps/lua/dist && tar -C deps/lua/dist -xf deps/lua/lua-dist.tar.gz
- mkdir deps/pcre2/dist && tar -C deps/pcre2/dist -xf deps/pcre2/pcre2-dist.tar.gz
- mkdir deps/quictls/dist && tar -C deps/quictls/dist -xf deps/quictls/quictls-dist.tar.gz
- make -C haproxy dist-deb
- |
set -euo pipefail
PACKAGE_NAME="haproxy-debian"
DEB_VERSION="$(cat haproxy/*.dsc | grep -E '^Version:' | cut -d' ' -f2-)"
if [ "$CI_COMMIT_REF_NAME" != "$CI_DEFAULT_BRANCH" ]; then
export PACKAGE_NAME="haproxy-debian-branches"
export DEB_VERSION="branch-$CI_COMMIT_REF_SLUG"
echo "Git reference $CI_COMMIT_REF_NAME is not the default branch. Setting coordinates to $PACKAGE_NAME/$DEB_VERSION"
fi
GITLAB_IS_LAME_DEB_VERSION=$(echo "${DEB_VERSION}" | tr '~' '-')
echo "Publishing Debian package version ${DEB_VERSION} to haproxy-debian@${GITLAB_IS_LAME_DEB_VERSION}"
for artifact in haproxy/haproxy*.deb; do
artifact_filename=$(basename "${artifact}")
gitlab_is_lame_artifact_filename=$(echo "${artifact_filename}" | tr '~' '-' | tr '+' '-')
echo "Uploading to haproxy-debian@${DEB_VERSION}... ${artifact_filename} -> ${gitlab_is_lame_artifact_filename}"
curl -fsSL -H"JOB-TOKEN: $CI_JOB_TOKEN" \
--upload-file "${artifact}" \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${PACKAGE_NAME}/${GITLAB_IS_LAME_DEB_VERSION}/${gitlab_is_lame_artifact_filename}"
echo "OK"
done
needs:
- job: lua
artifacts: true
- job: pcre2
artifacts: true
- job: quictls
artifacts: true
artifacts:
expire_in: 7 days
paths: [ "haproxy/haproxy*" ]