-
Notifications
You must be signed in to change notification settings - Fork 3
140 lines (122 loc) · 5.4 KB
/
ci-cd.yaml
File metadata and controls
140 lines (122 loc) · 5.4 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
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
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.
name: Publish Docker image
on:
push
jobs:
build:
name: Docker Build
runs-on: ubuntu-latest
if: ${{ github.ref != 'refs/heads/dev' && github.ref != 'refs/heads/master' }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Build
uses: docker/build-push-action@v3
with:
context: PoliNetworkBot_CSharp/
push: false
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/master' }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Set env
if: ${{ github.ref == 'refs/heads/master' }}
run: echo "DOCKER_REPO=$(echo prod)" >> $GITHUB_ENV
- name: Set env
if: ${{ github.ref == 'refs/heads/dev' }}
run: echo "DOCKER_REPO=$(echo dev)" >> $GITHUB_ENV
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: PoliNetworkBot_CSharp/
push: true
tags: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}
Update-K8s-Manifests:
name: Update K8s Deployment Manifest with Image Version
needs: push_to_registry
runs-on: ubuntu-latest
steps:
- name: Get application code from repo
uses: actions/checkout@v3
with:
repository: polinetworkorg/polinetwork-cd
ssh-key: ${{ secrets.CD_DEPLOY_KEY }}
- name: Debug
run: |
sudo apt install tree
tree -L 2
- name: Update image name in manifest file
if: ${{ github.ref == 'refs/heads/dev' }}
uses: azure/powershell@v1
env:
DOCKER_REPO: 'dev'
STAGE_ENV: 'dev'
with:
inlineScript: |
$line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line
$content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
$content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
azPSVersion: "latest"
- name: Update image name in manifest file
if: ${{ github.ref == 'refs/heads/master' }}
env:
DOCKER_REPO: 'prod'
STAGE_ENV: 'prod'
uses: azure/powershell@v1
with:
inlineScript: |
$line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line
$content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
$content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
azPSVersion: "latest"
- name: Update image name in manifest file
if: ${{ github.ref == 'refs/heads/master' }}
env:
DOCKER_REPO: 'prod'
STAGE_ENV: 'mat'
uses: azure/powershell@v1
with:
inlineScript: |
$line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line
$content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
$content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
azPSVersion: "latest"
- name: Update image name in manifest file
if: ${{ github.ref == 'refs/heads/dev' }}
env:
DOCKER_REPO: 'dev'
STAGE_ENV: 'rooms'
uses: azure/powershell@v1
with:
inlineScript: |
$line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line
$content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
$content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
azPSVersion: "latest"
- name: Commit changes in manifest to repo
run: |
git config user.name "GitHub Actions Bot"
git config user.email ""
git add */bot-deployment.yaml
git commit -m "Update image version in K8s Deployment manifests file"
git config pull.rebase false # merge
git pull
git push origin