diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index aa0c32c..9f07fd7 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -13,6 +13,8 @@ env:
SRC_PROJECT_PATH: '/webapp01/webapp01.csproj'
AZURE_WEBAPP_PACKAGE_PATH: './src' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '9.0.x' # set this to the dot net version to use
+ imageName: "webapp01"
+ tag: ${{ github.sha }}
jobs:
ci_build:
@@ -36,4 +38,5 @@ jobs:
dotnet restore ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}${{ env.SRC_PROJECT_PATH }}
dotnet build --configuration Release ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}${{ env.SRC_PROJECT_PATH }}
-
\ No newline at end of file
+ - name: Build the Docker image
+ run: docker build ./src/webapp01 --file ./src/webapp01/Dockerfile --tag ${{ env.imageName }}:${{ env.tag }}
diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml
index 6b6bba3..3cee7b1 100644
--- a/.github/workflows/cicd.yml
+++ b/.github/workflows/cicd.yml
@@ -52,6 +52,20 @@ jobs:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/webapp01/bin/publish'
+ - uses: azure/docker-login@v1
+ with:
+ login-server: crdevsecopscldev.azurecr.io
+ username: ${{ secrets.REGISTRY_USERNAME }}
+ password: ${{ secrets.REGISTRY_PASSWORD }}
+ - run: |
+ docker build ./src/webapp01 --file ./src/webapp01/Dockerfile -t crdevsecopscldev.azurecr.io/webapp01:${{ github.sha }}
+ docker push crdevsecopscldev.azurecr.io/webapp01:${{ github.sha }}
+
+ - uses: azure/webapps-deploy@v2
+ with:
+ app-name: ${{ env.AZURE_WEBAPP_NAME }}
+ images: 'crdevsecopscldev.azurecr.io/webapp01:${{ github.sha }}'
+
- name: logout
run: |
az logout
\ No newline at end of file
diff --git a/src/webapp01/.dockerignore b/src/webapp01/.dockerignore
new file mode 100644
index 0000000..fe1152b
--- /dev/null
+++ b/src/webapp01/.dockerignore
@@ -0,0 +1,30 @@
+**/.classpath
+**/.dockerignore
+**/.env
+**/.git
+**/.gitignore
+**/.project
+**/.settings
+**/.toolstarget
+**/.vs
+**/.vscode
+**/*.*proj.user
+**/*.dbmdl
+**/*.jfm
+**/azds.yaml
+**/bin
+**/charts
+**/docker-compose*
+**/Dockerfile*
+**/node_modules
+**/npm-debug.log
+**/obj
+**/secrets.dev.yaml
+**/values.dev.yaml
+LICENSE
+README.md
+!**/.gitignore
+!.git/HEAD
+!.git/config
+!.git/packed-refs
+!.git/refs/heads/**
\ No newline at end of file
diff --git a/src/webapp01/Dockerfile b/src/webapp01/Dockerfile
new file mode 100644
index 0000000..8f360a1
--- /dev/null
+++ b/src/webapp01/Dockerfile
@@ -0,0 +1,30 @@
+# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
+
+# This stage is used when running from VS in fast mode (Default for Debug configuration)
+FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
+USER $APP_UID
+WORKDIR /app
+EXPOSE 8080
+EXPOSE 8081
+
+
+# This stage is used to build the service project
+FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
+ARG BUILD_CONFIGURATION=Release
+WORKDIR /src
+COPY ["webapp01.csproj", "."]
+RUN dotnet restore "./webapp01.csproj"
+COPY . .
+WORKDIR "/src/."
+RUN dotnet build "./webapp01.csproj" -c $BUILD_CONFIGURATION -o /app/build
+
+# This stage is used to publish the service project to be copied to the final stage
+FROM build AS publish
+ARG BUILD_CONFIGURATION=Release
+RUN dotnet publish "./webapp01.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
+
+# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
+FROM base AS final
+WORKDIR /app
+COPY --from=publish /app/publish .
+ENTRYPOINT ["dotnet", "webapp01.dll"]
\ No newline at end of file
diff --git a/src/webapp01/Properties/launchSettings.json b/src/webapp01/Properties/launchSettings.json
index f24c911..2530cee 100644
--- a/src/webapp01/Properties/launchSettings.json
+++ b/src/webapp01/Properties/launchSettings.json
@@ -1,23 +1,34 @@
{
- "$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
- "dotnetRunMessages": true,
"launchBrowser": true,
- "applicationUrl": "http://localhost:5075",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
- }
+ },
+ "dotnetRunMessages": true,
+ "applicationUrl": "http://localhost:5075"
},
"https": {
"commandName": "Project",
- "dotnetRunMessages": true,
"launchBrowser": true,
- "applicationUrl": "https://localhost:7058;http://localhost:5075",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
- }
+ },
+ "dotnetRunMessages": true,
+ "applicationUrl": "https://localhost:7058;http://localhost:5075"
+ },
+ "Container (Dockerfile)": {
+ "commandName": "Docker",
+ "launchBrowser": true,
+ "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
+ "environmentVariables": {
+ "ASPNETCORE_HTTPS_PORTS": "8081",
+ "ASPNETCORE_HTTP_PORTS": "8080"
+ },
+ "publishAllPorts": true,
+ "useSSL": true
}
- }
-}
+ },
+ "$schema": "https://json.schemastore.org/launchsettings.json"
+}
\ No newline at end of file
diff --git a/src/webapp01/webapp01.csproj b/src/webapp01/webapp01.csproj
index 1acb179..54dfb41 100644
--- a/src/webapp01/webapp01.csproj
+++ b/src/webapp01/webapp01.csproj
@@ -4,11 +4,15 @@
net9.0
enable
enable
+ 7f0355f0-e3cb-4a1e-bf2d-0431db9b93f8
+ Linux
+ .
+