generated from ActionsFundamentals/octodex-rss-renderer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontinuous_delivery_complete.yml
More file actions
172 lines (137 loc) · 4.24 KB
/
continuous_delivery_complete.yml
File metadata and controls
172 lines (137 loc) · 4.24 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
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
#
# A more complex end to end single workflow that will build and test our code, build a
# container and publish it to the GHCR and then finally deploy it to a cloud based
# environment.
#
name: Continuous Delivery
on:
# push:
# - main
workflow_dispatch:
jobs:
build:
name: Build
strategy:
matrix:
os:
- ubuntu-20.04
node_version:
- 16
- 14
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node_version }}
cache: npm
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Build
run: npm run build
- name: Save Applicaton Bundle
uses: actions/upload-artifact@v2
with:
name: app-${{ matrix.os }}-${{ matrix.node_version }}
path: |
.next
public
package.json
package-lock.json
#
# Build the container using the previously built artifacts from the build job
#
build_container:
name: Build Container
needs:
- build
runs-on: ubuntu-20.04
outputs:
deployment_container_url: ${{ steps.container_meta.outputs.container_tag }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Unpack Artifact
uses: actions/download-artifact@v2
with:
name: app-ubuntu-20.04-16
path: continuous-delivery/app
- name: Display structure of downloaded files
run: ls -R
working-directory: continuous-delivery/app
- name: Restore the node_modules
run: |
npm ci
working-directory: continuous-delivery/app
# Define the container URL tag for publishing
- name: Define container tag
id: container_meta
uses: actions/github-script@v4
with:
script: |
core.setOutput(
'container_tag',
`ghcr.io/${context.repo.owner}/${context.repo.repo}:${context.sha}`.toLowerCase()
);
- name: Build Container
run: |
docker build . --tag ${{ steps.container_meta.outputs.container_tag }}
working-directory: continuous-delivery
- name: GitHub Container Registry Login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Container to GHCR
run: |
docker push ${{ steps.container_meta.outputs.container_tag }}
#
# Deploys the container to a Cloud Environment
#
deploy:
name: Deploy to Azure Environment
needs:
- build
- build_container
runs-on: ubuntu-20.04
environment:
name: azure_production
url: ${{ steps.azure_deployment.outputs.app-url }}
env:
acr_container: ${{ secrets.ACR_URL }}/octodex-rss-renderer:${{ github.sha }}
steps:
- name: Deploy
run: echo "deploying..."
- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Login to ACR
uses: docker/login-action@v1
with:
registry: ${{ secrets.ACR_URL }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Fetch GHCR Container and push to ACR
run: |
docker pull ${{ needs.build_container.outputs.deployment_container_url }}
docker tag ${{ needs.build_container.outputs.deployment_container_url }} ${{ env.acr_container }}
docker push ${{ env.acr_container }}
- name: Deploy Container
id: azure_deployment
uses: azure/aci-deploy@v1
with:
resource-group: ${{ secrets.RESOURCE_GROUP }}
dns-name-label: octodex-rss${{ github.run_number }}
image: ${{ env.acr_container }}
registry-login-server: ${{ secrets.ACR_URL }}
registry-username: ${{ secrets.ACR_USERNAME }}
registry-password: ${{ secrets.ACR_PASSWORD }}
name: octodex-rss-renderer
location: uksouth
ports: 3000