-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (92 loc) · 3.22 KB
/
ci.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
name: CI
on:
workflow_dispatch:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
env:
GOOS: linux
GOARCH: amd64
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.21.x
cache: false
- name: Get Go cached paths
run: |
echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Set up dependencies cache
uses: actions/cache@v3
with:
path: |
${{ env.cache }}
key: setup-go-deps-${{ runner.os }}-go-${{ hashFiles('go.sum', 'go.mod') }}
- run: echo "$GOOS $GOARCH" > env.txt
- name: Set up intermediate built files cache
uses: actions/cache@v3
with:
path: |
${{ env.modcache }}
key: setup-go-build-${{ env.GOOS }}-${{ env.GOARCH }}-${{ runner.os }}-go-${{ hashFiles('**/*.go', 'env.txt') }}
restore-keys: |
setup-go-build-${{ env.GOOS }}-${{ env.GOARCH }}-${{ runner.os }}-go
- name: Build Linux binary
run: go build
- name: Build & tar docker image
if: ${{ true }}
run: |
docker build -t az-appservice-go .
docker save az-appservice-go |gzip > az-appservice-go.tar.gz
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: docker-image
path: az-appservice-go.tar.gz
choose-registry:
runs-on: ubuntu-latest
env:
dockerhub: true
azure: false
outputs:
dockerhub: ${{ steps.choose.outputs.dockerhub }}
azureregistry: ${{ steps.choose.outputs.azureregistry }}
steps:
- name: Choose container registry
id: choose
run: |
echo "dockerhub==${dockerhub}" >> $GITHUB_OUTPUT
echo "azureregistry==${azureregistry}" >> $GITHUB_OUTPUT
publish-to-registry:
needs: [build, choose-registry]
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: docker-image
- name: Unar docker image
run: |
gunzip -c az-appservice-go.tar.gz| docker load
docker images
- name: Publish to Docker Hub
if: needs.choose-registry.outputs.dockerhub
run: |
docker tag az-appservice-go ${{ secrets.DOCKER_USERNAME }}/az-appservice-go
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
docker push ${{ secrets.DOCKER_USERNAME }}/az-appservice-go
deplpoy-to-azure-from-dockerhub:
if: needs.choose-registry.outputs.dockerhub
needs: [publish-to-registry, choose-registry]
runs-on: ubuntu-latest
steps:
- name: Deploy to Azure Web App from docker hub
uses: azure/webapps-deploy@v2
with:
app-name: az-appservice-go-dockerhub
publish-profile: ${{ secrets.APP_GO_DOCKERHUB_PROFILE }}