Skip to content

Commit 17bc65a

Browse files
authored
Build ubi image (#6)
Signed-off-by: Tamal Saha <[email protected]>
1 parent 9d1c478 commit 17bc65a

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ jobs:
7070
make release RELEASE=${{ matrix.k8s }}
7171
cd ../nonroot
7272
make release RELEASE=${{ matrix.k8s }}
73+
cd ../ubi
74+
make release RELEASE=${{ matrix.k8s }}

ubi/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM alpine
2+
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
ARG VERSION
6+
7+
RUN set -x \
8+
&& apk add --update ca-certificates curl zip bzip2
9+
10+
RUN set -x \
11+
&& curl -LO https://github.com/moparisthebest/static-curl/archive/refs/heads/master.zip \
12+
&& unzip master.zip \
13+
&& cd static-curl-master \
14+
&& ARCH=${TARGETARCH} ./build.sh
15+
16+
RUN set -x \
17+
&& curl -LO "https://dl.k8s.io/release/$VERSION/bin/${TARGETOS}/${TARGETARCH}/kubectl" \
18+
&& chmod +x kubectl
19+
20+
21+
22+
FROM registry.access.redhat.com/ubi10/ubi-minimal
23+
24+
LABEL org.opencontainers.image.source https://github.com/appscodelabs/kubectl-docker
25+
26+
ARG TARGETARCH
27+
28+
COPY --from=0 /tmp/release/curl-$TARGETARCH /usr/bin/curl
29+
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
30+
COPY --from=0 /kubectl /usr/bin/kubectl
31+
32+
USER 65534

ubi/Makefile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
SHELL=/bin/bash -o pipefail
2+
3+
REGISTRY ?= appscode
4+
BIN := kubectl-nonroot
5+
IMAGE := $(REGISTRY)/$(BIN)
6+
RELEASE ?= 1.20
7+
VERSION ?= $(shell curl -fsSL https://dl.k8s.io/release/stable-$(RELEASE).txt)-ubi
8+
SRC_REG ?=
9+
10+
DOCKER_PLATFORMS := linux/amd64 linux/arm64
11+
PLATFORM ?= $(firstword $(DOCKER_PLATFORMS))
12+
TAG = $(VERSION)_$(subst /,_,$(PLATFORM))
13+
14+
container-%:
15+
@$(MAKE) container \
16+
--no-print-directory \
17+
PLATFORM=$(subst _,/,$*)
18+
19+
push-%:
20+
@$(MAKE) push \
21+
--no-print-directory \
22+
PLATFORM=$(subst _,/,$*)
23+
24+
all-container: $(addprefix container-, $(subst /,_,$(DOCKER_PLATFORMS)))
25+
26+
all-push: $(addprefix push-, $(subst /,_,$(DOCKER_PLATFORMS)))
27+
28+
ifeq (,$(SRC_REG))
29+
container:
30+
@echo "container: $(IMAGE):$(TAG)"
31+
@docker buildx build --platform $(PLATFORM) --build-arg VERSION=$(VERSION) --load --pull -t $(IMAGE):$(TAG) -f Dockerfile .
32+
@echo
33+
else
34+
container:
35+
@echo "container: $(IMAGE):$(TAG)"
36+
@docker tag $(SRC_REG)/$(BIN):$(TAG) $(IMAGE):$(TAG)
37+
@echo
38+
endif
39+
40+
push: container
41+
@docker push $(IMAGE):$(TAG)
42+
@echo "pushed: $(IMAGE):$(TAG)"
43+
@echo
44+
45+
.PHONY: manifest-version
46+
manifest-version:
47+
docker manifest create -a $(IMAGE):$(VERSION) $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(VERSION)_$(subst /,_,$(PLATFORM)))
48+
docker manifest push $(IMAGE):$(VERSION)
49+
50+
.PHONY: manifest-release
51+
manifest-release:
52+
docker manifest create -a $(IMAGE):v$(RELEASE)-ubi $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(VERSION)_$(subst /,_,$(PLATFORM)))
53+
docker manifest push $(IMAGE):v$(RELEASE)-ubi
54+
docker manifest create -a $(IMAGE):$(RELEASE)-ubi $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(VERSION)_$(subst /,_,$(PLATFORM)))
55+
docker manifest push $(IMAGE):$(RELEASE)-ubi
56+
57+
.PHONY: docker-manifest
58+
docker-manifest: manifest-version manifest-release
59+
60+
.PHONY: release
61+
release:
62+
@$(MAKE) all-push docker-manifest --no-print-directory

0 commit comments

Comments
 (0)