diff --git a/.github/workflows/pr-containers.yml b/.github/workflows/pr-containers.yml new file mode 100644 index 0000000000..c4d21f6d45 --- /dev/null +++ b/.github/workflows/pr-containers.yml @@ -0,0 +1,37 @@ +name: build Velero containers on Dockerfile change + +on: + pull_request: + branches: + - 'main' + - 'release-**' + paths: + - 'Dockerfile' + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + name: Checkout + + - name: Set up QEMU + id: qemu + uses: docker/setup-qemu-action@v1 + with: + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + with: + version: latest + + # Although this action also calls docker-push.sh, it is not triggered + # by push, so BRANCH and TAG are empty by default. docker-push.sh will + # only build Velero image without pushing. + - name: Make Velero container without pushing to registry. + if: github.repository == 'vmware-tanzu/velero' + run: | + ./hack/docker-push.sh \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 598fbf38ac..f8592162ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -62,7 +62,8 @@ env CGO_ENABLED=0 \ COPY . /go/src/github.com/vmware-tanzu/velero RUN mkdir -p /output/usr/bin && \ - bash /go/src/github.com/vmware-tanzu/velero/hack/build-restic.sh + export GOARM=$(echo "${GOARM}" | cut -c2-) && \ + /go/src/github.com/vmware-tanzu/velero/hack/build-restic.sh # Velero image packing section FROM gcr.io/distroless/base-debian11@sha256:99133cb0878bb1f84d1753957c6fd4b84f006f2798535de22ebf7ba170bbf434 diff --git a/changelogs/unreleased/5771-blackpiglet b/changelogs/unreleased/5771-blackpiglet new file mode 100644 index 0000000000..e7c340ab97 --- /dev/null +++ b/changelogs/unreleased/5771-blackpiglet @@ -0,0 +1 @@ +Add PR container build action, which will not push image. Add GOARM parameter. \ No newline at end of file diff --git a/hack/docker-push.sh b/hack/docker-push.sh index d9f1835b8b..d675bffd34 100755 --- a/hack/docker-push.sh +++ b/hack/docker-push.sh @@ -56,6 +56,18 @@ elif [[ "$triggeredBy" == "tags" ]]; then TAG=$(echo $GITHUB_REF | cut -d / -f 3) fi +# if both BRANCH and TAG are empty, then it's triggered by PR. Use target branch instead. +# BRANCH is needed in docker buildx command to set as image tag. +# When action is triggered by PR, just build container without pushing, so set type to local. +# When action is triggered by PUSH, need to push container, so set type to registry. +if [[ -z $BRANCH && -z $TAG ]]; then + echo "Test Velero container build without pushing, when Dockerfile is changed by PR." + BRANCH="${GITHUB_BASE_REF}-container" + OUTPUT_TYPE="local,dest=." +else + OUTPUT_TYPE="registry" +fi + TAG_LATEST=false if [[ ! -z "$TAG" ]]; then echo "We're building tag $TAG" @@ -90,11 +102,9 @@ echo "BUILDX_PLATFORMS: $BUILDX_PLATFORMS" echo "Building and pushing container images." -# The use of "registry" as the buildx output type below instructs -# Docker to push the image VERSION="$VERSION" \ TAG_LATEST="$TAG_LATEST" \ BUILDX_PLATFORMS="$BUILDX_PLATFORMS" \ -BUILDX_OUTPUT_TYPE="registry" \ +BUILDX_OUTPUT_TYPE=$OUTPUT_TYPE \ make all-containers