From 795d4606d78a155154a8228e86aaa1a85cca1cba Mon Sep 17 00:00:00 2001 From: Arne Moerman Date: Sun, 3 May 2026 10:34:46 +0200 Subject: [PATCH] Add Docker support and CI workflow for build and push Added .dockerignore and Dockerfile for containerization. Introduced GitHub Actions workflow to build and push images to Gitea registry. Updated project file with Docker properties and Azure Containers Tools package. Enhanced launchSettings.json with Docker profile and improved environment settings. --- .dockerignore | 30 ++++++++++ .gitea/workflows/build-and-push.yml | 36 ++++++++++++ For Real Consulting/Dockerfile | 17 ++++++ .../For Real Consulting.csproj | 3 + .../Properties/launchSettings.json | 55 +++++++++++-------- 5 files changed, 119 insertions(+), 22 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/build-and-push.yml create mode 100644 For Real Consulting/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/.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/.gitea/workflows/build-and-push.yml b/.gitea/workflows/build-and-push.yml new file mode 100644 index 0000000..349f13f --- /dev/null +++ b/.gitea/workflows/build-and-push.yml @@ -0,0 +1,36 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + +jobs: + build-and-push: + runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:act-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Generate datetime tag + id: vars + run: echo "tag=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT + + - name: Log in to Gitea Registry + uses: docker/login-action@v3 + with: + registry: git.arnemoerman.be + username: arne + password: ${{ secrets.PAT_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: ./For Real Consulting + file: ./For Real Consulting/Dockerfile + push: true + tags: | + git.arnemoerman.be/arne/for-real-consulting:latest + git.arnemoerman.be/arne/for-real-consulting:${{ steps.vars.outputs.tag }} diff --git a/For Real Consulting/Dockerfile b/For Real Consulting/Dockerfile new file mode 100644 index 0000000..5ae2ace --- /dev/null +++ b/For Real Consulting/Dockerfile @@ -0,0 +1,17 @@ +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build +WORKDIR /src + +COPY ["For Real Consulting/For Real Consulting.csproj", "For Real Consulting/"] +RUN dotnet restore "For Real Consulting/For Real Consulting.csproj" + +COPY . . +WORKDIR "/src/For Real Consulting" +RUN dotnet publish "For Real Consulting.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final +WORKDIR /app +COPY --from=build /app/publish . + +EXPOSE 8080 +ENV ASPNETCORE_URLS=http://+:8080 +ENTRYPOINT ["dotnet", "For_Real_Consulting.dll"] diff --git a/For Real Consulting/For Real Consulting/For Real Consulting.csproj b/For Real Consulting/For Real Consulting/For Real Consulting.csproj index 5320cf9..b6f9b0d 100644 --- a/For Real Consulting/For Real Consulting/For Real Consulting.csproj +++ b/For Real Consulting/For Real Consulting/For Real Consulting.csproj @@ -8,6 +8,8 @@ For_Real_Consulting $(AssemblyName.Replace(' ', '_')) true + Linux + .. @@ -17,6 +19,7 @@ + diff --git a/For Real Consulting/For Real Consulting/Properties/launchSettings.json b/For Real Consulting/For Real Consulting/Properties/launchSettings.json index 686c6bb..a0d04d6 100644 --- a/For Real Consulting/For Real Consulting/Properties/launchSettings.json +++ b/For Real Consulting/For Real Consulting/Properties/launchSettings.json @@ -1,25 +1,36 @@ { - "$schema": "https://json.schemastore.org/launchsettings.json", - "profiles": { - "http": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "http://for-real-consulting.dev.localhost:5211", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } + "profiles": { + "http": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" }, - "https": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "https://for-real-consulting.dev.localhost:7106;http://for-real-consulting.dev.localhost:5211", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } + "dotnetRunMessages": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "applicationUrl": "http://for-real-consulting.dev.localhost:5211" + }, + "https": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "applicationUrl": "https://for-real-consulting.dev.localhost:7106;http://for-real-consulting.dev.localhost:5211" + }, + "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