Skip to content

Commit 27d7c50

Browse files
committed
Add arm64 to releases
This moves all the release builds into a Dockerfile which is a bit cleaner for setting up our build environment. Non-linux/amd64 builds are cross-compiled. Currently onlinux linux/amd64, linux/arm64, and windows/amd64 are supported, but is easy to add more, provided their is a cross-compile toolchain available for it. Signed-off-by: Brian Goff <[email protected]>
1 parent 7ad5709 commit 27d7c50

7 files changed

Lines changed: 180 additions & 160 deletions

File tree

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.github/
2+
.dockerignore
3+
releases/
4+
bin/

.github/workflows/release.yml

Lines changed: 33 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -53,33 +53,27 @@ jobs:
5353
runs-on: ${{ matrix.os }}
5454
needs: [check]
5555
timeout-minutes: 10
56-
5756
strategy:
5857
matrix:
59-
os: [ubuntu-18.04, windows-2019]
60-
58+
os: [ubuntu-18.04]
59+
platform:
60+
- linux/amd64
61+
- linux/arm64
62+
- windows/amd64
6163
steps:
6264
- name: Install Go
6365
uses: actions/setup-go@v2
6466
with:
6567
go-version: '1.17.3'
66-
6768
- name: Set env
6869
shell: bash
6970
env:
7071
MOS: ${{ matrix.os }}
7172
run: |
7273
releasever=${{ github.ref }}
7374
releasever="${releasever#refs/tags/}"
74-
os=linux
75-
[[ "${MOS}" =~ "windows" ]] && {
76-
os=windows
77-
}
7875
echo "RELEASE_VER=${releasever}" >> $GITHUB_ENV
7976
echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
80-
echo "OS=${os}" >> $GITHUB_ENV
81-
echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
82-
8377
- name: Checkout containerd
8478
uses: actions/checkout@v2
8579
with:
@@ -90,169 +84,54 @@ jobs:
9084
ref: ${{ github.ref }}
9185
path: src/github.com/containerd/containerd
9286

93-
- name: HCS Shim commit
94-
id: hcsshim_commit
95-
if: startsWith(matrix.os, 'windows')
96-
shell: bash
97-
run: echo "::set-output name=sha::$(grep 'Microsoft/hcsshim ' go.mod | awk '{print $2}')"
98-
working-directory: src/github.com/containerd/containerd
99-
100-
- name: Checkout hcsshim source
101-
if: startsWith(matrix.os, 'windows')
102-
uses: actions/checkout@v2
87+
- name: Setup buildx instance
88+
uses: docker/setup-buildx-action@v1
10389
with:
104-
repository: Microsoft/hcsshim
105-
ref: ${{ steps.hcsshim_commit.outputs.sha }}
106-
path: src/github.com/Microsoft/hcsshim
107-
90+
use: true
91+
- uses: crazy-max/ghaction-github-runtime@v1 # sets up needed vars for caching to github
10892
- name: Make
10993
shell: bash
11094
run: |
111-
make build
112-
make binaries
113-
rm bin/containerd-stress*
114-
[[ "${OS}" == "windows" ]] && {
115-
(
116-
bindir="$(pwd)/bin"
117-
cd ../../Microsoft/hcsshim
118-
GO111MODULE=on go build -mod=vendor -o "${bindir}/containerd-shim-runhcs-v1.exe" ./cmd/containerd-shim-runhcs-v1
119-
)
120-
}
121-
TARFILE="containerd-${RELEASE_VER#v}-${OS}-amd64.tar.gz"
122-
tar czf ${TARFILE} bin/
123-
sha256sum ${TARFILE} >${TARFILE}.sha256sum
124-
working-directory: src/github.com/containerd/containerd
125-
126-
- name: Save build binaries
127-
uses: actions/upload-artifact@v2
128-
with:
129-
name: containerd-binaries-${{ matrix.os }}
130-
path: src/github.com/containerd/containerd/*.tar.gz*
131-
132-
- name: Make cri-containerd tar
133-
shell: bash
134-
env:
135-
RUNC_FLAVOR: runc
136-
run: |
137-
if [[ "${OS}" == "linux" ]]; then
138-
sudo apt-get update
139-
sudo apt-get install -y gperf
140-
sudo -E PATH=$PATH script/setup/install-seccomp
95+
cache="--cache-from=type=gha,scope=containerd-release --cache-to=type=gha,scope=containerd-release"
96+
if [[ "${PLATFORM}" =~ "windows" ]]; then
97+
# For Windows the cni build script generates a config but shells out to powershell (and also assume it is running on windows) to get a gateway and subnet.
98+
# The values provided here are taken from packages that we previously generated.
99+
export GATEWAY=172.21.16.1
100+
export PREFIX_LEN=12
101+
BUILD_ARGS="--build-arg GATEWAY --build-arg PREFIX_LEN"
141102
fi
142-
make cri-release cri-cni-release
143-
working-directory: src/github.com/containerd/containerd
103+
docker buildx build ${cache} --build-arg RELEASE_VER --build-arg GO_VERSION ${BUILD_ARGS} -f .github/workflows/release/Dockerfile.${{matrix.os}} --platform=${PLATFORM} -o releases/ .
104+
echo PLATFORM_CLEAN=${PLATFORM/\//-} >> $GITHUB_ENV
144105
145-
- name: Save cri-containerd binaries
106+
# Remove symlinks since we don't want these in the release Artifacts
107+
find ./releases/ -maxdepth 1 -type l | xargs rm
108+
working-directory: src/github.com/containerd/containerd
109+
env:
110+
GO_VERSION: '1.17.2'
111+
PLATFORM: ${{ matrix.platform }}
112+
- name: Save Artifacts
146113
uses: actions/upload-artifact@v2
147114
with:
148-
name: cri-containerd-binaries-${{ matrix.os }}
149-
path: src/github.com/containerd/containerd/releases/cri-containerd-*.tar.gz*
115+
name: release-tars-${{env.PLATFORM_CLEAN}}
116+
path: src/github.com/containerd/containerd/releases/*.tar.gz*
150117

151118
release:
152119
name: Create containerd Release
153120
runs-on: ubuntu-18.04
154121
timeout-minutes: 10
155122
needs: [build, check]
156-
outputs:
157-
upload_url: ${{ steps.create_release.outputs.upload_url }}
158-
159123
steps:
160124
- name: Download builds and release notes
161125
uses: actions/download-artifact@v2
162126
with:
163127
path: builds
164128
- name: Create Release
165-
id: create_release
166-
uses: actions/[email protected]
167-
env:
168-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129+
uses: softprops/action-gh-release@v1
169130
with:
170-
tag_name: ${{ github.ref }}
171-
release_name: containerd ${{ needs.check.outputs.stringver }}
172-
body_path: ./builds/containerd-release-notes/release-notes.md
131+
token: ${{ secrets.GITHUB_TOKEN }}
132+
fail_on_unmatched_files: true
173133
draft: false
174134
prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
175-
176-
release-upload:
177-
name: Upload containerd tarballs
178-
runs-on: ubuntu-18.04
179-
timeout-minutes: 10
180-
needs: [release]
181-
182-
strategy:
183-
matrix:
184-
os: [ubuntu-18.04, windows-2019]
185-
186-
steps:
187-
- name: Download builds and release notes
188-
uses: actions/download-artifact@v2
189-
with:
190-
path: builds
191-
- name: Catalog build assets for upload
192-
id: catalog
193-
env:
194-
OS: ${{ matrix.os }}
195-
run: |
196-
_filenum=1
197-
for f in `ls "builds/containerd-binaries-${OS}"`; do
198-
echo "::set-output name=file${_filenum}::${f}"
199-
let "_filenum+=1"
200-
done
201-
for f in `ls builds/cri-containerd-binaries-${OS}`; do
202-
echo "::set-output name=file${_filenum}::${f}"
203-
let "_filenum+=1"
204-
done
205-
- name: Upload containerd tarball
206-
uses: actions/upload-release-asset@v1
207-
env:
208-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
209-
with:
210-
upload_url: ${{ needs.release.outputs.upload_url }}
211-
asset_path: ./builds/containerd-binaries-${{ matrix.os }}/${{ steps.catalog.outputs.file1 }}
212-
asset_name: ${{ steps.catalog.outputs.file1 }}
213-
asset_content_type: application/gzip
214-
- name: Upload sha256 sum
215-
uses: actions/upload-release-asset@v1
216-
env:
217-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
218-
with:
219-
upload_url: ${{ needs.release.outputs.upload_url }}
220-
asset_path: ./builds/containerd-binaries-${{ matrix.os }}/${{ steps.catalog.outputs.file2 }}
221-
asset_name: ${{ steps.catalog.outputs.file2 }}
222-
asset_content_type: text/plain
223-
- name: Upload cri containerd tarball
224-
uses: actions/upload-release-asset@v1
225-
env:
226-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
227-
with:
228-
upload_url: ${{ needs.release.outputs.upload_url }}
229-
asset_path: ./builds/cri-containerd-binaries-${{ matrix.os }}/${{ steps.catalog.outputs.file3 }}
230-
asset_name: ${{ steps.catalog.outputs.file3 }}
231-
asset_content_type: application/gzip
232-
- name: Upload cri sha256 sum
233-
uses: actions/upload-release-asset@v1
234-
env:
235-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
236-
with:
237-
upload_url: ${{ needs.release.outputs.upload_url }}
238-
asset_path: ./builds/cri-containerd-binaries-${{ matrix.os }}/${{ steps.catalog.outputs.file4 }}
239-
asset_name: ${{ steps.catalog.outputs.file4 }}
240-
asset_content_type: text/plain
241-
- name: Upload cri/cni containerd tarball
242-
uses: actions/upload-release-asset@v1
243-
env:
244-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
245-
with:
246-
upload_url: ${{ needs.release.outputs.upload_url }}
247-
asset_path: ./builds/cri-containerd-binaries-${{ matrix.os }}/${{ steps.catalog.outputs.file5 }}
248-
asset_name: ${{ steps.catalog.outputs.file5 }}
249-
asset_content_type: application/gzip
250-
- name: Upload cri/cni sha256 sum
251-
uses: actions/upload-release-asset@v1
252-
env:
253-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
254-
with:
255-
upload_url: ${{ needs.release.outputs.upload_url }}
256-
asset_path: ./builds/cri-containerd-binaries-${{ matrix.os }}/${{ steps.catalog.outputs.file6 }}
257-
asset_name: ${{ steps.catalog.outputs.file6 }}
258-
asset_content_type: text/plain
135+
body_path: ./builds/containerd-release-notes/release-notes.md
136+
files: |
137+
builds/release-tars-**/*
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Copyright The containerd 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+
ARG GO_VERSION
16+
ARG GO_IMAGE=golang:${GO_VERSION}
17+
FROM --platform=$BUILDPLATFORM $GO_IMAGE AS go
18+
19+
FROM --platform=$BUILDPLATFORM ubuntu:18.04 AS base
20+
SHELL ["/bin/bash", "-xec"]
21+
# Ubuntu has entirely separate repos for non-amd64 architectures
22+
# Because of this we can't just add new arches, we need to update the repo list first
23+
RUN \
24+
echo deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic main multiverse restricted universe > /etc/apt/sources.list; \
25+
echo deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic-updates main multiverse restricted universe >> /etc/apt/sources.list; \
26+
echo deb [arch=amd64] http://security.ubuntu.com/ubuntu/ bionic-security main multiverse restricted universe >> /etc/apt/sources.lis; \
27+
echo deb [arch=arm64,armhf] http://ports.ubuntu.com/ubuntu-ports/ bionic main multiverse restricted universe >> /etc/apt/sources.list; \
28+
echo deb [arch=arm64,armhf] http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main multiverse restricted universe >> /etc/apt/sources.list
29+
RUN dpkg --add-architecture arm64
30+
RUN apt-get update && apt-get install -y \
31+
binutils-mingw-w64 \
32+
crossbuild-essential-arm64 \
33+
g++-mingw-w64-x86-64 \
34+
git \
35+
libseccomp-dev:amd64 \
36+
libseccomp-dev:arm64 \
37+
pkg-config
38+
ARG TARGETARCH
39+
ARG TARGETVARIANT
40+
ARG TARGETOS
41+
# btrfs-progs cannot have multiple arch versions installed at the same time
42+
# Unfortunately this is also means we can't share a build cache between arches beyond this point.
43+
#
44+
# Also note this won't work with 32bit arm versions, and likely some other things such as ppc.
45+
# For that we'd need to translate $TARGETARCH and $TARGETVARIANT into Ubuntu specific values.
46+
# Since we don't support these architectures right now this is good enough.
47+
RUN \
48+
if [ "$TARGETOS" = "linux" ]; then \
49+
apt-get update && \
50+
apt-get install -y btrfs-progs:${TARGETARCH}; \
51+
fi
52+
ENV PATH=/usr/local/go/bin:$PATH
53+
ENV GOPATH=/go
54+
ENV CGO_ENABLED=1
55+
56+
FROM base AS linux-arm64
57+
ENV CC=aarch64-linux-gnu-gcc
58+
RUN \
59+
PKG_CONFIG_PATH="$(pkg-config --variable pc_path pkg-config)"; \
60+
for i in $(find /usr/lib -name 'pkgconfig'); do \
61+
PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:$i"; \
62+
done; \
63+
echo export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}" > /tmp/pkgconfig
64+
65+
FROM base AS linux-amd64
66+
67+
FROM base AS windows-amd64
68+
ENV CC=x86_64-w64-mingw32-gcc
69+
# Set variables used by cni script which would otherwise shell out to powershell
70+
ARG GATEWAY
71+
ENV GATEWAY=$GATEWAY
72+
ARG PREFIX_LEN
73+
ENV PREFIX_LEN=$PREFIX_LEN
74+
75+
FROM ${TARGETOS}-${TARGETARCH}${TARGETVARIANT} AS target
76+
COPY . /go/src/github.com/containerd/containerd
77+
WORKDIR /go/src/github.com/containerd/containerd
78+
ARG TARGETARCH
79+
ARG TARGETOS
80+
ENV GOARCH=$TARGETARCH
81+
ENV GOOS=$TARGETOS
82+
ENV OS=$TARGETOS
83+
ARG RELEASE_VER
84+
ENV VERSION=$RELEASE_VER
85+
RUN \
86+
--mount=type=bind,from=go,source=/usr/local/go,target=/usr/local/go \
87+
--mount=type=cache,target=/root/.cache/go-build \
88+
[ -f /tmp/pkgconfig ] && . /tmp/pkgconfig; \
89+
make release cri-release cri-cni-release
90+
91+
FROM scratch AS release
92+
COPY --from=target /go/src/github.com/containerd/containerd/releases/ /

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ MANDIR ?= $(DATADIR)/man
3030
TEST_IMAGE_LIST ?=
3131

3232
# Used to populate variables in version package.
33-
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
33+
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
3434
REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
3535
PACKAGE=github.com/containerd/containerd
3636
SHIM_CGO_ENABLED ?= 0
@@ -271,6 +271,7 @@ install-man: man
271271
@echo "$(WHALE) $@"
272272
$(foreach manpage,$(addprefix man/,$(MANPAGES)), $(call installmanpage,$(manpage),$(subst .,,$(suffix $(manpage))),$(notdir $(manpage))))
273273

274+
274275
releases/$(RELEASE).tar.gz: $(BINARIES)
275276
@echo "$(WHALE) $@"
276277
@rm -rf releases/$(RELEASE) releases/$(RELEASE).tar.gz

Makefile.windows

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ ifeq ($(GOARCH),amd64)
2222
TESTFLAGS_RACE= -race
2323
endif
2424

25-
BINARIES:=$(addsuffix .exe,$(BINARIES))
25+
WINDOWS_SHIM=bin/containerd-shim-runhcs-v1.exe
26+
BINARIES := $(addsuffix .exe,$(BINARIES)) $(WINDOWS_SHIM)
27+
28+
$(WINDOWS_SHIM): script/setup/install-runhcs-shim go.mod
29+
DESTDIR=$(PWD)/bin $<
2630

2731
bin/%.exe: cmd/% FORCE
2832
$(BUILD_BINARY)

script/setup/install-cni-windows

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ calculate_subnet() {
6565

6666
# nat already exists on the Windows VM, the subnet and gateway
6767
# we specify should match that.
68-
gateway="$(powershell -c "(Get-NetIPAddress -InterfaceAlias 'vEthernet (nat)' -AddressFamily IPv4).IPAddress")"
69-
prefix_len="$(powershell -c "(Get-NetIPAddress -InterfaceAlias 'vEthernet (nat)' -AddressFamily IPv4).PrefixLength")"
68+
: ${GATEWAY:="$(powershell -c "(Get-NetIPAddress -InterfaceAlias 'vEthernet (nat)' -AddressFamily IPv4).IPAddress")"}
69+
: ${PREFIX_LEN:="$(powershell -c "(Get-NetIPAddress -InterfaceAlias 'vEthernet (nat)' -AddressFamily IPv4).PrefixLength")"}
7070

71-
subnet="$(calculate_subnet "$gateway" "$prefix_len")"
71+
subnet="$(calculate_subnet "$GATEWAY" "$PREFIX_LEN")"
7272

7373
# The "name" field in the config is used as the underlying
7474
# network type right now (see
@@ -85,7 +85,7 @@ bash -c 'cat >"'"${CNI_CONFIG_DIR}"'"/0-containerd-nat.conf <<EOF
8585
"subnet": "'$subnet'",
8686
"routes": [
8787
{
88-
"GW": "'$gateway'"
88+
"GW": "'$GATEWAY'"
8989
}
9090
]
9191
},

0 commit comments

Comments
 (0)