-
Notifications
You must be signed in to change notification settings - Fork 204
120 lines (111 loc) · 4.88 KB
/
docker_auto_release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Build on release and push to Docker Hub
on:
push:
tags:
- "v*"
jobs:
main:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
DOCKER_PLATFORMS: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
DOCKER_IMAGE: haproxytech/kubernetes-ingress
LATEST_BRANCH: "1.9"
steps:
- name: Login to Docker Hub
id: login_docker
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Login to Container Registry
id: login_ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Check out repo
id: checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Prepare env variables
id: env
run: |
echo "BUILD_BRANCH=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's:^v::g' | cut -d. -f-2)" >> $GITHUB_ENV
echo "BUILD_VER=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's:^v::g')" >> $GITHUB_ENV
echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
echo "GIT_SHA=$(git rev-parse --short HEAD | cut -c1-7)" >> $GITHUB_ENV
echo "GIT_REF=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" >> $GITHUB_ENV
echo "LATEST_BRANCH=$(curl -sfSL 'https://raw.githubusercontent.com/haproxytech/kubernetes-ingress/master/documentation/doc.yaml' 2>/dev/null | awk -F: '/^active_version/ {gsub(/^ /,"",$2); print $2}' || echo $LATEST_BRANCH)" >> $GITHUB_ENV
- name: Build and push latest stable branch
if: ${{ env.BUILD_BRANCH == env.LATEST_BRANCH }}
id: docker_build_latest
uses: docker/build-push-action@v2
with:
context: .
file: build/Dockerfile
builder: ${{ steps.buildx.outputs.name }}
platforms: ${{ env.DOCKER_PLATFORMS }}
push: true
labels: |
org.opencontainers.image.authors=${{ github.repository_owner }}
org.opencontainers.image.created=${{ env.BUILD_DATE }}
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }}
org.opencontainers.image.ref.name=${{ env.GIT_REF }}
org.opencontainers.image.revision=${{ env.GIT_SHA }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ env.BUILD_VER }}
tags: |
${{ env.DOCKER_IMAGE }}:latest
${{ env.DOCKER_IMAGE }}:${{ env.BUILD_BRANCH }}
${{ env.DOCKER_IMAGE }}:${{ env.BUILD_VER }}
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ env.BUILD_BRANCH }}
ghcr.io/${{ github.repository }}:${{ env.BUILD_VER }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Build and push everything else
if: ${{ env.BUILD_BRANCH != env.LATEST_BRANCH }}
id: docker_build_regular
uses: docker/build-push-action@v2
with:
context: .
file: build/Dockerfile
builder: ${{ steps.buildx.outputs.name }}
platforms: ${{ env.DOCKER_PLATFORMS }}
push: true
labels: |
org.opencontainers.image.authors=${{ github.repository_owner }}
org.opencontainers.image.created=${{ env.BUILD_DATE }}
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }}
org.opencontainers.image.ref.name=${{ env.GIT_REF }}
org.opencontainers.image.revision=${{ env.GIT_SHA }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ env.BUILD_VER }}
tags: |
${{ env.DOCKER_IMAGE }}:${{ env.BUILD_BRANCH }}
${{ env.DOCKER_IMAGE }}:${{ env.BUILD_VER }}
ghcr.io/${{ github.repository }}:${{ env.BUILD_BRANCH }}
ghcr.io/${{ github.repository }}:${{ env.BUILD_VER }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache