Skip to content

Commit

Permalink
Add test for base docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
Minituff committed Oct 25, 2023
1 parent a4cff9f commit 31128b0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
echo "Running unit tests..."
./tests/tests.sh
- name: Validate Dockerfile supports multi-arch
run: |
echo "Checking if the base docker image supports amd64 and arm64..."
./tests/validate_dockerfile.sh
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

Expand Down
39 changes: 39 additions & 0 deletions tests/validate_dockerfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Read the Dockerfile and find the FROM line
from_line=$(grep '^FROM ' Dockerfile)

# Extract the image name and SHA hash
if [[ $from_line =~ FROM[[:space:]]+([^@]+)@([^[:space:]]+) ]]; then
image_name="${BASH_REMATCH[1]}"
sha_from_dockerfile="${BASH_REMATCH[2]}"
full_image_name="$image_name@$sha_from_dockerfile"

echo "Image Name: '$image_name'"
echo "Full Image Name: '$full_image_name'"
echo "SHA from image: '$sha_from_dockerfile'"
else
echo "FROM line with SHA not found in Dockerfile"
fi

# Run the docker command to get the SHA from mquery
mquery_output=$(docker run --rm mplatform/mquery:latest@sha256:938c26673f9b81f1c574e5911b79c4a9accf6aa918af575c94c9d488121db63c $image_name --platforms linux/amd64,linux/arm64)
sha_from_mquery=$(echo "$mquery_output" | grep -oP '(?<=digest: )[^\)]+')

echo "SHA from mquery: '$sha_from_mquery'"

# Compare the two SHAs
if [[ "$sha_from_dockerfile" == "$sha_from_mquery" ]]; then
echo "SHAs match. All is well."
else
echo "SHAs do not match. Check your Dockerfile."
exit 1
fi

# Check for the presence of linux/amd64 and linux/arm64 in the output
if echo "$mquery_output" | grep -q "linux/amd64" && echo "$mquery_output" | grep -q "linux/arm64"; then
echo "Both linux/amd64 and linux/arm64 are supported."
else
echo "One of linux/amd64 or linux/arm64 is not supported."
exit 1
fi

0 comments on commit 31128b0

Please sign in to comment.