generated from csdev/golang-template
-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (113 loc) · 3.37 KB
/
docker.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
name: docker
on:
pull_request:
push:
branches:
- 'master'
tags:
- 'v*'
workflow_dispatch:
# prevent concurrent workflow runs
# - for pull requests, we only want to build the latest commit
# - for master and tags, we need to run all builds, since containers must be pushed
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
IMAGE_NAME: csang/ezghsa
jobs:
docker:
timeout-minutes: 20
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Build dev image
uses: docker/build-push-action@v4
with:
context: .
file: ./build/dev/Dockerfile
load: true
tags: ${{ env.IMAGE_NAME }}-dev:gha
cache-from: type=gha
cache-to: type=gha,mode=max
-
name: Test dev image
run: >
docker run --rm "$IMAGE_NAME"-dev:gha \
/bin/sh -c 'go test -coverprofile=c.out "./..." && go tool cover -func=c.out'
-
name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push prod image
uses: docker/build-push-action@v4
with:
context: .
file: ./build/prod/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
release:
needs: docker
if: startsWith(github.ref, 'refs/tags/v')
timeout-minutes: 10
runs-on: ubuntu-latest
permissions:
contents: write # for releases api
packages: read
strategy:
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Deploy standalone binaries
env:
GH_TOKEN: ${{ github.token }}
run: |
tag="${GITHUB_REF#'refs/tags/v'}-$(tr / - <<<"${{ matrix.platform }}")"
cid="$(docker create --platform="${{ matrix.platform }}" "$IMAGE_NAME":"${GITHUB_REF#'refs/tags/v'}")"
docker cp "${cid}:/opt/go/bin/ezghsa" "ezghsa-${tag}"
docker rm "$cid"
gh release upload "${GITHUB_REF#'refs/tags/'}" "ezghsa-${tag}"
shell: bash