Skip to content

Commit 2a97944

Browse files
authored
Merge pull request #3371 from redhatrises/make_container_tool_variable
✨ (go/v4): Allows container tool to be configured in Makefile
2 parents 06f8164 + 1075dbf commit 2a97944

File tree

8 files changed

+96
-48
lines changed

8 files changed

+96
-48
lines changed

docs/book/src/component-config-tutorial/testdata/project/Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14+
# CONTAINER_TOOL defines the container tool to be used for building images.
15+
# Be aware that the target commands are only tested with Docker which is
16+
# scaffolded by default. However, you might want to replace it to use other
17+
# tools. (i.e. podman)
18+
CONTAINER_TOOL ?= docker
19+
1420
# Setting SHELL to bash allows bash commands to be executed by recipes.
1521
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
1622
SHELL = /usr/bin/env bash -o pipefail
@@ -73,11 +79,11 @@ run: manifests generate fmt vet ## Run a controller from your host.
7379
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
7480
.PHONY: docker-build
7581
docker-build: test ## Build docker image with the manager.
76-
docker build -t ${IMG} .
82+
$(CONTAINER_TOOL) build -t ${IMG} .
7783

7884
.PHONY: docker-push
7985
docker-push: ## Push docker image with the manager.
80-
docker push ${IMG}
86+
$(CONTAINER_TOOL) push ${IMG}
8187

8288
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
8389
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
@@ -90,10 +96,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
9096
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
9197
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
9298
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
93-
- docker buildx create --name project-v3-builder
94-
docker buildx use project-v3-builder
95-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
96-
- docker buildx rm project-v3-builder
99+
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
100+
$(CONTAINER_TOOL) buildx use project-v3-builder
101+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
102+
- $(CONTAINER_TOOL) buildx rm project-v3-builder
97103
rm Dockerfile.cross
98104

99105
##@ Deployment

pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ else
7171
GOBIN=$(shell go env GOBIN)
7272
endif
7373
74+
# CONTAINER_TOOL defines the container tool to be used for building images.
75+
# Be aware that the target commands are only tested with Docker which is
76+
# scaffolded by default. However, you might want to replace it to use other
77+
# tools. (i.e. podman)
78+
CONTAINER_TOOL ?= docker
79+
7480
# Setting SHELL to bash allows bash commands to be executed by recipes.
7581
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
7682
SHELL = /usr/bin/env bash -o pipefail
@@ -133,11 +139,11 @@ run: manifests generate fmt vet ## Run a controller from your host.
133139
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
134140
.PHONY: docker-build
135141
docker-build: test ## Build docker image with the manager.
136-
docker build -t ${IMG} .
142+
$(CONTAINER_TOOL) build -t ${IMG} .
137143
138144
.PHONY: docker-push
139145
docker-push: ## Push docker image with the manager.
140-
docker push ${IMG}
146+
$(CONTAINER_TOOL) push ${IMG}
141147
142148
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
143149
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
@@ -150,10 +156,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
150156
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
151157
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
152158
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
153-
- docker buildx create --name project-v3-builder
154-
docker buildx use project-v3-builder
155-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
156-
- docker buildx rm project-v3-builder
159+
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
160+
$(CONTAINER_TOOL) buildx use project-v3-builder
161+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
162+
- $(CONTAINER_TOOL) buildx rm project-v3-builder
157163
rm Dockerfile.cross
158164
159165
##@ Deployment

testdata/project-v4-config/Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14+
# CONTAINER_TOOL defines the container tool to be used for building images.
15+
# Be aware that the target commands are only tested with Docker which is
16+
# scaffolded by default. However, you might want to replace it to use other
17+
# tools. (i.e. podman)
18+
CONTAINER_TOOL ?= docker
19+
1420
# Setting SHELL to bash allows bash commands to be executed by recipes.
1521
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
1622
SHELL = /usr/bin/env bash -o pipefail
@@ -73,11 +79,11 @@ run: manifests generate fmt vet ## Run a controller from your host.
7379
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
7480
.PHONY: docker-build
7581
docker-build: test ## Build docker image with the manager.
76-
docker build -t ${IMG} .
82+
$(CONTAINER_TOOL) build -t ${IMG} .
7783

7884
.PHONY: docker-push
7985
docker-push: ## Push docker image with the manager.
80-
docker push ${IMG}
86+
$(CONTAINER_TOOL) push ${IMG}
8187

8288
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
8389
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
@@ -90,10 +96,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
9096
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
9197
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
9298
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
93-
- docker buildx create --name project-v3-builder
94-
docker buildx use project-v3-builder
95-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
96-
- docker buildx rm project-v3-builder
99+
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
100+
$(CONTAINER_TOOL) buildx use project-v3-builder
101+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
102+
- $(CONTAINER_TOOL) buildx rm project-v3-builder
97103
rm Dockerfile.cross
98104

99105
##@ Deployment

testdata/project-v4-declarative-v1/Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14+
# CONTAINER_TOOL defines the container tool to be used for building images.
15+
# Be aware that the target commands are only tested with Docker which is
16+
# scaffolded by default. However, you might want to replace it to use other
17+
# tools. (i.e. podman)
18+
CONTAINER_TOOL ?= docker
19+
1420
# Setting SHELL to bash allows bash commands to be executed by recipes.
1521
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
1622
SHELL = /usr/bin/env bash -o pipefail
@@ -73,11 +79,11 @@ run: manifests generate fmt vet ## Run a controller from your host.
7379
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
7480
.PHONY: docker-build
7581
docker-build: test ## Build docker image with the manager.
76-
docker build -t ${IMG} .
82+
$(CONTAINER_TOOL) build -t ${IMG} .
7783

7884
.PHONY: docker-push
7985
docker-push: ## Push docker image with the manager.
80-
docker push ${IMG}
86+
$(CONTAINER_TOOL) push ${IMG}
8187

8288
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
8389
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
@@ -90,10 +96,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
9096
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
9197
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
9298
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
93-
- docker buildx create --name project-v3-builder
94-
docker buildx use project-v3-builder
95-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
96-
- docker buildx rm project-v3-builder
99+
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
100+
$(CONTAINER_TOOL) buildx use project-v3-builder
101+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
102+
- $(CONTAINER_TOOL) buildx rm project-v3-builder
97103
rm Dockerfile.cross
98104

99105
##@ Deployment

testdata/project-v4-multigroup/Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14+
# CONTAINER_TOOL defines the container tool to be used for building images.
15+
# Be aware that the target commands are only tested with Docker which is
16+
# scaffolded by default. However, you might want to replace it to use other
17+
# tools. (i.e. podman)
18+
CONTAINER_TOOL ?= docker
19+
1420
# Setting SHELL to bash allows bash commands to be executed by recipes.
1521
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
1622
SHELL = /usr/bin/env bash -o pipefail
@@ -73,11 +79,11 @@ run: manifests generate fmt vet ## Run a controller from your host.
7379
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
7480
.PHONY: docker-build
7581
docker-build: test ## Build docker image with the manager.
76-
docker build -t ${IMG} .
82+
$(CONTAINER_TOOL) build -t ${IMG} .
7783

7884
.PHONY: docker-push
7985
docker-push: ## Push docker image with the manager.
80-
docker push ${IMG}
86+
$(CONTAINER_TOOL) push ${IMG}
8187

8288
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
8389
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
@@ -90,10 +96,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
9096
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
9197
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
9298
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
93-
- docker buildx create --name project-v3-builder
94-
docker buildx use project-v3-builder
95-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
96-
- docker buildx rm project-v3-builder
99+
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
100+
$(CONTAINER_TOOL) buildx use project-v3-builder
101+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
102+
- $(CONTAINER_TOOL) buildx rm project-v3-builder
97103
rm Dockerfile.cross
98104

99105
##@ Deployment

testdata/project-v4-with-deploy-image/Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14+
# CONTAINER_TOOL defines the container tool to be used for building images.
15+
# Be aware that the target commands are only tested with Docker which is
16+
# scaffolded by default. However, you might want to replace it to use other
17+
# tools. (i.e. podman)
18+
CONTAINER_TOOL ?= docker
19+
1420
# Setting SHELL to bash allows bash commands to be executed by recipes.
1521
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
1622
SHELL = /usr/bin/env bash -o pipefail
@@ -73,11 +79,11 @@ run: manifests generate fmt vet ## Run a controller from your host.
7379
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
7480
.PHONY: docker-build
7581
docker-build: test ## Build docker image with the manager.
76-
docker build -t ${IMG} .
82+
$(CONTAINER_TOOL) build -t ${IMG} .
7783

7884
.PHONY: docker-push
7985
docker-push: ## Push docker image with the manager.
80-
docker push ${IMG}
86+
$(CONTAINER_TOOL) push ${IMG}
8187

8288
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
8389
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
@@ -90,10 +96,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
9096
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
9197
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
9298
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
93-
- docker buildx create --name project-v3-builder
94-
docker buildx use project-v3-builder
95-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
96-
- docker buildx rm project-v3-builder
99+
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
100+
$(CONTAINER_TOOL) buildx use project-v3-builder
101+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
102+
- $(CONTAINER_TOOL) buildx rm project-v3-builder
97103
rm Dockerfile.cross
98104

99105
##@ Deployment

testdata/project-v4-with-grafana/Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14+
# CONTAINER_TOOL defines the container tool to be used for building images.
15+
# Be aware that the target commands are only tested with Docker which is
16+
# scaffolded by default. However, you might want to replace it to use other
17+
# tools. (i.e. podman)
18+
CONTAINER_TOOL ?= docker
19+
1420
# Setting SHELL to bash allows bash commands to be executed by recipes.
1521
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
1622
SHELL = /usr/bin/env bash -o pipefail
@@ -73,11 +79,11 @@ run: manifests generate fmt vet ## Run a controller from your host.
7379
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
7480
.PHONY: docker-build
7581
docker-build: test ## Build docker image with the manager.
76-
docker build -t ${IMG} .
82+
$(CONTAINER_TOOL) build -t ${IMG} .
7783

7884
.PHONY: docker-push
7985
docker-push: ## Push docker image with the manager.
80-
docker push ${IMG}
86+
$(CONTAINER_TOOL) push ${IMG}
8187

8288
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
8389
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
@@ -90,10 +96,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
9096
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
9197
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
9298
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
93-
- docker buildx create --name project-v3-builder
94-
docker buildx use project-v3-builder
95-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
96-
- docker buildx rm project-v3-builder
99+
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
100+
$(CONTAINER_TOOL) buildx use project-v3-builder
101+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
102+
- $(CONTAINER_TOOL) buildx rm project-v3-builder
97103
rm Dockerfile.cross
98104

99105
##@ Deployment

testdata/project-v4/Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14+
# CONTAINER_TOOL defines the container tool to be used for building images.
15+
# Be aware that the target commands are only tested with Docker which is
16+
# scaffolded by default. However, you might want to replace it to use other
17+
# tools. (i.e. podman)
18+
CONTAINER_TOOL ?= docker
19+
1420
# Setting SHELL to bash allows bash commands to be executed by recipes.
1521
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
1622
SHELL = /usr/bin/env bash -o pipefail
@@ -73,11 +79,11 @@ run: manifests generate fmt vet ## Run a controller from your host.
7379
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
7480
.PHONY: docker-build
7581
docker-build: test ## Build docker image with the manager.
76-
docker build -t ${IMG} .
82+
$(CONTAINER_TOOL) build -t ${IMG} .
7783

7884
.PHONY: docker-push
7985
docker-push: ## Push docker image with the manager.
80-
docker push ${IMG}
86+
$(CONTAINER_TOOL) push ${IMG}
8187

8288
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
8389
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
@@ -90,10 +96,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
9096
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
9197
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
9298
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
93-
- docker buildx create --name project-v3-builder
94-
docker buildx use project-v3-builder
95-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
96-
- docker buildx rm project-v3-builder
99+
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
100+
$(CONTAINER_TOOL) buildx use project-v3-builder
101+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
102+
- $(CONTAINER_TOOL) buildx rm project-v3-builder
97103
rm Dockerfile.cross
98104

99105
##@ Deployment

0 commit comments

Comments
 (0)