Add `docker-buildx` target to `Makefile`
To allow building a multi-platform container image using `buildx`. Various configuration flags allow for fine(r)-grain control over the build process: - `BASE_IMG`: FQDN of the base image that should be used, without a tag. - `BASE_TAG: tag of the base image that should be used. Allows checksum sum to be included. - `BUILDX_PLATFORMS`: platforms to target for the final container image. - `BUILDX_ARGS`: additional `docker buildx build` arguments, e.g. `--push` to push the result to a (local) image registry. Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
parent
869c7960e3
commit
c9e3f97470
|
@ -1,4 +1,4 @@
|
||||||
FROM ghcr.io/hiddeco/golang-with-libgit2:dev as builder
|
FROM ghcr.io/hiddeco/golang-with-libgit2:dev as build
|
||||||
|
|
||||||
# Use the GitHub Actions uid:gid combination for proper fs permissions
|
# Use the GitHub Actions uid:gid combination for proper fs permissions
|
||||||
RUN groupadd -g 116 test && \
|
RUN groupadd -g 116 test && \
|
||||||
|
|
|
@ -44,11 +44,11 @@ jobs:
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
- name: Build container image
|
- name: Build container image
|
||||||
run: make docker-build IMG=test/source-controller:latest
|
run: make docker-build IMG=test/source-controller TAG=latest
|
||||||
- name: Load test image
|
- name: Load test image
|
||||||
run: kind load docker-image test/source-controller:latest
|
run: kind load docker-image test/source-controller:latest
|
||||||
- name: Deploy controller
|
- name: Deploy controller
|
||||||
run: make dev-deploy IMG=test/source-controller:latest
|
run: make dev-deploy IMG=test/source-controller TAG=latest
|
||||||
- name: Run smoke tests
|
- name: Run smoke tests
|
||||||
run: |
|
run: |
|
||||||
kubectl -n source-system apply -f ./config/samples
|
kubectl -n source-system apply -f ./config/samples
|
||||||
|
|
|
@ -37,7 +37,7 @@ RUN groupadd controller && \
|
||||||
useradd --gid controller --shell /bin/sh --create-home controller
|
useradd --gid controller --shell /bin/sh --create-home controller
|
||||||
|
|
||||||
# Copy libgit2
|
# Copy libgit2
|
||||||
COPY --from=build /libgit2/lib/* /usr/local/lib/
|
COPY --from=build /libgit2/lib/ /usr/local/lib/
|
||||||
RUN ldconfig
|
RUN ldconfig
|
||||||
|
|
||||||
# Upgrade packages and install runtime dependencies
|
# Upgrade packages and install runtime dependencies
|
||||||
|
|
31
Makefile
31
Makefile
|
@ -1,10 +1,17 @@
|
||||||
# Image URL to use all building/pushing image targets
|
# Image URL to use all building/pushing image targets
|
||||||
IMG ?= fluxcd/source-controller:latest
|
IMG ?= fluxcd/source-controller
|
||||||
|
TAG ?= latest
|
||||||
|
|
||||||
# Base image used to build the Go binary
|
# Base image used to build the Go binary
|
||||||
BASE_IMG ?= ghcr.io/hiddeco/golang-with-libgit2
|
BASE_IMG ?= ghcr.io/hiddeco/golang-with-libgit2
|
||||||
BASE_TAG ?= dev
|
BASE_TAG ?= dev
|
||||||
|
|
||||||
|
# Allows for defining additional Docker buildx arguments,
|
||||||
|
# e.g. '--push'.
|
||||||
|
BUILDX_ARGS ?=
|
||||||
|
# Architectures to build images for
|
||||||
|
BUILDX_PLATFORMS ?= linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
|
||||||
# Produce CRDs that work back to Kubernetes 1.16
|
# Produce CRDs that work back to Kubernetes 1.16
|
||||||
CRD_OPTIONS ?= crd:crdVersions=v1
|
CRD_OPTIONS ?= crd:crdVersions=v1
|
||||||
|
|
||||||
|
@ -60,12 +67,12 @@ uninstall: manifests ## Uninstall CRDs from a cluster
|
||||||
kustomize build config/crd | kubectl delete -f -
|
kustomize build config/crd | kubectl delete -f -
|
||||||
|
|
||||||
deploy: manifests ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
|
deploy: manifests ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
|
||||||
cd config/manager && kustomize edit set image fluxcd/source-controller=${IMG}
|
cd config/manager && kustomize edit set image fluxcd/source-controller=$(IMG):$(TAG)
|
||||||
kustomize build config/default | kubectl apply -f -
|
kustomize build config/default | kubectl apply -f -
|
||||||
|
|
||||||
dev-deploy: ## Deploy controller dev image in the configured Kubernetes cluster in ~/.kube/config
|
dev-deploy: ## Deploy controller dev image in the configured Kubernetes cluster in ~/.kube/config
|
||||||
mkdir -p config/dev && cp config/default/* config/dev
|
mkdir -p config/dev && cp config/default/* config/dev
|
||||||
cd config/dev && kustomize edit set image fluxcd/source-controller=${IMG}
|
cd config/dev && kustomize edit set image fluxcd/source-controller=$(IMG):$(TAG)
|
||||||
kustomize build config/dev | kubectl apply -f -
|
kustomize build config/dev | kubectl apply -f -
|
||||||
rm -rf config/dev
|
rm -rf config/dev
|
||||||
|
|
||||||
|
@ -84,7 +91,7 @@ fmt: ## Run go fmt against code
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
cd api; go fmt ./...
|
cd api; go fmt ./...
|
||||||
|
|
||||||
vet: ## Run go vet against code
|
vet: $(LIBGIT2) ## Run go vet against code
|
||||||
PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig \
|
PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig \
|
||||||
go vet ./...
|
go vet ./...
|
||||||
cd api; go vet ./...
|
cd api; go vet ./...
|
||||||
|
@ -92,14 +99,22 @@ vet: ## Run go vet against code
|
||||||
generate: controller-gen ## Generate API code
|
generate: controller-gen ## Generate API code
|
||||||
cd api; $(CONTROLLER_GEN) object:headerFile="../hack/boilerplate.go.txt" paths="./..."
|
cd api; $(CONTROLLER_GEN) object:headerFile="../hack/boilerplate.go.txt" paths="./..."
|
||||||
|
|
||||||
docker-build: ## Build the docker image
|
docker-build: ## Build the Docker image
|
||||||
docker build \
|
docker build \
|
||||||
--build-arg BASE_IMG=$(BASE_IMG) \
|
--build-arg BASE_IMG=$(BASE_IMG) \
|
||||||
--build-arg BASE_TAG=$(BASE_TAG) \
|
--build-arg BASE_TAG=$(BASE_TAG) \
|
||||||
-t ${IMG} .
|
-t $(IMG):$(TAG) .
|
||||||
|
|
||||||
|
docker-buildx: ## Build the cross-platform Docker image
|
||||||
|
docker buildx build \
|
||||||
|
--build-arg BASE_IMG=$(BASE_IMG) \
|
||||||
|
--build-arg BASE_TAG=$(BASE_TAG) \
|
||||||
|
--platform=$(BUILDX_PLATFORMS) \
|
||||||
|
-t $(IMG):$(TAG) \
|
||||||
|
$(BUILDX_ARGS) .
|
||||||
|
|
||||||
docker-push: ## Push docker image
|
docker-push: ## Push Docker image
|
||||||
docker push ${IMG}
|
docker push $(IMG):$(TAG)
|
||||||
|
|
||||||
controller-gen: ## Find or download controller-gen
|
controller-gen: ## Find or download controller-gen
|
||||||
ifeq (, $(shell which controller-gen))
|
ifeq (, $(shell which controller-gen))
|
||||||
|
|
Loading…
Reference in New Issue