Skip to content

Commit 2d92be1

Browse files
committed
feat: use github action to build multiarch tapp images
1 parent 06c840f commit 2d92be1

File tree

7 files changed

+354
-0
lines changed

7 files changed

+354
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: release-multiarch
2+
3+
on:
4+
create:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
release-multiarch:
10+
11+
runs-on: ubuntu-18.04
12+
13+
steps:
14+
- uses: actions/checkout@v1
15+
16+
- uses: actions/cache@v1
17+
with:
18+
path: ~/go/pkg/mod
19+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
20+
restore-keys: |
21+
${{ runner.os }}-go-
22+
23+
- uses: azure/docker-login@v1
24+
with:
25+
username: ${{ secrets.REGISTRY_USERNAME }}
26+
password: ${{ secrets.REGISTRY_PASSWORD }}
27+
28+
- name: Set up Docker Buildx
29+
id: buildx
30+
uses: crazy-max/ghaction-docker-buildx@v1
31+
with:
32+
buildx-version: latest
33+
qemu-version: latest
34+
35+
- run: |
36+
make release.multiarch

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ clean:
99
build:
1010
hack/build.sh
1111

12+
# ==============================================================================
13+
# Includes
14+
15+
include build/lib/common.mk
16+
include build/lib/image.mk
17+
1218
# Run test
1319
#
1420
# Args:
@@ -38,4 +44,9 @@ push-image:
3844

3945
release: build-image push-image
4046

47+
## release.multiarch: Build docker images for multiple platforms and push manifest lists to registry.
48+
.PHONY: release.multiarch
49+
release.multiarch:
50+
@$(MAKE) image.manifest.push.multiarch BINS="tapp-controller"
51+
4152
# vim: set ts=2 sw=2 tw=0 noet :

build/docker/Dockerfile_arch

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Tencent is pleased to support the open source community by making TKEStack
2+
# available.
3+
#
4+
# Copyright (C) 2012-2019 Tencent. All Rights Reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use
7+
# this file except in compliance with the License. You may obtain a copy of the
8+
# License at
9+
#
10+
# https://opensource.org/licenses/Apache-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
# WARRANTIES OF ANY KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations under the License.
16+
17+
FROM golang:1.14.4 AS builder
18+
ARG TARGETPLATFORM
19+
RUN echo "building for ${TARGETPLATFORM}"
20+
ARG WORKDIR="/go/src/tkestack.io/tapp/"
21+
RUN mkdir -p ${WORKDIR}
22+
WORKDIR ${WORKDIR}
23+
## cache dependancies if we won't change mod/sum
24+
COPY go.mod go.sum ${WORKDIR}
25+
RUN go mod download
26+
27+
COPY . ${WORKDIR}
28+
RUN make build
29+
30+
31+
FROM alpine:3.9
32+
33+
RUN mkdir /etc/certs
34+
ADD build/docker/ca.crt /etc/certs
35+
ADD build/docker/tls.crt /etc/certs
36+
ADD build/docker/tls.key /etc/certs
37+
COPY --from=builder /go/src/tkestack.io/tapp/bin/tapp-controller /usr/local/bin
38+
39+
ENTRYPOINT ["/usr/local/bin/tapp-controller"]

build/lib/common.mk

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Tencent is pleased to support the open source community by making TKEStack
2+
# available.
3+
#
4+
# Copyright (C) 2012-2019 Tencent. All Rights Reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use
7+
# this file except in compliance with the License. You may obtain a copy of the
8+
# License at
9+
#
10+
# https://opensource.org/licenses/Apache-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
# WARRANTIES OF ANY KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations under the License.
16+
17+
SHELL := /bin/bash
18+
19+
# include the common make file
20+
COMMON_SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
21+
22+
ifeq ($(origin ROOT_DIR),undefined)
23+
ROOT_DIR := $(abspath $(shell cd $(COMMON_SELF_DIR)/../.. && pwd -P))
24+
endif
25+
ifeq ($(origin OUTPUT_DIR),undefined)
26+
OUTPUT_DIR := $(ROOT_DIR)/_output
27+
$(shell mkdir -p $(OUTPUT_DIR))
28+
endif
29+
ifeq ($(origin TOOLS_DIR),undefined)
30+
TOOLS_DIR := $(OUTPUT_DIR)/tools
31+
$(shell mkdir -p $(TOOLS_DIR))
32+
endif
33+
ifeq ($(origin TMP_DIR),undefined)
34+
TMP_DIR := $(OUTPUT_DIR)/tmp
35+
$(shell mkdir -p $(TMP_DIR))
36+
endif
37+
38+
# set the version number. you should not need to do this
39+
# for the majority of scenarios.
40+
ifeq ($(origin VERSION), undefined)
41+
VERSION := $(shell git describe --dirty --always --tags | sed 's/-/./g')
42+
endif
43+
GIT_COMMIT:=$(shell git log --first-parent -1 --oneline | awk '{print $$1}')
44+
45+
PLATFORMS ?= linux_amd64 linux_arm64
46+
47+
# Set a specific PLATFORM
48+
# Target OS must be linux
49+
ifeq ($(origin PLATFORM), undefined)
50+
ifeq ($(origin GOOS), undefined)
51+
GOOS := linux
52+
endif
53+
ifeq ($(origin GOARCH), undefined)
54+
GOARCH := $(shell go env GOARCH)
55+
endif
56+
PLATFORM := $(GOOS)_$(GOARCH)
57+
else
58+
GOOS := $(word 1, $(subst _, ,$(PLATFORM)))
59+
GOARCH := $(word 2, $(subst _, ,$(PLATFORM)))
60+
endif
61+
62+
COMMA := ,
63+
SPACE :=
64+
SPACE +=

build/lib/create-manifest.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
3+
# Tencent is pleased to support the open source community by making TKEStack
4+
# available.
5+
#
6+
# Copyright (C) 2012-2019 Tencent. All Rights Reserved.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use
9+
# this file except in compliance with the License. You may obtain a copy of the
10+
# License at
11+
#
12+
# https://opensource.org/licenses/Apache-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16+
# WARRANTIES OF ANY KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations under the License.
18+
19+
set -o errexit
20+
set -o nounset
21+
set -o pipefail
22+
23+
REGISTRY_PREFIX=${REGISTRY_PREFIX:-"tkestack"}
24+
PLATFORMS=${PLATFORMS:-"linux_amd64 linux_arm64"}
25+
26+
if [ -z ${IMAGE} ]; then
27+
echo "Please provide IMAGE."
28+
exit 1
29+
fi
30+
31+
if [ -z ${VERSION} ]; then
32+
echo "Please provide VERSION."
33+
exit 1
34+
fi
35+
36+
rm -rf ${HOME}/.docker/manifests/docker.io_${REGISTRY_PREFIX}_${IMAGE}-${VERSION}
37+
DES_REGISTRY=${REGISTRY_PREFIX}/${IMAGE}
38+
for platform in ${PLATFORMS}; do
39+
os=${platform%_*}
40+
arch=${platform#*_}
41+
variant=""
42+
if [ ${arch} == "arm64" ]; then
43+
variant="--variant unknown"
44+
fi
45+
46+
docker manifest create --amend ${DES_REGISTRY}:${VERSION} \
47+
${DES_REGISTRY}-${arch}:${VERSION}
48+
49+
docker manifest annotate ${DES_REGISTRY}:${VERSION} \
50+
${DES_REGISTRY}-${arch}:${VERSION} \
51+
--os ${os} --arch ${arch} ${variant}
52+
done
53+
docker manifest push --purge ${DES_REGISTRY}:${VERSION}

build/lib/image.mk

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Tencent is pleased to support the open source community by making TKEStack
2+
# available.
3+
#
4+
# Copyright (C) 2012-2019 Tencent. All Rights Reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use
7+
# this file except in compliance with the License. You may obtain a copy of the
8+
# License at
9+
#
10+
# https://opensource.org/licenses/Apache-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
# WARRANTIES OF ANY KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations under the License.
16+
17+
# ==============================================================================
18+
# Makefile helper functions for docker image
19+
20+
DOCKER := DOCKER_CLI_EXPERIMENTAL=enabled docker
21+
DOCKER_SUPPORTED_API_VERSION ?= 1.40
22+
DOCKER_VERSION ?= 19.03
23+
24+
REGISTRY_PREFIX ?= tkestack
25+
26+
EXTRA_ARGS ?=
27+
_DOCKER_BUILD_EXTRA_ARGS :=
28+
29+
ifdef HTTP_PROXY
30+
_DOCKER_BUILD_EXTRA_ARGS += --build-arg http_proxy=${HTTP_PROXY}
31+
endif
32+
ifdef HTTPS_PROXY
33+
_DOCKER_BUILD_EXTRA_ARGS += --build-arg https_proxy=${HTTPS_PROXY}
34+
endif
35+
36+
ifneq ($(EXTRA_ARGS), )
37+
_DOCKER_BUILD_EXTRA_ARGS += $(EXTRA_ARGS)
38+
endif
39+
40+
.PHONY: image.verify
41+
image.verify:
42+
$(eval API_VERSION := $(shell $(DOCKER) version | grep -E 'API version: {1,6}[0-9]' | head -n1 | awk '{print $$3} END { if (NR==0) print 0}' ))
43+
$(eval PASS := $(shell echo "$(API_VERSION) >= $(DOCKER_SUPPORTED_API_VERSION)" | bc))
44+
@if [ $(PASS) -ne 1 ]; then \
45+
$(DOCKER) -v ;\
46+
echo "Unsupported docker version. Docker API version should be greater than $(DOCKER_SUPPORTED_API_VERSION) (Or docker version: $(DOCKER_VERSION))"; \
47+
exit 1; \
48+
fi
49+
50+
.PHONY: image.buildx.verify
51+
image.buildx.verify: image.verify
52+
$(eval PASS := $(shell $(DOCKER) buildx version > /dev/null && echo 1 || echo 0))
53+
@if [ $(PASS) -ne 1 ]; then \
54+
$(MAKE) image.buildx.install; \
55+
fi
56+
57+
.PHONY: image.buildx.install
58+
image.buildx.install:
59+
@$(ROOT_DIR)/build/lib/install-buildx.sh
60+
61+
.PHONY: image.build
62+
image.build: image.buildx.verify $(addprefix image.build., $(addprefix $(PLATFORM)., $(BINS)))
63+
64+
.PHONY: image.build.multiarch
65+
image.build.multiarch: image.buildx.verify $(foreach p,$(PLATFORMS),$(addprefix image.build., $(addprefix $(p)., $(BINS))))
66+
67+
.PHONY: image.build.%
68+
image.build.%:
69+
$(eval PLATFORM := $(word 1,$(subst ., ,$*)))
70+
$(eval IMAGE := $(word 2,$(subst ., ,$*)))
71+
$(eval OS := $(word 1,$(subst _, ,$(PLATFORM))))
72+
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
73+
$(eval IMAGE_PLAT := $(subst _,/,$(PLATFORM)))
74+
$(eval IMAGE_NAME := $(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION))
75+
@echo "===========> Building docker image $(IMAGE) $(VERSION) for $(IMAGE_PLAT)"
76+
$(DOCKER) buildx build --platform $(IMAGE_PLAT) --load -t $(IMAGE_NAME) $(_DOCKER_BUILD_EXTRA_ARGS) \
77+
-f $(ROOT_DIR)/build/docker/Dockerfile_arch $(ROOT_DIR)
78+
79+
.PHONY: image.push
80+
image.push: image.buildx.verify $(addprefix image.push., $(addprefix $(PLATFORM)., $(BINS)))
81+
82+
.PHONY: image.push.multiarch
83+
image.push.multiarch: image.buildx.verify $(foreach p,$(PLATFORMS),$(addprefix image.push., $(addprefix $(p)., $(BINS))))
84+
85+
.PHONY: image.push.%
86+
image.push.%: image.build.%
87+
@echo "===========> Pushing image $(IMAGE) $(VERSION) to $(REGISTRY_PREFIX)"
88+
$(DOCKER) push $(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION)
89+
90+
.PHONY: image.manifest.push
91+
image.manifest.push: export DOCKER_CLI_EXPERIMENTAL := enabled
92+
image.manifest.push: image.buildx.verify $(addprefix image.manifest.push., $(addprefix $(PLATFORM)., $(BINS)))
93+
94+
.PHONY: image.manifest.push.%
95+
image.manifest.push.%: image.push.% image.manifest.remove.%
96+
@echo "===========> Pushing manifest $(IMAGE) $(VERSION) to $(REGISTRY_PREFIX) and then remove the local manifest list"
97+
@$(DOCKER) manifest create $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION) \
98+
$(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION)
99+
@$(DOCKER) manifest annotate $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION) \
100+
$(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION) \
101+
--os $(OS) --arch ${ARCH}
102+
@$(DOCKER) manifest push --purge $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION)
103+
104+
# Docker cli has a bug: https://github.com/docker/cli/issues/954
105+
# If you find your manifests were not updated,
106+
# Please manually delete them in $HOME/.docker/manifests/
107+
# and re-run.
108+
.PHONY: image.manifest.remove.%
109+
image.manifest.remove.%:
110+
@rm -rf ${HOME}/.docker/manifests/docker.io_$(REGISTRY_PREFIX)_$(IMAGE)-$(VERSION)
111+
112+
.PHONY: image.manifest.push.multiarch
113+
image.manifest.push.multiarch: image.push.multiarch $(addprefix image.manifest.push.multiarch., $(BINS))
114+
115+
.PHONY: image.manifest.push.multiarch.%
116+
image.manifest.push.multiarch.%:
117+
@echo "===========> Pushing manifest $* $(VERSION) to $(REGISTRY_PREFIX) and then remove the local manifest list"
118+
REGISTRY_PREFIX=$(REGISTRY_PREFIX) PLATFROMS="$(PLATFORMS)" IMAGE=$* VERSION=$(VERSION) DOCKER_CLI_EXPERIMENTAL=enabled \
119+
$(ROOT_DIR)/build/lib/create-manifest.sh

build/lib/install-buildx.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
# Tencent is pleased to support the open source community by making TKEStack
4+
# available.
5+
#
6+
# Copyright (C) 2012-2019 Tencent. All Rights Reserved.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use
9+
# this file except in compliance with the License. You may obtain a copy of the
10+
# License at
11+
#
12+
# https://opensource.org/licenses/Apache-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16+
# WARRANTIES OF ANY KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations under the License.
18+
19+
set -o errexit
20+
set -o nounset
21+
set -o pipefail
22+
23+
BUILDX_VERSION=${BUILDX_VERSION:-"v0.4.1"}
24+
ARCH=${ARCH:-"amd64"}
25+
BUILDX_BIN="https://github.com/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.linux-${ARCH}"
26+
27+
echo "Downloading docker-buildx"
28+
wget -c ${BUILDX_BIN} -O ./docker-buildx
29+
mkdir -p ~/.docker/cli-plugins/
30+
mv ./docker-buildx ~/.docker/cli-plugins/
31+
chmod a+x ~/.docker/cli-plugins/docker-buildx
32+
docker buildx version

0 commit comments

Comments
 (0)