Skip to content

Commit 7a0774c

Browse files
committed
BUILD: docker: Add Github actions for auto and manual multiarch builds for Docker Hub.
1 parent 4262a20 commit 7a0774c

File tree

2 files changed

+204
-0
lines changed

2 files changed

+204
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Build on release and push to Docker Hub
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
jobs:
7+
main:
8+
runs-on: ubuntu-latest
9+
env:
10+
DOCKER_PLATFORMS: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le
11+
DOCKER_IMAGE: haproxytech/kubernetes-ingress
12+
STABLE_BRANCH: "1.6"
13+
steps:
14+
- name: Login to Docker Hub
15+
id: login
16+
uses: docker/login-action@v1
17+
with:
18+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
19+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
20+
21+
- name: Set up QEMU
22+
uses: docker/setup-qemu-action@v1
23+
24+
- name: Set up Docker Buildx
25+
id: buildx
26+
uses: docker/setup-buildx-action@v1
27+
28+
- name: Cache Docker layers
29+
uses: actions/cache@v2
30+
with:
31+
path: /tmp/.buildx-cache
32+
key: ${{ runner.os }}-buildx-${{ github.sha }}
33+
restore-keys: |
34+
${{ runner.os }}-buildx-
35+
36+
- name: Check out repo
37+
id: checkout
38+
uses: actions/checkout@v2
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Prepare env variables
43+
id: env
44+
run: |
45+
echo "BUILD_BRANCH=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's:^v::g' | cut -d. -f-2)" >> $GITHUB_ENV
46+
echo "BUILD_VER=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's:^v::g')" >> $GITHUB_ENV
47+
echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
48+
echo "GIT_SHA=$(git rev-parse --short HEAD | cut -c1-7)" >> $GITHUB_ENV
49+
echo "GIT_REF=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" >> $GITHUB_ENV
50+
51+
- name: Build and push latest stable branch
52+
if: ${{ env.BUILD_BRANCH == env.STABLE_BRANCH }}
53+
id: docker_build_latest
54+
uses: docker/build-push-action@v2
55+
with:
56+
context: .
57+
file: build/Dockerfile
58+
builder: ${{ steps.buildx.outputs.name }}
59+
platforms: ${{ env.DOCKER_PLATFORMS }}
60+
push: true
61+
labels: |
62+
org.opencontainers.image.authors=${{ github.repository_owner }}
63+
org.opencontainers.image.created=${{ env.BUILD_DATE }}
64+
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }}
65+
org.opencontainers.image.ref.name=${{ env.GIT_REF }}
66+
org.opencontainers.image.revision=${{ env.GIT_SHA }}
67+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
68+
org.opencontainers.image.version=${{ env.BUILD_VER }}
69+
tags: |
70+
${{ env.DOCKER_IMAGE }}:latest
71+
${{ env.DOCKER_IMAGE }}:${{ env.BUILD_VER }}
72+
cache-from: type=local,src=/tmp/.buildx-cache
73+
cache-to: type=local,dest=/tmp/.buildx-cache-new
74+
75+
- name: Build and push everything else
76+
if: ${{ env.BUILD_BRANCH != env.STABLE_BRANCH }}
77+
id: docker_build_regular
78+
uses: docker/build-push-action@v2
79+
with:
80+
context: .
81+
file: build/Dockerfile
82+
builder: ${{ steps.buildx.outputs.name }}
83+
platforms: ${{ env.DOCKER_PLATFORMS }}
84+
push: true
85+
labels: |
86+
org.opencontainers.image.authors=${{ github.repository_owner }}
87+
org.opencontainers.image.created=${{ env.BUILD_DATE }}
88+
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }}
89+
org.opencontainers.image.ref.name=${{ env.GIT_REF }}
90+
org.opencontainers.image.revision=${{ env.GIT_SHA }}
91+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
92+
org.opencontainers.image.version=${{ env.BUILD_VER }}
93+
tags: |
94+
${{ env.DOCKER_IMAGE }}:${{ env.BUILD_VER }}
95+
cache-from: type=local,src=/tmp/.buildx-cache
96+
cache-to: type=local,dest=/tmp/.buildx-cache-new
97+
98+
- name: Move cache
99+
run: |
100+
rm -rf /tmp/.buildx-cache
101+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Manual build latest tag and push to Docker Hub
2+
on:
3+
workflow_dispatch:
4+
jobs:
5+
main:
6+
runs-on: ubuntu-latest
7+
env:
8+
DOCKER_PLATFORMS: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le
9+
DOCKER_IMAGE: haproxytech/kubernetes-ingress
10+
STABLE_BRANCH: "1.6"
11+
steps:
12+
- name: Login to Docker Hub
13+
id: login
14+
uses: docker/login-action@v1
15+
with:
16+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
17+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
18+
19+
- name: Set up QEMU
20+
uses: docker/setup-qemu-action@v1
21+
22+
- name: Set up Docker Buildx
23+
id: buildx
24+
uses: docker/setup-buildx-action@v1
25+
26+
- name: Cache Docker layers
27+
uses: actions/cache@v2
28+
with:
29+
path: /tmp/.buildx-cache
30+
key: ${{ runner.os }}-buildx-${{ github.sha }}
31+
restore-keys: |
32+
${{ runner.os }}-buildx-
33+
34+
- name: Check out repo
35+
id: checkout
36+
uses: actions/checkout@v2
37+
with:
38+
fetch-depth: 0
39+
40+
- name: Reposition to latest tag
41+
run: |
42+
git checkout $(git describe --tags --abbrev=0)
43+
44+
- name: Prepare env variables
45+
id: env
46+
run: |
47+
echo "BUILD_BRANCH=$(git describe --tags --abbrev=0 | sed -e 's:^v::g' | cut -d. -f-2)" >> $GITHUB_ENV
48+
echo "BUILD_VER=$(git describe --tags --abbrev=0 | sed -e 's:^v::g')" >> $GITHUB_ENV
49+
echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
50+
echo "GIT_SHA=$(git rev-parse --short HEAD | cut -c1-7)" >> $GITHUB_ENV
51+
echo "GIT_REF=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" >> $GITHUB_ENV
52+
53+
- name: Build and push latest stable branch
54+
if: ${{ env.BUILD_BRANCH == env.STABLE_BRANCH }}
55+
id: docker_build_latest
56+
uses: docker/build-push-action@v2
57+
with:
58+
context: .
59+
file: build/Dockerfile
60+
builder: ${{ steps.buildx.outputs.name }}
61+
platforms: ${{ env.DOCKER_PLATFORMS }}
62+
push: true
63+
labels: |
64+
org.opencontainers.image.authors=${{ github.repository_owner }}
65+
org.opencontainers.image.created=${{ env.BUILD_DATE }}
66+
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }}
67+
org.opencontainers.image.ref.name=${{ env.GIT_REF }}
68+
org.opencontainers.image.revision=${{ env.GIT_SHA }}
69+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
70+
org.opencontainers.image.version=${{ env.BUILD_VER }}
71+
tags: |
72+
${{ env.DOCKER_IMAGE }}:latest
73+
${{ env.DOCKER_IMAGE }}:${{ env.BUILD_VER }}
74+
cache-from: type=local,src=/tmp/.buildx-cache
75+
cache-to: type=local,dest=/tmp/.buildx-cache-new
76+
77+
- name: Build and push everything else
78+
if: ${{ env.BUILD_BRANCH != env.STABLE_BRANCH }}
79+
id: docker_build_regular
80+
uses: docker/build-push-action@v2
81+
with:
82+
context: .
83+
file: build/Dockerfile
84+
builder: ${{ steps.buildx.outputs.name }}
85+
platforms: ${{ env.DOCKER_PLATFORMS }}
86+
push: true
87+
labels: |
88+
org.opencontainers.image.authors=${{ github.repository_owner }}
89+
org.opencontainers.image.created=${{ env.BUILD_DATE }}
90+
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }}
91+
org.opencontainers.image.ref.name=${{ env.GIT_REF }}
92+
org.opencontainers.image.revision=${{ env.GIT_SHA }}
93+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
94+
org.opencontainers.image.version=${{ env.BUILD_VER }}
95+
tags: |
96+
${{ env.DOCKER_IMAGE }}:${{ env.BUILD_VER }}
97+
cache-from: type=local,src=/tmp/.buildx-cache
98+
cache-to: type=local,dest=/tmp/.buildx-cache-new
99+
100+
- name: Move cache
101+
run: |
102+
rm -rf /tmp/.buildx-cache
103+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

0 commit comments

Comments
 (0)