Skip to content

Commit

Permalink
Build Multi-Arch Images 📦 (#499)
Browse files Browse the repository at this point in the history
* Build etcdbrctl in Docker container

* Let pipeline build multi-arch images
  • Loading branch information
timuthy authored Jul 8, 2022
1 parent f1bf59f commit 1a3a202
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
26 changes: 6 additions & 20 deletions .ci/build
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,9 @@ VERSION_FILE="$(${READLINK_BIN} -f "${SOURCE_PATH}/VERSION")"
VERSION="$(cat "${VERSION_FILE}")"
GIT_SHA=$(git rev-parse --short HEAD || echo "GitNotFound")

# If no LOCAL_BUILD environment variable is set, we configure the `go build` command
# to build for linux OS, amd64 architectures and without CGO enablement.
if [[ -z "$LOCAL_BUILD" ]]; then
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-a \
-mod vendor \
-v \
-o "${BINARY_PATH}/linux-amd64/etcdbrctl" \
-ldflags "-w -X ${REPOSITORY}/pkg/version.Version=${VERSION} -X ${REPOSITORY}/pkg/version.GitSHA=${GIT_SHA}" \
main.go

# If the LOCAL_BUILD environment variable is set, we simply run `go build`.
else
go build \
-v \
-mod vendor \
-o "${BINARY_PATH}/etcdbrctl" \
-ldflags "-w -X ${REPOSITORY}/pkg/version.Version=${VERSION} -X ${REPOSITORY}/pkg/version.GitSHA=${GIT_SHA}" \
main.go
fi
CGO_ENABLED=0 go build \
-v \
-mod vendor \
-o "${BINARY_PATH}/etcdbrctl" \
-ldflags "-w -X ${REPOSITORY}/pkg/version.Version=${VERSION} -X ${REPOSITORY}/pkg/version.GitSHA=${GIT_SHA}" \
main.go
4 changes: 4 additions & 0 deletions .ci/pipeline_definitions
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ etcd-backup-restore:
'inject-commit-hash'
inject_effective_version: true
publish:
oci-builder: docker-buildx
platforms:
- linux/amd64
- linux/arm64
dockerimages:
etcdbrctl:
registry: 'gcr-readwrite'
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ build-local:

.PHONY: docker-build
docker-build:
@.ci/build
@if [[ ! -f $(BIN_DIR)/linux-amd64/etcdbrctl ]]; then echo "No binary found. Please run 'make build'"; false; fi
@docker build -t ${IMG} -f $(BUILD_DIR)/Dockerfile --rm .

.PHONY: docker-push
Expand Down
11 changes: 9 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM eu.gcr.io/gardener-project/3rd/alpine:3.10.1
FROM golang:1.18.3 as builder

WORKDIR /go/src/github.com/gardener/backup-restore
COPY . .

RUN make build

FROM alpine:3.15.4

RUN apk add --update bash curl

COPY ./bin/linux-amd64/etcdbrctl /usr/local/bin/etcdbrctl
COPY --from=builder /go/src/github.com/gardener/backup-restore/bin/etcdbrctl /usr/local/bin/etcdbrctl
WORKDIR /
ENTRYPOINT ["/usr/local/bin/etcdbrctl"]

0 comments on commit 1a3a202

Please sign in to comment.