Skip to content

Commit 31b834a

Browse files
authored
Create main.yml
1 parent e33e7d3 commit 31b834a

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

.github/workflows/main.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Deploy Site
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
name: Build
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Setup node 12
18+
uses: actions/setup-node@v2-beta
19+
with:
20+
node-version: '12.x'
21+
22+
- name: Cache node modules
23+
id: cache-node
24+
uses: actions/cache@v2
25+
with:
26+
path: node_modules
27+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
28+
restore-keys: |
29+
${{ runner.os }}-node-
30+
31+
- name: Install dependencies
32+
if: steps.cache-node.outputs.cache-hit != 'true'
33+
run: |
34+
npm install --silent
35+
36+
- name: Build site
37+
run: npm run build
38+
39+
- name: Set up Docker Buildx
40+
uses: docker/setup-buildx-action@v1
41+
42+
43+
- name: Login to Container Registry
44+
uses: docker/login-action@v1
45+
with:
46+
registry: ${{ secrets.AZURE_REGISTRY_NAME }}
47+
username: ${{secrets.AZURE_REGISTRY_USER}}
48+
password: ${{secrets.AZURE_REGISTRY_PASS}}
49+
50+
- name: Build and push
51+
uses: docker/build-push-action@v2
52+
with:
53+
context: .
54+
file: ./Dockerfile
55+
push: true
56+
tags: ${{ secrets.AZURE_REGISTRY_NAME }}/popular-repos:${{ github.event.pull_request.head.sha || github.sha }}
57+
cache-from: type=registry,ref=${{ secrets.AZURE_REGISTRY_NAME }}/popular-repos:latest
58+
cache-to: type=inline
59+
60+
deploy_to_review:
61+
name: Deploy Review
62+
if: github.event_name == 'pull_request'
63+
runs-on: ubuntu-latest
64+
environment:
65+
name: review-lab
66+
url: ${{ steps.popular-repos-web.outputs.webapp-url }}
67+
needs: build
68+
steps:
69+
- name: Azure login
70+
uses: azure/login@v1
71+
with:
72+
creds: ${{ secrets.AZURE_SUBSCRIPTION_SECRET }}
73+
74+
- name: Create deployment slot
75+
run: |
76+
az webapp deployment slot create --name popular-repos --resource-group pied-piper-inc --slot review-pr-${{ github.event.number }} --configuration-source popular-repos
77+
78+
- name: Deploy popular repos
79+
uses: azure/webapps-deploy@v2
80+
id: popular-repos-web
81+
with:
82+
app-name: 'popular-repos'
83+
images: '${{ secrets.AZURE_REGISTRY_NAME }}/popular-repos:${{ github.event.pull_request.head.sha }}'
84+
slot-name: review-pr-${{ github.event.number }}
85+
86+
deploy_to_staging:
87+
name: Deploy Staging
88+
if: github.event.ref == 'refs/heads/main'
89+
runs-on: ubuntu-latest
90+
environment:
91+
name: staging
92+
url: ${{ steps.popular-repos-web.outputs.webapp-url }}
93+
needs: build
94+
steps:
95+
- name: Azure login
96+
uses: azure/login@v1
97+
with:
98+
creds: ${{ secrets.AZURE_SUBSCRIPTION_SECRET }}
99+
100+
- name: Deploy popular repos
101+
uses: azure/webapps-deploy@v2
102+
id: popular-repos-web
103+
with:
104+
app-name: 'popular-repos'
105+
images: '${{ secrets.AZURE_REGISTRY_NAME }}/popular-repos:${{ github.sha }}'
106+
slot-name: staging
107+
108+
deploy_to_production:
109+
name: Deploy Production
110+
if: github.event.ref == 'refs/heads/main'
111+
runs-on: ubuntu-latest
112+
environment:
113+
name: production
114+
url: https://popular-repos.azurewebsites.net
115+
needs: deploy_to_staging
116+
steps:
117+
- name: Azure login
118+
uses: azure/login@v1
119+
with:
120+
creds: ${{ secrets.AZURE_SUBSCRIPTION_SECRET }}
121+
122+
- name: Swap staging to production
123+
run: |
124+
az webapp deployment slot swap --name popular-repos --resource-group pied-piper-inc --slot staging --target-slot production
125+

0 commit comments

Comments
 (0)