Skip to content

Commit eba1370

Browse files
author
Raffaele Marcello
committed
Refactor Azure Bicep deployment workflow to include environment selection and update container registry SKU
1 parent 191bd1a commit eba1370

File tree

2 files changed

+116
-2
lines changed

2 files changed

+116
-2
lines changed

.github/workflows/dotnet-deploy.yml

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
name: .NET CI
22

3+
env:
4+
registryName: cq5qj5cc3ob6mmpnpreg.azurecr.io
5+
repositoryName: techexcel/dotnetcoreapp
6+
dockerFolderPath: ./src/Application/src/RazorPagesTestSample
7+
tag: ${{github.run_number}}
8+
39
on:
410
push:
511
branches: [ main ]
@@ -18,10 +24,100 @@ jobs:
1824
- uses: actions/checkout@v3
1925
- name: Setup .NET
2026
uses: actions/setup-dotnet@v3
21-
27+
with:
28+
dotnet-version: 8.0
29+
2230
- name: Restore dependencies
2331
run: dotnet restore ./src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj
2432
- name: Build
2533
run: dotnet build --no-restore ./src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj
2634
- name: Test
27-
run: dotnet test --no-build --verbosity normal ./src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj
35+
run: dotnet test --no-build --verbosity normal ./src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj
36+
37+
dockerBuildPush:
38+
runs-on: ubuntu-latest
39+
needs: build
40+
41+
steps:
42+
- uses: actions/checkout@v3
43+
44+
- name: Docker Login
45+
# You may pin to the exact commit or the version.
46+
# uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
47+
uses: docker/[email protected]
48+
with:
49+
# Server address of Docker registry. If not set then will default to Docker Hub
50+
registry: ${{ secrets.ACR_LOGIN_SERVER }}
51+
# Username used to log against the Docker registry
52+
username: ${{ secrets.ACR_USERNAME }}
53+
# Password or personal access token used to log against the Docker registry
54+
password: ${{ secrets.ACR_PASSWORD }}
55+
# Log out from the Docker registry at the end of a job
56+
logout: true
57+
58+
- name: Docker Build
59+
run: docker build -t $registryName/$repositoryName:$tag --build-arg build_version=$tag $dockerFolderPath
60+
61+
- name: Docker Push
62+
run: docker push $registryName/$repositoryName:$tag
63+
64+
deploy-to-dev:
65+
66+
runs-on: ubuntu-latest
67+
needs: dockerBuildPush
68+
environment:
69+
name: dev
70+
url: https://cq5qj5cc3ob6m-dev.azurewebsites.net/
71+
72+
steps:
73+
- name: 'Login via Azure CLI'
74+
uses: azure/[email protected]
75+
with:
76+
creds: ${{ secrets.AZURE_CREDENTIALS }}
77+
78+
- uses: azure/webapps-deploy@v2
79+
with:
80+
app-name: 'cq5qj5cc3ob6m-dev'
81+
images: cq5qj5cc3ob6mmpnpreg.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
82+
83+
deploy-to-test:
84+
85+
runs-on: ubuntu-latest
86+
needs: deploy-to-dev
87+
environment:
88+
name: test
89+
url: https://cq5qj5cc3ob6m-test.azurewebsites.net/
90+
91+
steps:
92+
- uses: actions/checkout@v3
93+
94+
- name: 'Login via Azure CLI'
95+
uses: azure/[email protected]
96+
with:
97+
creds: ${{ secrets.AZURE_CREDENTIALS }}
98+
99+
- uses: azure/webapps-deploy@v2
100+
with:
101+
app-name: 'cq5qj5cc3ob6m-test'
102+
images: cq5qj5cc3ob6mmpnpreg.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
103+
104+
deploy-to-prod:
105+
106+
runs-on: ubuntu-latest
107+
needs: deploy-to-test
108+
environment:
109+
name: prod
110+
url: https://cq5qj5cc3ob6m-prod.azurewebsites.net/
111+
112+
steps:
113+
- uses: actions/checkout@v3
114+
115+
- name: 'Login via Azure CLI'
116+
uses: azure/[email protected]
117+
with:
118+
creds: ${{ secrets.AZURE_CREDENTIALS }}
119+
120+
- uses: azure/webapps-deploy@v2
121+
with:
122+
app-name: 'cq5qj5cc3ob6m-prod'
123+
images: cq5qj5cc3ob6mmpnpreg.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
2+
WORKDIR /app
3+
4+
# Copy csproj and restore as distinct layers
5+
COPY *.csproj ./
6+
RUN dotnet restore
7+
8+
# Copy everything else and build
9+
COPY . ./
10+
RUN dotnet publish -c Release -o out
11+
12+
# Build runtime image
13+
FROM mcr.microsoft.com/dotnet/aspnet:8.0
14+
WORKDIR /app
15+
COPY --from=build-env /app/out .
16+
# Default ASP.NET port changed with .NET 8.0
17+
ENV ASPNETCORE_HTTP_PORTS=80
18+
ENTRYPOINT ["dotnet", "RazorPagesTestSample.dll"]

0 commit comments

Comments
 (0)