Skip to content

Commit c646404

Browse files
committed
docker deploy
1 parent 3d26a72 commit c646404

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed

.github/workflows/dotnet-deploy-3.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: .NET CI
2+
3+
env:
4+
registryName: pgtechexcelteam03.azurecr.io
5+
repositoryName: techexcel/dotnetcoreapp
6+
dockerFolderPath: ./src/Application/src/RazorPagesTestSample
7+
my_prefix: pgtechexcelteam03
8+
my_registry_name: pgtechexcelteam03
9+
tag: ${{github.run_number}}
10+
11+
on:
12+
push:
13+
branches: [ main, ci-cd ]
14+
paths: src/Application/**
15+
pull_request:
16+
branches: [ main, ci-cd ]
17+
paths: src/Application/**
18+
# Allows you to run this workflow manually from the Actions tab
19+
workflow_dispatch:
20+
jobs:
21+
build:
22+
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@v3
27+
- name: Setup .NET
28+
uses: actions/setup-dotnet@v3
29+
with:
30+
dotnet-version: 8.0
31+
32+
- name: Restore dependencies
33+
run: dotnet restore ./src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj
34+
- name: Build
35+
run: dotnet build --no-restore ./src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj
36+
- name: Test
37+
run: dotnet test --no-build --verbosity normal ./src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj
38+
39+
dockerBuildPush:
40+
runs-on: ubuntu-latest
41+
needs: build
42+
43+
steps:
44+
- uses: actions/checkout@v3
45+
46+
- name: Docker Login
47+
# You may pin to the exact commit or the version.
48+
# uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
49+
uses: docker/[email protected]
50+
with:
51+
# Server address of Docker registry. If not set then will default to Docker Hub
52+
registry: ${{ secrets.ACR_LOGIN_SERVER }}
53+
# Username used to log against the Docker registry
54+
username: ${{ secrets.ACR_USERNAME }}
55+
# Password or personal access token used to log against the Docker registry
56+
password: ${{ secrets.ACR_PASSWORD }}
57+
# Log out from the Docker registry at the end of a job
58+
logout: true
59+
60+
- name: Docker Build
61+
run: docker build -t $registryName/$repositoryName:$tag --build-arg build_version=$tag $dockerFolderPath
62+
63+
- name: Docker Push
64+
run: docker push $registryName/$repositoryName:$tag
65+
66+
deploy-to-dev:
67+
68+
runs-on: ubuntu-latest
69+
needs: dockerBuildPush
70+
environment:
71+
name: dev
72+
url: https://${my_prefix}-dev.azurewebsites.net/
73+
74+
steps:
75+
- name: 'Login via Azure CLI'
76+
uses: azure/[email protected]
77+
with:
78+
creds: ${{ secrets.AZURE_CREDENTIALS }}
79+
80+
- uses: azure/webapps-deploy@v2
81+
with:
82+
app-name: '{my_prefix}-dev'
83+
images: ${my_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
84+
85+
deploy-to-test:
86+
87+
runs-on: ubuntu-latest
88+
needs: deploy-to-dev
89+
environment:
90+
name: test
91+
url: https://${my_prefix}-test.azurewebsites.net/
92+
93+
steps:
94+
- uses: actions/checkout@v3
95+
96+
- name: 'Login via Azure CLI'
97+
uses: azure/[email protected]
98+
with:
99+
creds: ${{ secrets.AZURE_CREDENTIALS }}
100+
101+
- uses: azure/webapps-deploy@v2
102+
with:
103+
app-name: '${my_prefix}-test'
104+
images: ${my_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
105+
106+
deploy-to-prod:
107+
108+
runs-on: ubuntu-latest
109+
needs: deploy-to-test
110+
environment:
111+
name: prod
112+
url: https://${my_prefix}-prod.azurewebsites.net/
113+
114+
steps:
115+
- uses: actions/checkout@v3
116+
117+
- name: 'Login via Azure CLI'
118+
uses: azure/[email protected]
119+
with:
120+
creds: ${{ secrets.AZURE_CREDENTIALS }}
121+
122+
- uses: azure/webapps-deploy@v2
123+
with:
124+
app-name: '{your_prefix}-prod'
125+
images: ${my_registry_name}.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)