ci: build arm64 in aws self-hosted

This commit is contained in:
William Yang 2022-01-19 10:43:02 +01:00
parent 5e01961dba
commit 06cf419f02
1 changed files with 165 additions and 57 deletions

View File

@ -7,6 +7,9 @@ concurrency:
on: on:
schedule: schedule:
- cron: '0 */6 * * *' - cron: '0 */6 * * *'
push:
branch:
- 'ci/*'
release: release:
types: types:
- published - published
@ -24,6 +27,8 @@ jobs:
outputs: outputs:
ce_old_vsns: ${{ steps.find_old_versons.outputs.ce_old_vsns }} ce_old_vsns: ${{ steps.find_old_versons.outputs.ce_old_vsns }}
ee_old_vsns: ${{ steps.find_old_versons.outputs.ee_old_vsns }} ee_old_vsns: ${{ steps.find_old_versons.outputs.ee_old_vsns }}
DEP_ROCKSDB_REF: ${{ steps.deps-refs.outputs.DEP_ROCKSDB_REF }}
DEP_QUICER_REF: ${{ steps.deps-refs.outputs.DEP_QUICER_REF }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -31,6 +36,14 @@ jobs:
ref: ${{ github.event.inputs.which_branch }} ref: ${{ github.event.inputs.which_branch }}
path: source path: source
fetch-depth: 0 fetch-depth: 0
- name: Get deps git refs for cache
id: deps-refs
working-directory: source
run: |
bash -x scripts/get-dep-refs.sh
make clean-all
- name: find old versions - name: find old versions
id: find_old_versons id: find_old_versons
shell: bash shell: bash
@ -131,12 +144,12 @@ jobs:
- emqx-enterprise - emqx-enterprise
otp: otp:
- 24.1.5-4 - 24.1.5-4
macos: os:
- macos-11 - macos-11
- macos-10.15 - macos-10.15
exclude: exclude:
- profile: emqx-edge - profile: emqx-edge
runs-on: ${{ matrix.macos }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/download-artifact@v2 - uses: actions/download-artifact@v2
with: with:
@ -154,7 +167,7 @@ jobs:
id: cache id: cache
with: with:
path: ~/.kerl/${{ matrix.otp }} path: ~/.kerl/${{ matrix.otp }}
key: otp-install-${{ matrix.otp }}-${{ matrix.macos }} key: otp-install-${{ matrix.otp }}-${{ matrix.os }}
- name: build erlang - name: build erlang
if: steps.cache.outputs.cache-hit != 'true' if: steps.cache.outputs.cache-hit != 'true'
timeout-minutes: 60 timeout-minutes: 60
@ -166,24 +179,16 @@ jobs:
kerl build ${{ matrix.otp }} kerl build ${{ matrix.otp }}
kerl install ${{ matrix.otp }} $HOME/.kerl/${{ matrix.otp }} kerl install ${{ matrix.otp }} $HOME/.kerl/${{ matrix.otp }}
- name: Get deps git refs for cache
id: deps-refs
run: |
cd source
. $HOME/.kerl/${{ matrix.otp }}/activate
make ensure-rebar3
sudo cp rebar3 /usr/local/bin/rebar3
scripts/get-dep-refs.sh
- name: load rocksdb cache - name: load rocksdb cache
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: source/_build/default/lib/rocksdb/ path: source/_build/default/lib/rocksdb/
key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ steps.deps-refs.outputs.DEP_ROCKSDB_REF }} key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ needs.prepare.outputs.DEP_ROCKSDB_REF }}
- name: load quicer cache - name: load quicer cache
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: source/_build/default/lib/quicer/ path: source/_build/default/lib/quicer/
key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ steps.deps-refs.outputs.DEP_QUICER_REF }} key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ needs.prepare.outputs.DEP_QUICER_REF }}
- name: build - name: build
working-directory: source working-directory: source
@ -224,9 +229,10 @@ jobs:
path: source/_packages/${{ matrix.profile }}/. path: source/_packages/${{ matrix.profile }}/.
linux: linux:
runs-on: ubuntu-20.04
needs: prepare needs: prepare
runs-on: ${{ matrix.build_machine }}
container:
image: "ghcr.io/emqx/emqx-builder/5.0-5:${{ matrix.elixir }}-${{ matrix.otp }}-${{ matrix.os }}"
strategy: strategy:
fail-fast: false fail-fast: false
@ -262,11 +268,20 @@ jobs:
- centos7 - centos7
- raspbian10 - raspbian10
# - raspbian9 # - raspbian9
build_machine:
- aws-arm64
- ubuntu-20.04
exclude: exclude:
- arch: arm64
build_machine: ubuntu-20.04
- arch: amd64
build_machine: aws-arm64
- os: raspbian9 - os: raspbian9
arch: amd64 arch: amd64
- os: raspbian10 - os: raspbian10
arch: amd64 arch: amd64
- os: raspbian10 # we only have arm32 image
arch: arm64
- os: raspbian9 - os: raspbian9
profile: emqx profile: emqx
- os: raspbian10 - os: raspbian10
@ -294,36 +309,28 @@ jobs:
shell: bash shell: bash
steps: steps:
- uses: docker/setup-buildx-action@v1 - uses: AutoModality/action-clean@v1
- uses: docker/setup-qemu-action@v1 if: matrix.build_machine == 'aws-arm64'
with:
image: tonistiigi/binfmt:latest
platforms: all
- uses: actions/download-artifact@v2 - uses: actions/download-artifact@v2
with: with:
name: source name: source
path: . path: .
- name: unzip source code - name: unzip source code
run: unzip -q source.zip run: unzip -q source.zip
- name: Get deps git refs for cache
id: deps-refs
run: |
cd source
scripts/get-dep-refs.sh
- name: load rocksdb cache - name: load rocksdb cache
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: | path: |
source/_build/default/lib/rocksdb/ source/_build/default/lib/rocksdb/
source/deps/rocksdb/ source/deps/rocksdb/
key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ steps.deps-refs.outputs.DEP_ROCKSDB_REF }} key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ needs.prepare.outputs.DEP_ROCKSDB_REF }}
- name: load quicer cache - name: load quicer cache
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: | path: |
source/_build/default/lib/quicer/ source/_build/default/lib/quicer/
source/deps/quicer/ source/deps/quicer/
key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ steps.deps-refs.outputs.DEP_QUICER_REF }} key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ needs.prepare.outputs.DEP_QUICER_REF }}
- name: download old emqx tgz packages - name: download old emqx tgz packages
env: env:
OTP_VSN: ${{ matrix.otp }} OTP_VSN: ${{ matrix.otp }}
@ -350,7 +357,11 @@ jobs:
fi fi
mkdir -p _upgrade_base mkdir -p _upgrade_base
cd _upgrade_base cd _upgrade_base
old_vsns=($(echo $OLD_VSNS | tr ' ' ' ')) old_vsns=$(echo "$OLD_VSNS" | tr ' ' ' ')
# workaround for bash empty array expanding issue in different bash versions
if [ -n "$old_vsns" ]; then
old_vsns=($old_vsns)
for tag in ${old_vsns[@]}; do for tag in ${old_vsns[@]}; do
package_name="${PROFILE}-${tag#[e|v]}-otp${OTP_VSN}-${SYSTEM}-${ARCH}" package_name="${PROFILE}-${tag#[e|v]}-otp${OTP_VSN}-${SYSTEM}-${ARCH}"
if [ ! -z "$(echo $(curl -I -m 10 -o /dev/null -s -w %{http_code} https://s3-us-west-2.amazonaws.com/packages.emqx/$s3dir/$tag/$package_name.tar.gz) | grep -oE "^[23]+")" ]; then if [ ! -z "$(echo $(curl -I -m 10 -o /dev/null -s -w %{http_code} https://s3-us-west-2.amazonaws.com/packages.emqx/$s3dir/$tag/$package_name.tar.gz) | grep -oE "^[23]+")" ]; then
@ -359,7 +370,10 @@ jobs:
echo "$(cat $package_name.tar.gz.sha256) $package_name.tar.gz" | sha256sum -c || exit 1 echo "$(cat $package_name.tar.gz.sha256) $package_name.tar.gz" | sha256sum -c || exit 1
fi fi
done done
fi
- name: build emqx packages - name: build emqx packages
working-directory: source
env: env:
OTP: ${{ matrix.otp }} OTP: ${{ matrix.otp }}
ELIXIR: ${{ matrix.elixir }} ELIXIR: ${{ matrix.elixir }}
@ -367,26 +381,19 @@ jobs:
ARCH: ${{ matrix.arch }} ARCH: ${{ matrix.arch }}
SYSTEM: ${{ matrix.os }} SYSTEM: ${{ matrix.os }}
if: ${{ matrix.build_elixir == 'no_elixir' }} if: ${{ matrix.build_elixir == 'no_elixir' }}
working-directory: source
run: | run: |
set -eu
for PKGTYPE in tgz pkg;
do
./scripts/buildx.sh \ ./scripts/buildx.sh \
--profile "${PROFILE}" \ --profile "${PROFILE}" \
--pkgtype "tgz" \ --pkgtype "${PKGTYPE}" \
--arch "${ARCH}" \ --arch "${ARCH}" \
--otp "${OTP}" \ --otp "${OTP}" \
--elixir "${ELIXIR}" \ --elixir "${ELIXIR}" \
--system "${SYSTEM}" \ --system "${SYSTEM}" \
--builder "ghcr.io/emqx/emqx-builder/5.0-5:${ELIXIR}-${OTP}-${SYSTEM}" --builder "ghcr.io/emqx/emqx-builder/5.0-5:${ELIXIR}-${OTP}-${SYSTEM}"
## the pkg build is incremental on the tgz build done
./scripts/buildx.sh \
--profile "${PROFILE}" \
--pkgtype "pkg" \
--arch "${ARCH}" \
--otp "${OTP}" \
--elixir "${ELIXIR}" \
--system "${SYSTEM}" \
--builder "ghcr.io/emqx/emqx-builder/5.0-5:${ELIXIR}-${OTP}-${SYSTEM}"
- name: build emqx packages (Elixir) - name: build emqx packages (Elixir)
env: env:
OTP: ${{ matrix.otp }} OTP: ${{ matrix.otp }}
@ -416,7 +423,7 @@ jobs:
if [ -d _packages/$PROFILE ]; then if [ -d _packages/$PROFILE ]; then
cd _packages/$PROFILE cd _packages/$PROFILE
for var in $(ls emqx-* ); do for var in $(ls emqx-* ); do
sudo bash -c "echo $(sha256sum $var | awk '{print $1}') > $var.sha256" bash -c "echo $(sha256sum $var | awk '{print $1}') > $var.sha256"
done done
cd - cd -
fi fi
@ -427,12 +434,14 @@ jobs:
path: source/_packages/${{ matrix.profile }}/. path: source/_packages/${{ matrix.profile }}/.
docker: docker:
runs-on: ubuntu-20.04 runs-on: ${{ matrix.build_machine }}
needs: prepare needs: prepare
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os:
- alpine3.14
profile: # all editions for docker profile: # all editions for docker
- emqx-edge - emqx-edge
- emqx - emqx
@ -448,6 +457,14 @@ jobs:
- arm64 - arm64
build_elixir: build_elixir:
- no_elixir - no_elixir
build_machine:
- aws-arm64
- ubuntu-20.04
exclude:
- arch: arm64
build_machine: ubuntu-20.04
- arch: amd64
build_machine: aws-arm64
include: include:
- profile: emqx - profile: emqx
otp: 24.1.5-4 otp: 24.1.5-4
@ -456,24 +473,37 @@ jobs:
build_elixir: with_elixir build_elixir: with_elixir
steps: steps:
- uses: AutoModality/action-clean@v1
if: matrix.build_machine == 'aws-arm64'
- uses: actions/download-artifact@v2 - uses: actions/download-artifact@v2
with: with:
name: source name: source
path: . path: .
- name: unzip source code - name: unzip source code
run: unzip -q source.zip run: unzip -q source.zip
- uses: docker/setup-buildx-action@v1 - uses: docker/setup-buildx-action@v1
- uses: docker/setup-qemu-action@v1
- name: load rocksdb cache
uses: actions/cache@v2
with: with:
image: tonistiigi/binfmt:latest path: source/_build/default/lib/rocksdb/
platforms: all key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ needs.prepare.outputs.DEP_ROCKSDB_REF }}
- name: load quicer cache
uses: actions/cache@v2
with:
path: source/_build/default/lib/quicer/
key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ needs.prepare.outputs.DEP_QUICER_REF }}
# NOTE, Pls make sure this is identical as the one in job 'docker-push-multi-arch-manifest'
- uses: docker/metadata-action@v3 - uses: docker/metadata-action@v3
id: meta id: meta
if: ${{ matrix.build_elixir == 'no_elixir' }} if: ${{ matrix.build_elixir == 'no_elixir' }}
with: with:
images: ${{ github.repository_owner }}/${{ matrix.profile }} images: ${{ github.repository_owner }}/${{ matrix.profile }}
flavor: | flavor: |
latest=${{ !github.event.release.prerelease }} latest=${{ github.event_name == 'release' && !github.event.release.prerelease }}
suffix=-${{ matrix.arch }}
tags: | tags: |
type=ref,event=branch type=ref,event=branch
type=ref,event=pr type=ref,event=pr
@ -509,11 +539,11 @@ jobs:
push: ${{ github.event_name == 'release' && !github.event.release.prerelease }} push: ${{ github.event_name == 'release' && !github.event.release.prerelease }}
pull: true pull: true
no-cache: true no-cache: true
platforms: linux/amd64,linux/arm64 platforms: linux/${{ matrix.arch }}
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
build-args: | build-args: |
BUILD_FROM=ghcr.io/emqx/emqx-builder/5.0-5:${{ matrix.elixir }}-${{ matrix.otp }}-alpine3.14 BUILD_FROM=ghcr.io/emqx/emqx-builder/5.0-5:${{ matrix.elixir }}-${{ matrix.otp }}-${{ matrix.os }}
RUN_FROM=alpine:3.14 RUN_FROM=alpine:3.14
EMQX_NAME=${{ matrix.profile }} EMQX_NAME=${{ matrix.profile }}
file: source/deploy/docker/Dockerfile file: source/deploy/docker/Dockerfile
@ -529,8 +559,8 @@ jobs:
tags: ${{ steps.meta-elixir.outputs.tags }} tags: ${{ steps.meta-elixir.outputs.tags }}
labels: ${{ steps.meta-elixir.outputs.labels }} labels: ${{ steps.meta-elixir.outputs.labels }}
build-args: | build-args: |
BUILD_FROM=ghcr.io/emqx/emqx-builder/5.0-5:${{ matrix.elixir }}-${{ matrix.otp }}-alpine3.14 BUILD_FROM=ghcr.io/emqx/emqx-builder/5.0-5:${{ matrix.elixir }}-${{ matrix.otp }}-${{ matrix.os }}
RUN_FROM=alpine:3.14 RUN_FROM=${{ steps.os-img.outputs.img }}
EMQX_NAME=emqx-elixir EMQX_NAME=emqx-elixir
file: source/deploy/docker/Dockerfile file: source/deploy/docker/Dockerfile
context: source context: source
@ -557,6 +587,84 @@ jobs:
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
docker push public.ecr.aws/emqx/emqx:${version#v} docker push public.ecr.aws/emqx/emqx:${version#v}
docker-push-multi-arch-manifest:
if: github.event_name == 'release'
needs: docker
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
profile: # all editions for docker
- emqx-edge
- emqx
- emqx-enterprise
arch:
- amd64
- arm64
build_machine:
- aws-arm64
- ubuntu-20.04
exclude:
- arch: arm64
build_machine: ubuntu-20.04
- arch: amd64
build_machine: aws-arm64
# NOTE: for docker, only support latest otp version, not a matrix
otp:
- 24.1.5-3 # update to latest
steps:
- uses: docker/login-action@v1
if: matrix.arch == 'amd64'
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
# NOTE, Pls make sure this is identical as the one in job 'docker'
- uses: docker/metadata-action@v3
if: matrix.arch == 'amd64'
id: meta
with:
images: ${{ github.repository_owner }}/${{ matrix.profile }}
flavor: |
latest=false
suffix=-${{ matrix.arch }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=semver,pattern={{version}}
labels:
org.opencontainers.image.otp.version=${{ matrix.otp }}
- name: update manifest for multiarch image
# we only run on amd64
if: matrix.arch == 'amd64'
run: |
set -xeu
img_amd64="${{ steps.meta.outputs.tags }}"
img_arm64=$(echo ${img_amd64} | sed 's/-amd64$/-arm64/g')
img_march=${img_amd64%-amd64}
docker pull "$img_amd64"
docker pull --platform linux/arm64 "$img_arm64"
img_amd64_digest=$(docker inspect --format='{{index .RepoDigests 0}}' "$img_amd64")
img_arm64_digest=$(docker inspect --format='{{index .RepoDigests 0}}' "$img_arm64")
echo "sha256 of amd64 is $img_amd64_digest"
echo "sha256 of arm64 is $img_arm64_digest"
docker manifest create "${img_march}" \
--amend "$img_amd64_digest" \
--amend "$img_arm64_digest"
docker manifest push "${img_march}"
# PUSH latest if it is a release build
if ${{ github.event_name == 'release' && !github.event.release.prerelease }}; then
img_latest="${{ github.repository_owner }}/${{ matrix.profile }}:latest"
docker manifest create "${img_latest}" \
--amend "$img_amd64_digest" \
--amend "$img_arm64_digest"
docker manifest push "${img_latest}"
fi
delete-artifact: delete-artifact:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
needs: [prepare, mac, linux, docker] needs: [prepare, mac, linux, docker]