-
Notifications
You must be signed in to change notification settings - Fork 4
173 lines (150 loc) · 4.96 KB
/
authorization-service.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: AuthorizationService
on:
workflow_dispatch:
push:
branches:
- main
paths:
- src/Services/AuthorizationService/**
pull_request:
types: [opened, synchronize, reopened]
paths:
- src/Services/AuthorizationService/**
defaults:
run:
working-directory: src
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
# Checks out the code
- name: Checkout
uses: actions/checkout@v2
# Sets up the .NET SDK
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1.7.2
with:
dotnet-version: '5.0.x'
# Installs the dependencies
- name: Install dependencies
run: dotnet restore ./Services/AuthorizationService/API
# Builds the code
- name: Build
run: dotnet build --no-restore ./Services/AuthorizationService/API
test:
needs: build
name: Test
runs-on: ubuntu-latest
steps:
# Checks out the code
- name: Checkout
uses: actions/checkout@v2
# Tests the code
- name: Build
run: dotnet test ./Services/AuthorizationService/Tests
semver:
name: Calculate SemVer version
runs-on: ubuntu-latest
outputs:
SEMVER: ${{ steps.fixsemver.outputs.SEMVER }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Git version
id: gitversion
uses: codacy/git-version@2.4.0
with:
prefix: kwetter-authorization-service-
- name: Fix semver
id: fixsemver
run: |
VERSION=${{ steps.gitversion.outputs.VERSION }}
FIXED_SEMVER=${VERSION##*kwetter-authorization-service-}
echo "::set-output name=SEMVER::${FIXED_SEMVER}"
echo "${FIXED_SEMVER}"
docker:
needs:
- test
- semver
name: Build and push Docker images
env:
SEMVER: ${{ needs.semver.outputs.SEMVER }}
environment:
name: docker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Add Neuralm certificate
run: |
echo "Create root certificate directory"
sudo mkdir -p /usr/local/share/ca-certificates/${{ secrets.NEURALM_REGISTRY }}/
echo "Create certificate"
sudo printf "${{ secrets.NEURALM_CERTIFICATE }}" >> neuralm.crt
echo "Create docker directory"
sudo mkdir -p /etc/docker/
echo "Create docker daemon json"
sudo touch /etc/docker/daemon.json
echo "Copy certificate to the ca-certificates directory"
sudo cp neuralm.crt /usr/local/share/ca-certificates/${{ secrets.NEURALM_REGISTRY }}/ca.crt
echo "Create neuralm certificate directory in docker"
sudo mkdir -p /etc/docker/certs.d/${{ secrets.NEURALM_REGISTRY }}/
echo "Copy certificate to the docker directory"
sudo cp neuralm.crt /etc/docker/certs.d/${{ secrets.NEURALM_REGISTRY }}/ca.crt
echo "Update CA certificates"
sudo update-ca-certificates
echo "Restart docker"
sudo systemctl daemon-reload
sudo systemctl restart docker
- name: Set up Docker 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: Login to Neuralm Docker registry
uses: docker/login-action@v1
with:
registry: ${{ secrets.NEURALM_REGISTRY }}
username: ${{ secrets.NEURALM_DOCKER_USERNAME }}
password: ${{ secrets.NEURALM_DOCKER_PASSWORD }}
- name: Build and push AuthorizationService Docker image
run: |
echo "Building AuthorizationService docker image"
docker build -t ${{ secrets.NEURALM_REGISTRY }}/kwetter-authorization-service:${{ env.SEMVER }} -t ${{ secrets.NEURALM_REGISTRY }}/kwetter-authorization-service:latest -f ./kwetter-authorization-service.Dockerfile .
echo "Publishing AuthorizationService docker image"
docker push --all-tags ${{ secrets.NEURALM_REGISTRY }}/kwetter-authorization-service
production:
needs:
- docker
- semver
name: Deploy to Kubernetes
env:
SEMVER: ${{ needs.semver.outputs.SEMVER }}
environment:
name: production
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update manifest tags
run: |
sed -i'' -e 's/:latest/:${{ env.SEMVER }}/g' ./../K8s/services/authorization-service/kwetter-authorization-service.deployment.yaml
- name: Set kubernetes context
uses: azure/k8s-set-context@v1
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBE_CONFIG }}
context: kwetter
- name: Deploy services
uses: jtalk/k8s-deploy@v2
with:
namespace: kwetter
manifests: |
./K8s/services/authorization-service/kwetter-authorization-service.deployment.yaml