From e4e7e637c5c9a211033a8a20493267c2f5fb39f3 Mon Sep 17 00:00:00 2001 From: Roland Fieger Date: Tue, 28 Oct 2025 12:32:15 +0100 Subject: [PATCH] Added docker --- .gitea/workflows/develop.yml | 26 ++++++++++- .gitignore | 2 + SimplePackage/dockerfile | 45 +++++++++++++++++++ .../SimplePackage.AssemblyInfo.cs | 2 +- .../SimplePackage.AssemblyInfoInputs.cache | 2 +- 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 SimplePackage/dockerfile diff --git a/.gitea/workflows/develop.yml b/.gitea/workflows/develop.yml index 1f93881..333dfce 100644 --- a/.gitea/workflows/develop.yml +++ b/.gitea/workflows/develop.yml @@ -25,7 +25,7 @@ jobs: - name: Add Nuget Credentials # run: dotnet nuget update source gitea --username sxhundred --password ${{ secrets.READ_NUGET_PAT }} --store-password-in-clear-text --configfile nuget.config - run: dotnet nuget update source gitea --username sxhundred --password ${{ secrets.READ_NUGET_PAT }} --store-password-in-clear-text --configfile nuget.config + run: dotnet nuget update source gitea --username ${{ secrets.READ_NUGET_USER }} --password ${{ secrets.READ_NUGET_PAT }} --store-password-in-clear-text --configfile nuget.config - name: Install GitVersion @@ -53,4 +53,26 @@ jobs: path: SimplePackage/bin/Debug/*.*nupkg - name: Publish Develop SimplePackage - run: dotnet nuget push SimplePackage/bin/Debug/*.nupkg --api-key ${{ secrets.READ_NUGET_PAT }} --no-symbols \ No newline at end of file + run: dotnet nuget push SimplePackage/bin/Debug/*.nupkg --api-key ${{ secrets.READ_NUGET_PAT }} --no-symbols + + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: Address of your docker registry in gitea + username: ${{ secrets.READ_NUGET_USER + password: ${{ secrets.READ_NUGET_PAT + + + - name: Build Docker Image + run: | + docker build --build-arg BuildVersion=${{ env.GitVersion_SemVer }} \ + --build-arg PACKAGETEST_FEED_URL=http://192.168.2.83:3100/api/packages/sxhundred/nuget/index.json \ + --build-arg READ_NUGET_USER=${{ secrets.READ_NUGET_USER }} \ + --build-arg READ_NUGET_PAT=${{ secrets.READ_NUGET_PAT }} \ + -t myimage:latest . + + - name: Push Docker Image + run: | + echo ${{ secrets.READ_NUGET_PAT }} | docker login -u ${{ secrets.READ_NUGET_USER }} --password-stdin + docker tag myimage:latest ${{ secrets.READ_NUGET_USER }}/myimage:develop + docker push ${{ secrets.READ_NUGET_USER }}/myimage:develop \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8c2b884..13e0920 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ # Built Visual Studio Code Extensions *.vsix +SimplePackage/obj/Debug/netstandard2.1/SimplePackage.AssemblyInfo.cs +SimplePackage/obj/Debug/netstandard2.1/SimplePackage.AssemblyInfoInputs.cache diff --git a/SimplePackage/dockerfile b/SimplePackage/dockerfile new file mode 100644 index 0000000..ab5eee2 --- /dev/null +++ b/SimplePackage/dockerfile @@ -0,0 +1,45 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build +ARG BuildVersion +ARG PACKAGETEST_FEED_URL +ARG READ_NUGET_PAT +ARG READ_NUGET_USER +ARG BuildUniqueID +LABEL build.uniqueid="${BuildUniqueID:-1}" +RUN wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash +# Optional: Sometimes the http client hangs because of a .NEt issue. Setting this in dockerfile helps +ENV DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0 +# Environment variable to enable seesion token cache. More on this here: https://github.com/Microsoft/artifacts-credprovider#help +ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true + +# Environment variable for adding endpoint credentials. More on this here: https://github.com/Microsoft/artifacts-credprovider#help +# Add "FEED_URL" AND "PAT" using --build-arg in docker build step. "endpointCredentials" field is an array, you can add multiple endpoint configurations. +# Make sure that you *do not* hard code the "PAT" here. That is a sensitive information and must not be checked in. +# ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS {\"endpointCredentials\": [{\"endpoint\":\"${FEED_URL}\", \"username\":\"ArtifactsDocker\", \"password\":\"${PAT}\"}, {\"endpoint\":\"${GITHUB_FEED_URL}\", \"username\":\"${GITHUB_USER}\", \"password\":\"${GITHUB_PAT}\"}]} +# RUN dotnet nuget add source ${FEED_URL} --name "myfeed" --username "whatever" --password="${PAT}" --store-password-in-clear-text --valid-authentication-types "basic" +RUN dotnet nuget add source ${PACKAGETEST_FEED_URL} --name "myfeed_gitea" --username "${READ_NUGET_USER}}" --password="${READ_NUGET_PAT}}" --store-password-in-clear-text --valid-authentication-types "basic" + +WORKDIR /src +COPY . . +RUN dotnet restore "SimplePackage/SimplePackage.csproj" --runtime linux-x64 +WORKDIR "/SimplePackage" +RUN dotnet build "SimplePackage.csproj" --no-restore -c Release -o /app /property:Version=${BuildVersion:-1.0.0-dev} --self-contained --runtime linux-x64 + +FROM build AS publish +ENV TZ=Europe/Berlin +ENV LANG de_DE.UTF-8 +ENV LANGUAGE de_DE:de +ENV LC_ALL de_DE.UTF-8 +ARG BuildVersion +RUN dotnet publish "SimplePackage.csproj" --no-restore -c Release -o /app /property:Version=${BuildVersion:-1.0.0-dev} --self-contained --runtime linux-x64 + +FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-jammy-chiseled-extra AS final +ENV TZ=Europe/Berlin +ENV LANG de_DE.UTF-8 +ENV LANGUAGE de_DE:de +ENV LC_ALL de_DE.UTF-8 +ENV ASPNETCORE_HTTP_PORTS=8080 +ENV ASPNETCORE_URLS=http://*:8080 +EXPOSE 8080 +WORKDIR /app +COPY --from=publish /app . +ENTRYPOINT ["./SimplePackage"] \ No newline at end of file diff --git a/SimplePackage/obj/Debug/netstandard2.1/SimplePackage.AssemblyInfo.cs b/SimplePackage/obj/Debug/netstandard2.1/SimplePackage.AssemblyInfo.cs index d6f90d7..56dc3ea 100644 --- a/SimplePackage/obj/Debug/netstandard2.1/SimplePackage.AssemblyInfo.cs +++ b/SimplePackage/obj/Debug/netstandard2.1/SimplePackage.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("SimplePackage")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f16bbb021a5935fe13422389a641345c09e66992")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b35ec0902bf235cd43e9eb57ed261d1efc9bf3c8")] [assembly: System.Reflection.AssemblyProductAttribute("SimplePackage")] [assembly: System.Reflection.AssemblyTitleAttribute("SimplePackage")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/SimplePackage/obj/Debug/netstandard2.1/SimplePackage.AssemblyInfoInputs.cache b/SimplePackage/obj/Debug/netstandard2.1/SimplePackage.AssemblyInfoInputs.cache index 9215574..f62077c 100644 --- a/SimplePackage/obj/Debug/netstandard2.1/SimplePackage.AssemblyInfoInputs.cache +++ b/SimplePackage/obj/Debug/netstandard2.1/SimplePackage.AssemblyInfoInputs.cache @@ -1 +1 @@ -90d52f61004d6770342ebc33c9b6a0b973947a35df2b7ee0b4481d085abc3e49 +e57fc372a4954336783480088d449e920ca66a75bdc78bf1b7bbd9100da8c525