Skip to content

Commit

Permalink
Merge pull request #29 from hasheddan/imagelight
Browse files Browse the repository at this point in the history
Switch to using buildx and imagelight.mk for multi-arch builds
  • Loading branch information
hasheddan authored Jan 24, 2022
2 parents 7608c9c + 43686b0 commit 504dff7
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 43 deletions.
18 changes: 2 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ GO111MODULE = on
# ====================================================================================
# Setup Images

DOCKER_REGISTRY = crossplane
REGISTRY_ORGS = docker.io/crossplane
IMAGES = provider-digitalocean provider-digitalocean-controller
-include build/makelib/image.mk
-include build/makelib/imagelight.mk

# ====================================================================================
# Targets
Expand Down Expand Up @@ -80,20 +80,6 @@ crds.clean:

generate: crds.clean

# Ensure a PR is ready for review.
reviewable: generate lint
@go mod tidy

# Ensure branch is clean.
check-diff: reviewable
@$(INFO) checking that branch is clean
@if [ ! -z "$$(git status --porcelain)" ]; then \
$(WARN) Git status failure see below output; \
git status; \
$(FAIL); \
fi
@$(OK) branch is clean

manifests:
@$(WARN) Deprecated. Please run make generate instead.

Expand Down
2 changes: 1 addition & 1 deletion build
11 changes: 5 additions & 6 deletions cluster/images/provider-digitalocean-controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
FROM BASEIMAGE
RUN apk --no-cache add ca-certificates bash
FROM gcr.io/distroless/static@sha256:d2b0ec3141031720cf5eedef3493b8e129bc91935a43b50562fbe5429878d96b

ARG ARCH
ARG TINI_VERSION
ARG TARGETOS
ARG TARGETARCH

ADD provider /usr/local/bin/crossplane-digitalocean-provider
ADD bin/$TARGETOS\_$TARGETARCH/provider /usr/local/bin/crossplane-digitalocean-provider

EXPOSE 8080
USER 1001
USER 65532
ENTRYPOINT ["crossplane-digitalocean-provider"]
28 changes: 19 additions & 9 deletions cluster/images/provider-digitalocean-controller/Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
# ====================================================================================
# Setup Project

PLATFORMS := linux_amd64 linux_arm64
include ../../../build/makelib/common.mk

# ====================================================================================
# Options
IMAGE = $(BUILD_REGISTRY)/provider-digitalocean-controller-$(ARCH)
include ../../../build/makelib/image.mk

include ../../../build/makelib/imagelight.mk

# ====================================================================================
# Targets

img.build:
@$(INFO) docker build $(IMAGE)
@$(MAKE) BUILD_ARGS="--load" img.build.shared
@$(OK) docker build $(IMAGE)

img.publish:
@$(INFO) docker publish $(IMAGE)
@$(MAKE) BUILD_ARGS="--push" img.build.shared
@$(OK) docker publish $(IMAGE)

img.build.shared:
@cp Dockerfile $(IMAGE_TEMP_DIR) || $(FAIL)
@cp $(OUTPUT_DIR)/bin/$(OS)_$(ARCH)/provider $(IMAGE_TEMP_DIR) || $(FAIL)
@cd $(IMAGE_TEMP_DIR) && $(SED_CMD) 's|BASEIMAGE|$(OSBASEIMAGE)|g' Dockerfile || $(FAIL)
@docker build $(BUILD_ARGS) \
--build-arg ARCH=$(ARCH) \
--build-arg TINI_VERSION=$(TINI_VERSION) \
@cp -r $(OUTPUT_DIR)/bin/ $(IMAGE_TEMP_DIR)/bin || $(FAIL)
@docker buildx build $(BUILD_ARGS) \
--platform $(IMAGE_PLATFORMS) \
-t $(IMAGE) \
$(IMAGE_TEMP_DIR) || $(FAIL)
@$(OK) docker build $(IMAGE)

img.promote:
@$(INFO) docker promote $(FROM_IMAGE) to $(TO_IMAGE)
@docker buildx imagetools create -t $(TO_IMAGE) $(FROM_IMAGE)
@$(OK) docker promote $(FROM_IMAGE) to $(TO_IMAGE)
2 changes: 1 addition & 1 deletion cluster/images/provider-digitalocean/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM BASEIMAGE
FROM scratch

COPY package.yaml .
27 changes: 18 additions & 9 deletions cluster/images/provider-digitalocean/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
# ====================================================================================
# Setup Project

PLATFORMS := linux_amd64 linux_arm64
include ../../../build/makelib/common.mk

# ====================================================================================
# Options
IMAGE = $(BUILD_REGISTRY)/provider-digitalocean-$(ARCH)
OSBASEIMAGE = scratch
include ../../../build/makelib/image.mk

include ../../../build/makelib/imagelight.mk

# ====================================================================================
# Targets

img.build:
@$(INFO) docker build $(IMAGE)
@$(MAKE) BUILD_ARGS="--load" img.build.shared
@$(OK) docker build $(IMAGE)

img.publish:
@$(INFO) docker publish $(IMAGE)
@$(MAKE) BUILD_ARGS="--push" img.build.shared
@$(OK) docker publish $(IMAGE)

img.build.shared:
@cp Dockerfile $(IMAGE_TEMP_DIR) || $(FAIL)
@cp -R ../../../package $(IMAGE_TEMP_DIR) || $(FAIL)
@cd $(IMAGE_TEMP_DIR) && $(SED_CMD) 's|BASEIMAGE|$(OSBASEIMAGE)|g' Dockerfile || $(FAIL)
@cd $(IMAGE_TEMP_DIR) && $(SED_CMD) 's|VERSION|$(VERSION)|g' package/crossplane.yaml || $(FAIL)
@cd $(IMAGE_TEMP_DIR) && find package -type f -name '*.yaml' -exec cat {} >> 'package.yaml' \; -exec printf '\n---\n' \; || $(FAIL)
@docker build $(BUILD_ARGS) \
--build-arg ARCH=$(ARCH) \
--build-arg TINI_VERSION=$(TINI_VERSION) \
@docker buildx build $(BUILD_ARGS) \
--platform $(IMAGE_PLATFORMS) \
-t $(IMAGE) \
$(IMAGE_TEMP_DIR) || $(FAIL)
@$(OK) docker build $(IMAGE)

img.promote:
@$(INFO) docker promote $(FROM_IMAGE) to $(TO_IMAGE)
@docker buildx imagetools create -t $(TO_IMAGE) $(FROM_IMAGE)
@$(OK) docker promote $(FROM_IMAGE) to $(TO_IMAGE)
2 changes: 1 addition & 1 deletion cluster/local/integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ CONTROLLER_IMAGE="${BUILD_REGISTRY}/${PROJECT_NAME}-controller-${SAFEHOSTARCH}"

version_tag="$(cat ${projectdir}/_output/version)"
# tag as latest version to load into kind cluster
PACKAGE_CONTROLLER_IMAGE="${DOCKER_REGISTRY}/${PROJECT_NAME}-controller:${VERSION}"
PACKAGE_CONTROLLER_IMAGE="${PROJECT_NAME}/${PROJECT_NAME}-controller:${VERSION}"
K8S_CLUSTER="${K8S_CLUSTER:-${BUILD_REGISTRY}-inttests}"

CROSSPLANE_NAMESPACE="crossplane-system"
Expand Down

0 comments on commit 504dff7

Please sign in to comment.