Skip to content

Commit 0216bae

Browse files
authored
docker: build for arm cpu (#8633)
ref: #4931
1 parent 62979db commit 0216bae

File tree

2 files changed

+82
-6
lines changed

2 files changed

+82
-6
lines changed

.github/workflows/docker-image.yml

+21-6
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,35 @@ jobs:
1515
runs-on: ubuntu-latest
1616
env:
1717
IMAGE_NAME: ipfs/go-ipfs
18-
WIP_IMAGE_TAG: wip
1918
steps:
2019
- name: Check out the repo
2120
uses: actions/checkout@v2
2221

23-
- name: Build wip Docker image
24-
run: docker build -t $IMAGE_NAME:$WIP_IMAGE_TAG .
22+
- name: Set up QEMU
23+
uses: docker/setup-qemu-action@v1
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v1
27+
28+
- name: Get tags
29+
id: tags
30+
run: |
31+
TAGS="$(./bin/get-docker-tags.sh $(date -u +%F))"
32+
TAGS="${TAGS//$'\n'/'%0A'}"
33+
echo "::set-output name=value::$(echo $TAGS)"
34+
shell: bash
2535

2636
- name: Log in to Docker Hub
2737
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
2838
with:
2939
username: ${{ secrets.DOCKER_USERNAME }}
3040
password: ${{ secrets.DOCKER_PASSWORD }}
3141

32-
- name: Publish Docker Image to Docker Hub
33-
run: ./bin/push-docker-tags.sh $(date -u +%F)
34-
42+
- name: Build Docker image and publish to Docker Hub
43+
uses: docker/build-push-action@v2
44+
with:
45+
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
46+
context: .
47+
push: true
48+
file: ./Dockerfile
49+
tags: "${{ steps.tags.outputs.value }}"

bin/get-docker-tags.sh

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
# get-docker-tags.sh
4+
#
5+
# Usage:
6+
# ./get-docker-tags.sh <build number> <git commit sha1> <git branch name> [git tag name]
7+
#
8+
# Example:
9+
#
10+
# # get tag for the master branch
11+
# ./get-docker-tags.sh $(date -u +%F) testingsha master
12+
#
13+
# # get tag for a release tag
14+
# ./get-docker-tags.sh $(date -u +%F) testingsha release v0.5.0
15+
#
16+
# # Serving suggestion in circle ci - https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables
17+
# ./get-docker-tags.sh $(date -u +%F) "$CIRCLE_SHA1" "$CIRCLE_BRANCH" "$CIRCLE_TAG"
18+
#
19+
set -euo pipefail
20+
21+
if [[ $# -lt 1 ]] ; then
22+
echo 'At least 1 arg required.'
23+
echo 'Usage:'
24+
echo './push-docker-tags.sh <build number> [git commit sha1] [git branch name] [git tag name]'
25+
exit 1
26+
fi
27+
28+
BUILD_NUM=$1
29+
GIT_SHA1=${2:-$(git rev-parse HEAD)}
30+
GIT_SHA1_SHORT=$(echo "$GIT_SHA1" | cut -c 1-7)
31+
GIT_BRANCH=${3:-$(git symbolic-ref -q --short HEAD || echo "unknown")}
32+
GIT_TAG=${4:-$(git describe --tags --exact-match || echo "")}
33+
34+
IMAGE_NAME=${IMAGE_NAME:-ipfs/go-ipfs}
35+
36+
echoImageName () {
37+
local IMAGE_TAG=$1
38+
echo "$IMAGE_NAME:$IMAGE_TAG"
39+
}
40+
41+
if [[ $GIT_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+-rc ]]; then
42+
echoImageName "$GIT_TAG"
43+
44+
elif [[ $GIT_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
45+
echoImageName "$GIT_TAG"
46+
echoImageName "latest"
47+
echoImageName "release" # see: https://github.com/ipfs/go-ipfs/issues/3999#issuecomment-742228981
48+
49+
elif [[ $GIT_BRANCH =~ ^bifrost-.* ]]; then
50+
# sanitize the branch name since docker tags have stricter char limits than git branch names
51+
branch=$(echo "$GIT_BRANCH" | tr '/' '-' | tr --delete --complement '[:alnum:]-')
52+
echoImageName "${branch}-${BUILD_NUM}-${GIT_SHA1_SHORT}"
53+
54+
elif [ "$GIT_BRANCH" = "master" ]; then
55+
echoImageName "master-${BUILD_NUM}-${GIT_SHA1_SHORT}"
56+
echoImageName "master-latest"
57+
58+
else
59+
echo "Nothing to do. No docker tag defined for branch: $GIT_BRANCH, tag: $GIT_TAG"
60+
61+
fi

0 commit comments

Comments
 (0)