diff --git a/.github/workflows/ci-docker-hotrod.yml b/.github/workflows/ci-docker-hotrod.yml index 1bba419d9a9..4b1b9cd229a 100644 --- a/.github/workflows/ci-docker-hotrod.yml +++ b/.github/workflows/ci-docker-hotrod.yml @@ -44,8 +44,21 @@ jobs: - uses: docker/setup-qemu-action@5927c834f5b4fdf503fca6f4c7eccda82949e1ee # v3.1.0 + - name: Define BUILD_FLAGS var if running on a Pull Request + run: | + case ${GITHUB_EVENT_NAME} in + pull_request) + echo "BUILD_FLAGS=-l -p linux/amd64" >> ${GITHUB_ENV} + ;; + *) + echo "BUILD_FLAGS=" >> ${GITHUB_ENV} + ;; + esac + - name: Build, test, and publish hotrod image - run: bash scripts/hotrod-integration-test.sh + run: | + bash scripts/hotrod-integration-test.sh \ + ${{ env.BUILD_FLAGS }} env: DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} diff --git a/scripts/hotrod-integration-test.sh b/scripts/hotrod-integration-test.sh index 8fc080e9378..40868066511 100755 --- a/scripts/hotrod-integration-test.sh +++ b/scripts/hotrod-integration-test.sh @@ -2,8 +2,32 @@ set -euxf -o pipefail +print_help() { + echo "Usage: $0 [-l] [-p platforms] [-h]" + echo "-h: Print help" + echo "-l: Enable local-only mode that only pushes images to local registry" + echo "-p: Comma-separated list of platforms to build for (default: all supported)" + exit 1 +} + docker_compose_file="./examples/hotrod/docker-compose.yml" platforms="linux/amd64,linux/s390x,linux/ppc64le,linux/arm64" +LOCAL_FLAG='' + +while getopts "lp:h" opt; do + case "${opt}" in + l) + # in the local-only mode the images will only be pushed to local registry + LOCAL_FLAG='-l' + ;; + p) + platforms=${OPTARG} + ;; + ?) + print_help + ;; + esac +done teardown() { echo "Tearing down..." @@ -21,14 +45,16 @@ make create-baseimg # Loop through each platform (separated by commas) for platform in $(echo "$platforms" | tr ',' ' '); do + # Extract the operating system from the platform string + os=${platform%%/*} #remove everything after the last slash # Extract the architecture from the platform string arch=${platform##*/} # Remove everything before the last slash - make "build-all-in-one" GOOS=linux GOARCH="${arch}" + make "build-all-in-one" GOOS=${os} GOARCH="${arch}" done # Build image locally (-l) for integration test bash scripts/build-upload-a-docker-image.sh -l -c example-hotrod -d examples/hotrod -p "${platforms}" -bash scripts/build-upload-a-docker-image.sh -l -b -c all-in-one -d cmd/all-in-one -p "${platforms}" -t release +bash scripts/build-upload-a-docker-image.sh ${LOCAL_FLAG} -b -c all-in-one -d cmd/all-in-one -p "${platforms}" -t release JAEGER_VERSION=$GITHUB_SHA REGISTRY="localhost:5000/" docker compose -f "$docker_compose_file" up -d