From 467a18ecfd1531fdfb7abaecd3d79474a95f0e24 Mon Sep 17 00:00:00 2001 From: Jaryl Chng Date: Tue, 22 Oct 2024 21:45:42 +0800 Subject: [PATCH] dynamically select Alpine version with correct Python version pin --- Dockerfile | 5 +++-- build.template.yml | 2 +- check.sh | 29 ++++++++++++++++------------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index feb9a68..afb9bca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ -ARG PYTHON_VERSION=3.11.9 +ARG PYTHON_VERSION +ARG ALPINE_VERSION -FROM python:${PYTHON_VERSION}-alpine3.19 AS builder +FROM python:${PYTHON_VERSION}-alpine${ALPINE_VERSION} AS builder ARG VERSION ARG CHECKSUM diff --git a/build.template.yml b/build.template.yml index 5136881..93f39f7 100644 --- a/build.template.yml +++ b/build.template.yml @@ -22,7 +22,7 @@ variables: - name: docker:dind command: ["--experimental"] script: - - VERSION=$LATEST CHECKSUM=$CHECKSUM PYTHON_VERSION=$PYTHON_VERSION ./build.sh + - VERSION=$LATEST CHECKSUM=$CHECKSUM PYTHON_VERSION=$PYTHON_VERSION ALPINE_VERSION=$ALPINE_VERSION ./build.sh build:amd64: extends: .build-template diff --git a/check.sh b/check.sh index 05d4a52..57855d6 100755 --- a/check.sh +++ b/check.sh @@ -1,28 +1,31 @@ #!/bin/bash -apk add curl jq +apk add curl jq htmlq [[ ! -f EXISTING ]] || touch EXISTING EXISTING=$(cat EXISTING) echo "Existing: ${EXISTING}" -if [[ -n $OVERWRITE ]]; then - echo "Overwriting: $OVERWRITE" - LATEST=$OVERWRITE -else - INFO=$(curl https://duo.com/docs/checksums | grep 'https://dl.duosecurity.com/duoauthproxy' | grep 'src.tgz' | rev | cut -d'>' -f1 | rev) - CHECKSUM=$(echo "$INFO" | cut -d' ' -f1) - LATEST=$(echo "$INFO" | cut -d'-' -f2) - PYTHON_VERSION=$(curl https://duo.com/docs/authproxy-notes | grep -Eo 'Python to \d+\.\d+\.\d+' | head -n1 | rev | cut -d' ' -f1 | rev) - echo "Latest: ${LATEST}" - echo "Checksum: ${CHECKSUM}" - echo "Python Version: ${PYTHON_VERSION}" -fi +INFO=$(curl https://duo.com/docs/checksums | grep 'https://dl.duosecurity.com/duoauthproxy' | grep 'src.tgz' | rev | cut -d'>' -f1 | rev) +CHECKSUM=$(echo "$INFO" | cut -d' ' -f1) +LATEST=$(echo "$INFO" | cut -d'-' -f2) +PYTHON_VERSION=$(curl https://duo.com/docs/authproxy-notes | grep -Eo 'Python to \d+\.\d+\.\d+' | head -n1 | rev | cut -d' ' -f1 | rev) +for ALPINE_VERSION in $(curl -s "https://pkgs.alpinelinux.org/packages?name=python${PYTHON_VERSION%.*.*}" | htmlq -w --text 'select#branch > option' | grep -v 'Branch' | grep -v 'edge' | tac | xargs); do + if curl -s "https://pkgs.alpinelinux.org/packages?name=python${PYTHON_VERSION%.*.*}&branch=${ALPINE_VERSION}" | grep -q ${PYTHON_VERSION%.*}; then + break + fi +done + +echo "Latest: ${LATEST}" +echo "Checksum: ${CHECKSUM}" +echo "Python Version: ${PYTHON_VERSION}" +echo "Alpine Version: ${ALPINE_VERSION}" if [[ (-n "${LATEST}" && "${LATEST}" != "${EXISTING}") ]]; then mv build.template.yml build.yml sed -i "s \$CHECKSUM ${CHECKSUM} g" 'build.yml' sed -i "s \$LATEST ${LATEST} g" 'build.yml' sed -i "s \$PYTHON_VERSION ${PYTHON_VERSION} g" 'build.yml' + sed -i "s \$ALPINE_VERSION ${ALPINE_VERSION} g" 'build.yml' echo "Building..." fi