Skip to content

Commit

Permalink
ci: move build into bash file
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp committed Aug 26, 2024
1 parent b99c1e9 commit 417bc4b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
37 changes: 37 additions & 0 deletions .github/scripts/build-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -euo pipefail

get_digest() {
local variant="$1"
local arch="$2"
find "/tmp/digests/digests-${variant}-${arch}" -type f -exec basename {} \;
}

create_manifest_list() {
local namespace="$1"
local variant="$2"
local digest_amd64="$3"
local digest_arm64="$4"

docker buildx imagetools create \
"$(jq -cr ".target.\"docker-metadata-action\".tags | map(select(startswith(\"${namespace}\")) | \"-t \" + .) | join(\" \")" "/tmp/bake-meta-${variant}-amd64.json")" \
"${namespace}@sha256:${digest_amd64}" \
"${namespace}@sha256:${digest_arm64}"
}

# Get list of unique variants
mapfile -t variants < <(find . -maxdepth 1 -name "bake-meta-*.json" -exec basename {} \; | sed -E 's/bake-meta-//; s/-amd64.json|-arm64.json//g' | sort -u)

for variant in "${variants[@]}"; do
echo "Processing variant: $variant"

# Fetch digests for amd64 and arm64 architectures
digest_amd64=$(get_digest "$variant" "amd64")
digest_arm64=$(get_digest "$variant" "arm64")
echo "Digest AMD64: $digest_amd64"
echo "Digest ARM64: $digest_arm64"

create_manifest_list "${DOCKER_NAMESPACE}" "$variant" "$digest_amd64" "$digest_arm64"
create_manifest_list "${GHCR_NAMESPACE}" "$variant" "$digest_amd64" "$digest_arm64"
done
24 changes: 2 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,27 +176,7 @@ jobs:
buildkitd-flags: "--debug"

- name: 🚀 Create manifest list and push
working-directory: /tmp
run: |
variants=($(ls bake-meta-*.json | sed -E 's/bake-meta-//; s/-amd64.json|-arm64.json//g' | sort -u))
for variant in "${variants[@]}"; do
# Fetch digests for amd64 and arm64 architectures
DIGEST_AMD64=$(basename $(ls /tmp/digests/digests-${variant}-amd64/*))
DIGEST_ARM64=$(basename $(ls /tmp/digests/digests-${variant}-arm64/*))
echo "Digest AMD64: $DIGEST_AMD64"
echo "Digest ARM64: $DIGEST_ARM64"
# Create the manifest list for Docker Hub
docker buildx imagetools create $(jq -cr ".target.\"docker-metadata-action\".tags | map(select(startswith(\"${DOCKER_NAMESPACE}\")) | \"-t \" + .) | join(\" \")" /tmp/bake-meta-${variant}-amd64.json) \
"${DOCKER_NAMESPACE}@sha256:${DIGEST_AMD64}" \
"${DOCKER_NAMESPACE}@sha256:${DIGEST_ARM64}"
# Create the manifest list for GHCR
docker buildx imagetools create $(jq -cr ".target.\"docker-metadata-action\".tags | map(select(startswith(\"${GHCR_NAMESPACE}\")) | \"-t \" + .) | join(\" \")" /tmp/bake-meta-${variant}-amd64.json) \
"${GHCR_NAMESPACE}@sha256:${DIGEST_AMD64}" \
"${GHCR_NAMESPACE}@sha256:${DIGEST_ARM64}"
done
shell: bash
run: .github/scripts/build-images.sh

...

0 comments on commit 417bc4b

Please sign in to comment.