Skip to content

Commit

Permalink
build: simplify ci by always building the arm image (#683)
Browse files Browse the repository at this point in the history
* build: simplify ci by always building the arm image
  • Loading branch information
Taepper authored Jan 28, 2025
1 parent 62197b0 commit b2d6dfe
Showing 1 changed file with 22 additions and 95 deletions.
117 changes: 22 additions & 95 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,110 +50,60 @@ jobs:
DIR_HASH=$(echo -n ${{ hashFiles('conanfile.py', 'conanprofile.docker', './Dockerfile_dependencies') }})
echo "DIR_HASH=$DIR_HASH" >> $GITHUB_ENV
- name: Determine platform build necessity
run: |
# Default PLATFORM_BUILD to false
echo "PLATFORM_BUILD=false" >> $GITHUB_ENV
# Check if architecture is amd64
if [[ "${{ matrix.arch }}" == "amd64" ]]; then
echo "PLATFORM_BUILD=true" >> $GITHUB_ENV
exit 0
fi
# Check if branch is main
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "PLATFORM_BUILD=true" >> $GITHUB_ENV
exit 0
fi
# Write the current labels to a file
cat <<EOF > event.json
${{ toJSON(github.event.pull_request.labels) }}
EOF
# Check if the PR has the label 'arm-image'
if jq -e '.[] | select(.name == "arm-image")' event.json > /dev/null; then
echo "PLATFORM_BUILD=true" >> $GITHUB_ENV
exit 0
fi
- name: Check if image exists
if: env.PLATFORM_BUILD == 'true'
- name: Check if dependency image exists
run: |
EXISTS=$(docker manifest inspect \
${{ env.DOCKER_DEPENDENCY_IMAGE_NAME }}:filehash-${{ env.DIR_HASH }}-${{ matrix.arch }} \
> /dev/null 2>&1 && echo "true" || echo "false")
echo "CACHE_HIT=$EXISTS" >> $GITHUB_ENV
- name: Build and push image if input files changed
if: env.CACHE_HIT == 'false' && env.PLATFORM_BUILD == 'true'
- name: Build and push dependency image if input files changed
if: env.CACHE_HIT == 'false'
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile_dependencies
push: true
tags: ${{ env.DOCKER_DEPENDENCY_IMAGE_NAME }}:filehash-${{ env.DIR_HASH }}-${{ matrix.arch }}
cache-from: type=gha,ref=builder-image-cache-${{ hashFiles('conanfile.py', 'Dockerfile') }}
cache-to: type=gha,mode=min,ref=builder-image-cache-${{ hashFiles('conanfile.py', 'Dockerfile') }}
platforms: "linux/${{ matrix.arch }}"
cache-from: type=gha,ref=dependency-image-cache-${{ matrix.arch }}-${{ hashFiles('conanfile.py', 'Dockerfile') }}
cache-to: type=gha,mode=min,ref=dependency-image-cache-${{ hashFiles('conanfile.py', 'Dockerfile') }}

- name: Tag dependency image with commit hash
if: env.PLATFORM_BUILD == 'true'
run: |
docker buildx imagetools create \
--tag ${{ env.DOCKER_DEPENDENCY_IMAGE_NAME }}:commit-${{ env.HEAD_SHA }}-${{ matrix.arch }} \
${{ env.DOCKER_DEPENDENCY_IMAGE_NAME }}:filehash-${{ env.DIR_HASH }}-${{ matrix.arch }}
- name: Build and push production image
if: env.PLATFORM_BUILD == 'true'
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: "linux/${{ matrix.arch }}"
cache-from: type=gha,ref=${{ github.ref_name }}-image-cache
cache-to: type=gha,mode=min,ref=${{ github.ref_name }}-image-cache
tags: ${{ env.DOCKER_IMAGE_NAME }}:commit-${{ env.HEAD_SHA }}-${{ matrix.arch }}
build-args: |
DEPENDENCY_IMAGE=${{ env.DOCKER_DEPENDENCY_IMAGE_NAME }}:commit-${{ env.HEAD_SHA }}-${{ matrix.arch }}
unitTests:
name: Unit tests
needs: dockerImage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Determine HEAD_SHA
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "HEAD_SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
else
echo "HEAD_SHA=${{ github.sha }}" >> $GITHUB_ENV
fi
- name: Build unit test image
uses: docker/build-push-action@v6
with:
context: .
target: builder
tags: builder
load: true
cache-from: type=gha,ref=${{ github.ref_name }}-image-cache
cache-to: type=gha,mode=min,ref=${{ github.ref_name }}-image-cache
cache-from: type=gha,ref=image-cache-${{ github.ref_name }}-${{ matrix.arch }}
cache-to: type=gha,mode=min,ref=image-cache-${{ github.ref_name }}-${{ matrix.arch }}
build-args: |
DEPENDENCY_IMAGE=${{ env.DOCKER_DEPENDENCY_IMAGE_NAME }}:commit-${{ env.HEAD_SHA }}-amd64
DEPENDENCY_IMAGE=${{ env.DOCKER_DEPENDENCY_IMAGE_NAME }}:commit-${{ env.HEAD_SHA }}-${{ matrix.arch }}
- name: Run unit tests
run: |
docker run \
--entrypoint "./silo_test" \
builder
- name: Build and push production image
uses: docker/build-push-action@v6
with:
context: .
push: true
cache-from: type=gha,ref=image-cache-${{ github.ref_name }}-${{ matrix.arch }}
cache-to: type=gha,mode=min,ref=image-cache-${{ github.ref_name }}-${{ matrix.arch }}
tags: ${{ env.DOCKER_IMAGE_NAME }}:commit-${{ env.HEAD_SHA }}-${{ matrix.arch }}
build-args: |
DEPENDENCY_IMAGE=${{ env.DOCKER_DEPENDENCY_IMAGE_NAME }}:commit-${{ env.HEAD_SHA }}-${{ matrix.arch }}
multiPlatformImages:
name: Create multi-platform images
needs: dockerImage
Expand All @@ -177,30 +127,6 @@ jobs:
echo "HEAD_SHA=${{ github.sha }}" >> $GITHUB_ENV
fi
- name: Detect all platforms with built images
run: |
PLATFORMS=""
PLATFORMS_TO_CHECK=(
"${{ env.DOCKER_IMAGE_NAME }}:commit-${{ env.HEAD_SHA }}-arm64"
"${{ env.DOCKER_IMAGE_NAME }}:commit-${{ env.HEAD_SHA }}-amd64"
)
for PLATFORM in "${PLATFORMS_TO_CHECK[@]}"; do
echo "Checking existence of: $PLATFORM"
if docker manifest inspect "$PLATFORM" > /dev/null 2>&1; then
echo "Image for $PLATFORM exists"
PLATFORMS+="$PLATFORM "
else
echo "Image for $PLATFORM does not exist"
fi
done
# Trim trailing space from PLATFORMS
PLATFORMS=$(echo "$PLATFORMS" | sed 's/[[:space:]]*$//')
echo "PLATFORM_SPECIFIC_IMAGES=$PLATFORMS" >> $GITHUB_ENV
- name: Docker metadata
id: dockerMetadataImage
uses: docker/metadata-action@v5
Expand All @@ -216,7 +142,8 @@ jobs:
TAGS=(${{ steps.dockerMetadataImage.outputs.tags }})
for TAG in "${TAGS[@]}"; do
docker buildx imagetools create --tag $TAG \
${{ env.PLATFORM_SPECIFIC_IMAGES }}
"${{ env.DOCKER_IMAGE_NAME }}:commit-${{ env.HEAD_SHA }}-arm64" \
"${{ env.DOCKER_IMAGE_NAME }}:commit-${{ env.HEAD_SHA }}-amd64"
done
endToEndTests:
Expand Down

0 comments on commit b2d6dfe

Please sign in to comment.