Skip to content

Commit 44bb936

Browse files
Joshua-Lester3j0shualeCopilotKeboo
authored
Add CICD Pipeline + Rev to .NET 10 (#3)
* update to net 10 + initial CI pipeline * adjust pipeline name * initial work on deploy job * Refactor CI/CD workflow for improved Docker image handling and Azure deployment * Update .github/workflows/Build-Test-And-Deploy.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove errant space * Update global.json Co-authored-by: Kevin B <Keboo@users.noreply.github.com> * remove azure pipelines workflows --------- Co-authored-by: Joshua Lester <jlester3@ewu.edu> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Kevin B <Keboo@users.noreply.github.com>
1 parent bca02bf commit 44bb936

File tree

12 files changed

+166
-370
lines changed

12 files changed

+166
-370
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: Build, Test, and Deploy Try .NET API
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
workflow_dispatch:
9+
10+
permissions:
11+
id-token: write
12+
contents: read
13+
14+
jobs:
15+
build-and-test:
16+
runs-on: ubuntu-latest
17+
environment: "BuildAndUploadImage"
18+
19+
steps:
20+
- uses: actions/checkout@v6
21+
22+
- name: Set up .NET
23+
uses: actions/setup-dotnet@v5
24+
with:
25+
global-json-file: global.json
26+
27+
- name: Set up dependency caching for faster builds
28+
uses: actions/cache@v5
29+
id: nuget-cache
30+
with:
31+
path: |
32+
~/.nuget/packages
33+
${{ github.workspace }}/**/obj/project.assets.json
34+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
35+
restore-keys: |
36+
${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
37+
${{ runner.os }}-nuget-
38+
39+
- name: Restore with dotnet
40+
run: dotnet restore
41+
42+
- name: Build with dotnet
43+
run: dotnet build -p:ContinuousIntegrationBuild=True -p:ReleaseDateAttribute=True --configuration Release --no-restore
44+
45+
- name: Run .NET Tests
46+
run: dotnet test --no-build --configuration Release
47+
48+
- name: Set up Docker Buildx
49+
uses: docker/setup-buildx-action@v3
50+
51+
# Build but no push with a PR
52+
- name: Docker build (no push)
53+
if: github.event_name == 'pull_request' || github.event_name == 'merge_group'
54+
uses: docker/build-push-action@v6
55+
with:
56+
push: false
57+
tags: temp-pr-validation
58+
file: ./Dockerfile
59+
60+
- name: Build Container Image
61+
if: github.event_name != 'pull_request_target' && github.event_name != 'pull_request'
62+
uses: docker/build-push-action@v6
63+
with:
64+
tags: ${{ vars.DEVCONTAINER_REGISTRY }}/try:${{ github.sha }},${{ vars.DEVCONTAINER_REGISTRY }}/try:latest
65+
file: ./Dockerfile
66+
context: .
67+
outputs: type=docker,dest=${{ github.workspace }}/tryimage.tar
68+
cache-from: type=gha
69+
cache-to: type=gha,mode=max
70+
71+
- name: Upload artifact
72+
if: github.event_name != 'pull_request_target' && github.event_name != 'pull_request'
73+
uses: actions/upload-artifact@v6
74+
with:
75+
name: tryimage
76+
path: ${{ github.workspace }}/tryimage.tar
77+
78+
deploy-development:
79+
if: github.event_name != 'pull_request_target' && github.event_name != 'pull_request'
80+
runs-on: ubuntu-latest
81+
needs: build-and-test
82+
environment:
83+
name: "Development"
84+
85+
steps:
86+
- name: Azure Login
87+
uses: azure/login@v2
88+
with:
89+
client-id: ${{ secrets.ESSENTIALCSHARPDEV_CLIENT_ID }}
90+
tenant-id: ${{ secrets.ESSENTIALCSHARP_TENANT_ID }}
91+
subscription-id: ${{ secrets.ESSENTIALCSHARP_SUBSCRIPTION_ID }}
92+
93+
- name: Download artifact
94+
uses: actions/download-artifact@v7
95+
with:
96+
name: tryimage
97+
path: ${{ github.workspace }}
98+
99+
- name: Load image
100+
run: |
101+
docker load --input ${{ github.workspace }}/tryimage.tar
102+
docker image ls -a
103+
104+
- name: Log in to container registry
105+
uses: azure/CLI@v2
106+
env:
107+
REGISTRY_URL: ${{ vars.DEVCONTAINER_REGISTRY }}
108+
with:
109+
inlineScript: |
110+
REGISTRY_NAME=${REGISTRY_URL%.azurecr.io}
111+
az acr login --name $REGISTRY_NAME
112+
113+
- name: Push Image to Container Registry
114+
env:
115+
REGISTRY_URL: ${{ vars.DEVCONTAINER_REGISTRY }}
116+
run: docker push --all-tags $REGISTRY_URL/try
117+
118+
- name: Create and Deploy to Container App
119+
uses: azure/CLI@v2
120+
env:
121+
CONTAINER_APP_NAME: ${{ vars.CONTAINER_APP_NAME }}
122+
RESOURCEGROUP: ${{ vars.RESOURCEGROUP }}
123+
CONTAINER_APP_ENVIRONMENT: ${{ vars.CONTAINER_APP_ENVIRONMENT }}
124+
REGISTRY_URL: ${{ vars.DEVCONTAINER_REGISTRY }}
125+
SUBSCRIPTION_ID: ${{ secrets.ESSENTIALCSHARP_SUBSCRIPTION_ID }}
126+
MANAGED_IDENTITY_ID: ${{ secrets.MANAGED_IDENTITY_ID }}
127+
with:
128+
inlineScript: |
129+
az config set extension.use_dynamic_install=yes_without_prompt
130+
az extension add --name containerapp --upgrade
131+
az containerapp up \
132+
-n $CONTAINER_APP_NAME \
133+
-g $RESOURCEGROUP \
134+
--image $REGISTRY_URL/try:${{ github.sha }} \
135+
--environment $CONTAINER_APP_ENVIRONMENT \
136+
--registry-server $REGISTRY_URL \
137+
--ingress external \
138+
--target-port 8080 \
139+
--user-assigned /subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCEGROUP/providers/Microsoft.ManagedIdentity/userAssignedIdentities/$MANAGED_IDENTITY_ID \
140+
--registry-identity /subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCEGROUP/providers/Microsoft.ManagedIdentity/userAssignedIdentities/$MANAGED_IDENTITY_ID
141+
142+
143+
- name: Logout of Azure CLI
144+
if: always()
145+
uses: azure/CLI@v2
146+
with:
147+
inlineScript: |
148+
az logout
149+
az cache purge
150+
az account clear

Directory.Packages.props

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
<PackageVersion Include="Assent" Version="2.3.2" />
88
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
99
<PackageVersion Include="AwesomeAssertions" Version="8.1.0" />
10-
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.1" />
11-
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.1" />
12-
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.1" />
13-
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.1" />
10+
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.0" />
11+
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="10.0.0" />
12+
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.0" />
13+
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0" />
1414
<PackageVersion Include="Microsoft.DotNet.Interactive.CSharpProject" Version="1.0.0-beta.25059.3" />
1515
<PackageVersion Include="Microsoft.Playwright" Version="1.42.0" />
1616
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
@@ -24,7 +24,7 @@
2424
<PackageVersion Include="Serilog.Sinks.RollingFileAlternate" Version="2.0.9" />
2525
<PackageVersion Include="Serilog" Version="3.1.1" />
2626
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
27-
<PackageVersion Include="System.Drawing.Common" Version="9.0.1" />
27+
<PackageVersion Include="System.Drawing.Common" Version="10.0.0" />
2828
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
2929
<PackageVersion Include="System.Reactive" Version="6.0.0" />
3030
<PackageVersion Include="System.Security.Cryptography.X509Certificates" Version="4.3.2" />

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:9.0-azurelinux3.0 AS build-env
1+
FROM mcr.microsoft.com/dotnet/sdk:10.0-azurelinux3.0 AS build-env
22
WORKDIR /App
33

44
# Copy everything
@@ -24,7 +24,7 @@ RUN dotnet restore --configfile /App/NuGet.config /App/TryDotNet.sln
2424
RUN dotnet publish -c Release -o out /App/src/Microsoft.TryDotNet
2525

2626
# Build runtime image
27-
FROM mcr.microsoft.com/dotnet/sdk:9.0-azurelinux3.0
27+
FROM mcr.microsoft.com/dotnet/sdk:10.0-azurelinux3.0
2828
ARG TRY_DOT_NET_BUILD_ID
2929
WORKDIR /App
3030

azure-pipelines-CI.yml

Lines changed: 0 additions & 191 deletions
This file was deleted.

0 commit comments

Comments
 (0)