Build container image #42
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build container image | |
on: | |
schedule: | |
- cron: "55 4 * * *" | |
workflow_call: | |
workflow_dispatch: | |
permissions: | |
contents: read | |
jobs: | |
image: | |
name: Build container image | |
runs-on: ubuntu-24.04 | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3 | |
with: | |
registry: ghcr.io | |
username: uniget-bot | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Install uniget | |
uses: uniget-org/uniget-action@2801de6989bb0c244342f750b29e6451498ba742 # v1 | |
with: | |
prefix: helper | |
tools: jq regclient | |
- name: Fetch release asset | |
run: | | |
INPUT_VERSION="${{ inputs.tag }}" | |
if test -n "${INPUT_VERSION}"; then | |
VERSION="${INPUT_VERSION#v}" | |
else | |
VERSION="$( uniget --version | cut -d' ' -f3 )" | |
fi | |
if test -z "${VERSION}"; then | |
echo "### Unable to determine version from input (${INPUT_VERSION}) or uniget" | |
exit 1 | |
fi | |
echo "VERSION=${VERSION}" >>"${GITHUB_ENV}" | |
echo "### Downloading from release ${VERSION}" | |
for ARCH in x86_64 aarch64; do | |
case "${ARCH}" in | |
x86_64) | |
ALT_ARCH=amd64 | |
;; | |
aarch64) | |
ALT_ARCH=arm64 | |
;; | |
*) | |
echo "### Unsupported architecture ${ARCH}" | |
exit 1 | |
;; | |
esac | |
echo "### Downloading for architecture ${ARCH} (${ALT_ARCH})" | |
mkdir -p "dist/default_linux_${ALT_ARCH}" | |
url="https://github.com/uniget-org/cli/releases/download/v${VERSION}/uniget_Linux_${ARCH}.tar.gz" | |
echo "### Downloading from ${url}" | |
curl --silent --show-error --location --fail "${url}" \ | |
| tar --extract --gzip --directory "dist/default_linux_${ALT_ARCH}" uniget | |
done | |
- name: Build systemd container image | |
run: | | |
echo "### Building container image for version ${VERSION}" | |
docker buildx build . \ | |
--target systemd-uniget \ | |
--platform linux/amd64,linux/arm64 \ | |
--build-arg version="${VERSION}" \ | |
--tag "ghcr.io/uniget-org/cli:${VERSION}" \ | |
--push | |
LATEST_VERSION="$( | |
./helper/usr/local/bin/regctl tag list ghcr.io/uniget-org/cli \ | |
| grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' \ | |
| sort -Vr \ | |
| head -n 1 | |
)" | |
if test -z "${LATEST_VERSION}"; then | |
echo "### No tags found" | |
exit | |
fi | |
echo "### Tagging ${LATEST_VERSION} as latest" | |
if ! ./helper/usr/local/bin/regctl manifest get ghcr.io/uniget-org/cli:${LATEST_VERSION}; then | |
echo " Tag ${LATEST_VERSION} does not exist" | |
exit | |
fi | |
./helper/usr/local/bin/regctl image copy \ | |
"ghcr.io/uniget-org/cli:${VERSION}" \ | |
"ghcr.io/uniget-org/cli:${LATEST_VERSION}" | |
- name: Build alpine container image | |
run: | | |
echo "### Building container image for version ${VERSION}" | |
docker buildx build . \ | |
--target alpine-uniget \ | |
--platform linux/amd64,linux/arm64 \ | |
--build-arg version="${VERSION}" \ | |
--tag "ghcr.io/uniget-org/cli:alpine-${VERSION}" \ | |
--push | |
- name: Build noble container image | |
run: | | |
echo "### Building container image for version ${VERSION}" | |
docker buildx build . \ | |
--target ubuntu2404-uniget \ | |
--platform linux/amd64,linux/arm64 \ | |
--build-arg version="${VERSION}" \ | |
--tag "ghcr.io/uniget-org/cli:noble-${VERSION}" \ | |
--push |