-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (113 loc) · 3.92 KB
/
push.yaml
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: Docker
on:
push:
branches: [ main, master, develop ]
paths-ignore:
- 'k8s/**'
workflow_run:
workflows: ["Sync"]
types:
- completed
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
TEST_TAG: unittests
jobs:
build-push:
name: Build and Deploy to Github Registry
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.prep.outputs.BUILD_ID }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Generate build ID
id: prep
run: |
branch=${GITHUB_REF##*/}
sha=${GITHUB_SHA::8}
ts=$(date +%s)
echo "BUILD_ID=${branch}-${ts}-${sha}" >> $GITHUB_OUTPUT
# These are prerequisites for the docker build step
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build test
uses: docker/build-push-action@v4
with:
context: .
file: ./BrotatoServer/Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
target: test
load: true
tags: ${{ env.TEST_TAG }}
- name: Test
run: |
mkdir TestResults
docker run --rm -v $(pwd)/TestResults:/src/BrotatoServer.Tests/TestResults ${{ env.TEST_TAG }}
- uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: .NET Tests
path: TestResults/*.trx
reporter: dotnet-trx
- name: Ensure Lowercase Imagename
run: |
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV
- name: Build and publish container image with tag
uses: docker/build-push-action@v3
id: build_and_publish
with:
push: true
context: .
file: ./BrotatoServer/Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.prep.outputs.BUILD_ID }}
update_k8s:
runs-on: ubuntu-latest
needs: build-push
steps:
- name: Check if main/master branch
run: |
if [[ ${{ github.ref }} != "refs/heads/main" && ${{ github.ref }} != "refs/heads/master" && ${{ github.ref }} != "refs/heads/develop" ]]; then exit 0; fi
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Kubectl
uses: azure/k8s-set-context@v3
with:
kubeconfig: ${{ secrets.KUBE_CONFIG_DATA }}
- name: Install Kustomize
run: |
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
sudo mv kustomize /usr/local/bin
- name: Update Kubernetes manifests
run: |
cd k8s/
kustomize create --autodetect
kustomize edit set image ghcr.io/danbopes/brotatoserver:${{ needs.build-push.outputs.image_tag }}
if [[ ${{ github.ref }} == "refs/heads/main" || ${{ github.ref }} == "refs/heads/master" ]]; then
kustomize edit set namespace brotato
else
kustomize edit set namespace brotato-dev
fi
kustomize build . > deploy.yaml
kubectl apply -f deploy.yaml
# - name: Commit and Push changes
# run: |
# git config --local user.email "[email protected]"
# git config --local user.name "GitHub Action"
# git add .
# git commit -m "Update image to latest"
# git push