Skip to content

Commit

Permalink
Add GOARM in Restic builder. Add PR container build action.
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Jiang <blackpiglet@gmail.com>
  • Loading branch information
Xun Jiang committed Jan 18, 2023
1 parent fce9669 commit 1810a97
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/pr-containers.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions changelogs/unreleased/5771-blackpiglet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add PR container build action, which will not push image. Add GOARM parameter.
16 changes: 13 additions & 3 deletions hack/docker-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

0 comments on commit 1810a97

Please sign in to comment.