Skip to content

Commit 4a7e6f2

Browse files
committed
Support building with podman
1 parent f13aac6 commit 4a7e6f2

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

Containerfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2021 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Containerfile for podman
16+
#
17+
# Ideally we would just use Dockerfile to avoid maintaining 2 files. However,
18+
# the Dockerfile is currently using some features [1] that podman doesn't
19+
# support. We should aim to re-merge these files eventually. In the meantime
20+
# we need to keep them consistent.
21+
#
22+
# [1] * RUN --mount=type=...
23+
# * podman can't pull dockerfile:1.1-experimental: unsupported docker v2s2
24+
# media type: "application/vnd.oci.image.layer.v1.tar+gzip"
25+
26+
# Build the manager binary
27+
FROM golang:1.16.0 as builder
28+
WORKDIR /workspace
29+
30+
# Run this with docker build --build_arg goproxy=$(go env GOPROXY) to override the goproxy
31+
ARG goproxy=https://proxy.golang.org
32+
ENV GOPROXY=$goproxy
33+
34+
# Copy the Go Modules manifests
35+
COPY go.mod go.mod
36+
COPY go.sum go.sum
37+
38+
# Cache deps before building and copying source so that we don't need to re-download as much
39+
# and so that source changes don't invalidate our downloaded layer
40+
RUN go mod download
41+
42+
# Copy the sources
43+
COPY ./ ./
44+
45+
# Build
46+
ARG package=.
47+
ARG ARCH
48+
ARG ldflags
49+
50+
# Do not force rebuild of up-to-date packages (do not use -a) and use the compiler cache folder
51+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
52+
go build -ldflags "${ldflags} -extldflags '-static'" \
53+
-o manager ${package}
54+
55+
# Production image
56+
FROM gcr.io/distroless/static:nonroot
57+
WORKDIR /
58+
COPY --from=builder /workspace/manager .
59+
# Use uid of nonroot user (65532) because kubernetes expects numeric user when applying pod security policies
60+
USER 65532
61+
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
5757
DOCKER_CLI_EXPERIMENTAL=enabled
5858
DOCKER_BUILDKIT=1
5959

60+
PODMAN ?= 0
61+
ifeq ($(PODMAN), 1)
62+
CONTAINERFILE ?= Containerfile
63+
else
64+
CONTAINERFILE ?= Dockerfile
65+
endif
66+
6067
# Release variables
6168

6269
STAGING_REGISTRY := gcr.io/k8s-staging-capi-openstack
@@ -121,7 +128,7 @@ test-e2e: $(GINKGO) $(KIND) $(KUSTOMIZE) e2e-image ## Run e2e tests
121128

122129
.PHONY: e2e-image
123130
e2e-image: docker-pull-prerequisites
124-
docker build -f Dockerfile --tag="gcr.io/k8s-staging-capi-openstack/capi-openstack-controller:e2e" .
131+
docker build -f $(CONTAINERFILE) --tag="gcr.io/k8s-staging-capi-openstack/capi-openstack-controller:e2e" .
125132

126133
CONFORMANCE_E2E_ARGS ?= -kubetest.config-file=$(KUBETEST_CONF_PATH)
127134
CONFORMANCE_E2E_ARGS += $(E2E_ARGS)
@@ -210,15 +217,15 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
210217

211218
.PHONY: docker-build
212219
docker-build: docker-pull-prerequisites ## Build the docker image for controller-manager
213-
docker build --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg LDFLAGS="$(LDFLAGS)" . -t $(CONTROLLER_IMG)-$(ARCH):$(TAG)
220+
docker build -f $(CONTAINERFILE) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg LDFLAGS="$(LDFLAGS)" . -t $(CONTROLLER_IMG)-$(ARCH):$(TAG)
214221

215222
.PHONY: docker-push
216223
docker-push: ## Push the docker image
217224
docker push $(CONTROLLER_IMG)-$(ARCH):$(TAG)
218225

219226
.PHONY: docker-pull-prerequisites
220227
docker-pull-prerequisites:
221-
docker pull docker.io/docker/dockerfile:1.1-experimental
228+
[ "$(PODMAN)" -eq 0 ] && docker pull docker.io/docker/dockerfile:1.1-experimental
222229
docker pull docker.io/library/golang:$(GOLANG_VERSION)
223230
docker pull gcr.io/distroless/static:latest
224231

0 commit comments

Comments
 (0)