Skip to content

Commit b2b1126

Browse files
authored
Make image multi-arch ready (#19)
Signed-off-by: Tamal Saha <[email protected]>
1 parent 6fbb956 commit b2b1126

File tree

3 files changed

+70
-24
lines changed

3 files changed

+70
-24
lines changed

.github/workflows/release.yml

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ on:
55
tags:
66
- "*.*"
77
- "*.*.*"
8-
8+
# Allows you to run this workflow manually from the Actions tab
99
workflow_dispatch:
10+
1011
concurrency:
1112
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
1213
cancel-in-progress: true
14+
1315
jobs:
1416
build:
1517
name: Build
@@ -29,14 +31,16 @@ jobs:
2931
- name: Set up Docker Buildx
3032
uses: docker/setup-buildx-action@v1
3133

34+
- name: Login to DockerHub
35+
uses: docker/login-action@v1
36+
with:
37+
username: 1gtm
38+
password: ${{ secrets.DOCKERHUB_TOKEN }}
39+
3240
- name: Run checks
3341
run: |
3442
make ci
3543
3644
- name: Build
37-
env:
38-
DOCKER_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
39-
USERNAME: 1gtm
4045
run: |
41-
docker login --username ${USERNAME} --password ${DOCKER_TOKEN}
42-
make push
46+
make release

Dockerfile

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1-
FROM tianon/toybox:0.8.4
1+
FROM alpine
2+
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
6+
RUN set -x \
7+
&& apk add --update ca-certificates curl
8+
9+
RUN curl -fsSL -o tini https://github.com/kubedb/tini/releases/download/v0.20.0/tini-static-${TARGETARCH} \
10+
&& chmod +x tini
11+
12+
13+
14+
FROM alpine
15+
16+
LABEL org.opencontainers.image.source https://github.com/kubedb/mysql-init-docker
17+
18+
RUN apk add --no-cache bash
219

320
COPY scripts /tmp/scripts
421
COPY init-script /init-script
5-
COPY tini /tmp/scripts/tini
22+
COPY --from=0 /tini /tmp/scripts/tini
623

724
ENTRYPOINT ["/init-script/run.sh"]

Makefile

+41-16
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,51 @@
11
SHELL=/bin/bash -o pipefail
22

3-
REGISTRY ?= kubedb
4-
BIN := mysql-init
5-
IMAGE := $(REGISTRY)/$(BIN)
6-
TAG := $(shell git describe --exact-match --abbrev=0 2>/dev/null || echo "")
3+
REGISTRY ?= kubedb
4+
BIN ?= mysql-init
5+
IMAGE := $(REGISTRY)/$(BIN)
6+
TAG ?= $(shell git describe --exact-match --abbrev=0 2>/dev/null || echo "")
77

8-
.PHONY: push
9-
push: container
10-
docker push $(IMAGE):$(TAG)
8+
DOCKER_PLATFORMS := linux/amd64 linux/arm64
9+
PLATFORM ?= linux/$(subst x86_64,amd64,$(subst aarch64,arm64,$(shell uname -m)))
10+
VERSION = $(TAG)_$(subst /,_,$(PLATFORM))
11+
12+
container-%:
13+
@$(MAKE) container \
14+
--no-print-directory \
15+
PLATFORM=$(subst _,/,$*)
16+
17+
push-%:
18+
@$(MAKE) push \
19+
--no-print-directory \
20+
PLATFORM=$(subst _,/,$*)
21+
22+
all-container: $(addprefix container-, $(subst /,_,$(DOCKER_PLATFORMS)))
23+
24+
all-push: $(addprefix push-, $(subst /,_,$(DOCKER_PLATFORMS)))
1125

1226
.PHONY: container
1327
container:
14-
wget -qO tini https://github.com/kubedb/tini/releases/download/v0.20.0/tini-static
15-
chmod +x tini
16-
chmod +x init-script/run.sh
17-
find $$(pwd)/scripts -type f -exec chmod +x {} \;
18-
docker build --pull -t $(IMAGE):$(TAG) .
19-
rm tini
28+
@echo "container: $(IMAGE):$(VERSION)"
29+
@docker buildx build --platform $(PLATFORM) --load --pull -t $(IMAGE):$(VERSION) -f Dockerfile .
30+
@echo
31+
32+
push: container
33+
@docker push $(IMAGE):$(VERSION)
34+
@echo "pushed: $(IMAGE):$(VERSION)"
35+
@echo
36+
37+
.PHONY: docker-manifest
38+
docker-manifest:
39+
docker manifest create -a $(IMAGE):$(TAG) $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(TAG)_$(subst /,_,$(PLATFORM)))
40+
docker manifest push $(IMAGE):$(TAG)
41+
42+
.PHONY: release
43+
release:
44+
@$(MAKE) all-push docker-manifest --no-print-directory
2045

2146
.PHONY: version
2247
version:
23-
@echo ::set-output name=version::$(TAG)
48+
@echo ::set-output name=version::$(VERSION)
2449

2550
.PHONY: fmt
2651
fmt:
@@ -39,5 +64,5 @@ ci: verify
3964
.PHONY: push-to-kind
4065
push-to-kind: container
4166
@echo "Loading docker image into kind cluster...."
42-
@kind load docker-image $(IMAGE):$(TAG)
43-
@echo "Image has been pushed successfully into kind cluster."
67+
@kind load docker-image $(IMAGE):$(VERSION)
68+
@echo "Image has been pushed successfully into kind cluster."

0 commit comments

Comments
 (0)