-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (96 loc) · 4.3 KB
/
deploy.yaml
File metadata and controls
100 lines (96 loc) · 4.3 KB
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
# This is a basic workflow to help you get started with Actions
name: Build Docker container, Push to ACR and Deploy to Azure Container Instance.
# Controls when the workflow will run
on:
# Triggers the workflow on push events but only for the master/main branch
push:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# checkout the repo
- name: 'Checkout GitHub Action'
uses: actions/checkout@main
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Restore dotnet dependencies
run: dotnet restore
- name: Build dotnet projects
run: dotnet build
- name: Run unit tests
run: dotnet test
- name: 'Login via Azure CLI'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: 'Build and push image'
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- run: |
docker build -f ${{ github.workspace }}/UnityBotService/Dockerfile -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/unitybotservice:${{ github.sha }} .
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/unitybotservice:${{ github.sha }}
deploy-to-container-instance:
needs: build-and-push
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ github.workspace }}/UnityBotService/Deployment
steps:
# checkout the repo
- name: 'Checkout GitHub Action'
uses: actions/checkout@main
- name: Create parameter file from template
env:
REG_UNAME: ${{ secrets.REGISTRY_USERNAME }}
REG_PWD: ${{ secrets.REGISTRY_PASSWORD }}
IMAGE_VERSION: ${{ github.sha }}
REGISTRY_LOGIN_SERVER: ${{ secrets.REGISTRY_LOGIN_SERVER }}
TWITTER_APIKEY: ${{ secrets.TWITTER_APIKEY }}
TWITTER_APISECRET: ${{ secrets.TWITTER_APISECRET }}
TWITTER_ACCESSTOKEN: ${{ secrets.TWITTER_ACCESSTOKEN }}
TWITTER_ACCESSTOKENSECRET: ${{ secrets.TWITTER_ACCESSTOKENSECRET }}
TWITTER_BEARERTOKEN: ${{ secrets.TWITTER_BEARERTOKEN }}
run: |
encodedApiKey=$(echo $TWITTER_APIKEY | base64)
encodedApiSecret=$(echo $TWITTER_APISECRET | base64)
encodedAccessToken=$(echo $TWITTER_ACCESSTOKEN | base64)
encodedAccessTokenSecret=$(echo $TWITTER_ACCESSTOKENSECRET | base64)
encodedBearerToken=$(echo $TWITTER_BEARERTOKEN | base64)
awk -v registryUsername="$REG_UNAME" \
-v registryPassword="$REG_PWD" \
-v imageVersion="$IMAGE_VERSION" \
-v registryUrl="$REGISTRY_LOGIN_SERVER" \
-v encodedApiKey="$encodedApiKey" \
-v encodedApiSecret="$encodedApiSecret" \
-v encodedAccessToken="$encodedAccessToken" \
-v encodedAccessTokenSecret="$encodedAccessTokenSecret" \
-v encodedBearerToken="$encodedBearerToken" \
'{
sub(/{REGISTRY_USERNAME}/, registryUsername);
sub(/{REGISTRY_PASSWORD}/, registryPassword);
sub(/{IMAGE_VERSION}/, imageVersion);
sub(/{REGISTRY_URL}/, registryUrl);
sub(/{TWITTER_APIKEY}/, encodedApiKey);
sub(/{TWITTER_APISECRET}/, encodedApiSecret);
sub(/{TWITTER_ACCESSTOKEN}/, encodedAccessToken);
sub(/{TWITTER_ACCESSTOKENSECRET}/, encodedAccessTokenSecret);
sub(/{TWITTER_BEARERTOKEN}/, encodedBearerToken);
print;
}' parameters.template.json > $RUNNER_TEMP/parameters.json
- name: 'Login via Azure CLI'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: 'Deploy to Azure Container Instances'
env:
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
run: |
az deployment group create -g $RESOURCE_GROUP -f containerdeploy.json -p ${{ runner.temp }}/parameters.json