docker: build for arm cpu (#8633)
ref: #4931
odanado committed
Feb 16, 2022 at 06:54 UTC
0216bae3078c18aaac1c44268f861cc519196665
2 files changed
+82
-6
.github/workflows/docker-image.yml
+21
-6
@@ -15,13 +15,23 @@ jobs:
15
runs-on: ubuntu-latest
16
env:
17
IMAGE_NAME: ipfs/go-ipfs
18
- WIP_IMAGE_TAG: wip
18
steps:
19
- name: Check out the repo
20
uses: actions/checkout@v2
21
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
35
36
- name: Log in to Docker Hub
37
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
@@ -29,6 +39,11 @@ jobs:
39
username: ${{ secrets.DOCKER_USERNAME }}
40
password: ${{ secrets.DOCKER_PASSWORD }}
41
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
new
+61
@@ -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