Skip to content

Commit b941b69

Browse files
Update README.md
1 parent a04dfb3 commit b941b69

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

README.md

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ Although I use Telerik's NuGet server because I have a license, these demos are
4545
| **Kendo Angular** | [![Build Angular](https://github.com/LanceMcCarthy/DevOpsExamples/actions/workflows/main_build-angular.yml/badge.svg)](https://github.com/LanceMcCarthy/DevOpsExamples/actions/workflows/main_build-angular.yml) | [![Build Status](https://dev.azure.com/lance/DevOps%20Examples/_apis/build/status%2FLanceMcCarthy.DevOpsExamples?branchName=main&jobName=BuildAngularAppWithVariables)](https://dev.azure.com/lance/DevOps%20Examples/_build/latest?definitionId=45&branchName=main) | [![Build status](https://gitlab.com/LanceMcCarthy/DevOpsExamples/badges/main/pipeline.svg)](https://gitlab.com/LanceMcCarthy/DevOpsExamples) |
4646
| **ASP.NET AJAX** (`net48`) | [![Build AJAX Application](https://github.com/LanceMcCarthy/DevOpsExamples/actions/workflows/main_build-ajax.yml/badge.svg)](https://github.com/LanceMcCarthy/DevOpsExamples/actions/workflows/main_build-ajax.yml) | [![Build Status](https://dev.azure.com/lance/DevOps%20Examples/_apis/build/status%2FLanceMcCarthy.DevOpsExamples?branchName=main&jobName=BuildAjaxApp)](https://dev.azure.com/lance/DevOps%20Examples/_build/latest?definitionId=45&branchName=main) | [![Build status](https://gitlab.com/LanceMcCarthy/DevOpsExamples/badges/main/pipeline.svg)](https://gitlab.com/LanceMcCarthy/DevOpsExamples) |
4747

48-
4948
### Bonus Notes
5049

5150
- Docker and DockerHub integration:
@@ -93,10 +92,10 @@ That mean you must also have the secrets in your **Settings** > **Secrets** list
9392
You could also dynamically update the credentials of a Package Source defined in your nuget.config file This is a good option when you do not want to use a `packageSourceCredentials` section that uses environment variables.
9493

9594
```powershell
96-
# Updates a source named 'Telerik' in the nuget.config
97-
dotnet nuget update source "Telerik" -s "https://nuget.telerik.com/v3/index.json" --configfile "src/nuget.config" -u '${{secrets.MyTelerikEmail}}' -p '${{secrets.MyTelerikPassword}}' --store-password-in-clear-text
95+
# Setting credentials for the 'Telerik_v3_Feed' defined in the nuget.config file.
96+
dotnet nuget update source "Telerik_v3_Feed" -s "https://nuget.telerik.com/v3/index.json" -u '${{secrets.MyTelerikEmail}}' -p '${{secrets.MyTelerikPassword}}' --configfile "src/nuget.config" --store-password-in-clear-text
9897
```
99-
That command will look through the nuget.config for a package source with the key `Telerik` and then add/update the credentials for that source.
98+
That command will look through the nuget.config for a package source with the key `Telerik_v3_Feed` and then add/update the credentials for that source.
10099

101100
#### Option 2 - Add a new package source
102101

@@ -115,47 +114,54 @@ You can use the same approach in the previous section. Everything is exactly the
115114
Please visit the [Announcing NuGet Keys](https://www.telerik.com/blogs/announcing-nuget-keys) blog post for more details how ot create the key and how to use it.
116115

117116
```powershell
118-
dotnet nuget update source "Telerik" --source "https://nuget.telerik.com/v3/index.json" --configfile "src/nuget.config" --username 'api-key' --password '${{ secrets.MyNuGetKey }}' --store-password-in-clear-text
117+
dotnet nuget update source "Telerik_v3_Feed" -s "https://nuget.telerik.com/v3/index.json" -u 'api-key' -p '${{secrets.MyNuGetKey}}' --configfile "src/nuget.config" --store-password-in-clear-text
119118
```
120119

121120
> [!CAUTION]
122-
> Protect your key by storing it in a GitHub Secret, then use the secret's varible name in the command
121+
> Protect your key by storing it in a GitHub Secret, then use the secret's ID in the command.
123122
124123
### Dockerfile: Using Secrets
125124

126125
When using a Dockerfile to build a .NET project that uses the Telerik NuGet server, you'll need a safe and secure way to handle your NuGet crednetials and your Telerik License Key. This can be done my mounting a Docker secret.
127126

128-
In your GitHub Actions workflow, you can define and set docker secrets in the docker build step. Take a look at the following example, we using GitHub secrest to set two docker secrets `telerik-nuget-key=${{secrets.MY_NUGET_KEY}}` and `telerik-license-key=${{secrets.MY_TELERIK_LICENSE_KEY}}`.
127+
In your GitHub Actions workflow, you can define and set docker secrets in the docker build step. In the following example, notice how we are setting two docker secrets (`nuget-sec` and `license-sec`) using the values from GitHub secrets.
129128

130129
```yaml
131130
- uses: docker/build-push-action@v3
132131
with:
133132
secrets: |
134-
telerik-nuget-key=${{secrets.MY_NUGET_KEY}}
135-
telerik-license-key=${{secrets.MY_TELERIK_LICENSE_KEY}}
133+
nuget-sec=${{secrets.MY_NUGET_KEY}}
134+
license-sec=${{secrets.MY_TELERIK_LICENSE_KEY}}
136135
```
137136
138-
Now, inside the Dockerfile's `build` stage, you can mount and use those secrets. See Stage 2 in the following example:
137+
Now, inside the Dockerfile, you can mount and use those secrets. See Stage 2 in the following example:
139138
140139
```Dockerfile
141140
### STAGE 1 ###
142-
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
141+
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
143142
WORKDIR /app
144143

145144
### STAGE 2 ###
146-
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
147-
WORKDIR /src/MyApp
145+
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
146+
WORKDIR /src
148147
COPY . .
149-
# 1. Mount the ecret and use it to add the Telerik server as a package source
150-
RUN --mount=type=secret,id=telerik-nuget-key \
151-
dotnet nuget add source 'https://nuget.telerik.com/v3/index.json' -n "TelerikNuGetServer" -u "api-key" -p $(cat /run/secrets/telerik-nuget-key) --store-password-in-clear-text
152-
# 2. Restore NuGet packages
153-
RUN dotnet restore "MyBlazorApp.csproj"
154-
# 3. Mount the "telerik-license-key" secret as an env var and build the project
155-
RUN --mount=type=secret,id=telerik-license-key \
156-
TELERIK_LICENSE="$(cat /run/secrets/telerik-license-key)" \
157-
dotnet publish "MyBlazorApp.csproj" -o /app/publish /p:UseAppHost=false --self-contained false
158-
148+
# STEP 1. Mount the 'nuget-sec' secret, then:
149+
# a. add the Telerik package source
150+
# b. restore packages
151+
RUN --mount=type=secret,id=nuget-sec,required \
152+
dotnet nuget add source 'https://nuget.telerik.com/v3/index.json' -n "Telerik_v3_Feed" -u "api-key" -p "$(cat /run/secrets/nuget-sec)" --store-password-in-clear-text \
153+
&& \
154+
dotnet restore "MyBlazorApp.csproj"
155+
# STEP 2. Mount the "license-sec" secret, then:
156+
# a. create the license file
157+
# b. build the project
158+
# c. delete the file so you don't distribute it in your image (important!)
159+
RUN --mount=type=secret,id=license-key,required \
160+
mkdir -p ~/.telerik && echo "$(cat /run/secrets/license-sec)" > ~/.telerik/telerik-license.txt \
161+
&& \
162+
dotnet publish "Researcher.Web/Researcher.Web.csproj" -o /app/publish /p:UseAppHost=false --no-restore --self-contained false \
163+
&& \
164+
rm -rf ~/.telerik
159165

160166
### STAGE 3 ###
161167
# Build final from base, but copy ONLY THE PUBLISH ARTIFACTS from stage 2
@@ -166,7 +172,7 @@ ENTRYPOINT ["dotnet", "MyBlazorApp.dll"]
166172
```
167173

168174
> [!CAUTION]
169-
> Only set these sensitive values in the build stage or you risk leaking secrets in the final image. Please [visit the complete Dockerfile](https://github.com/LanceMcCarthy/DevOpsExamples/blob/main/src/AspNetCore/MyAspNetCoreApp/Dockerfile) and [the workflow](https://github.com/LanceMcCarthy/DevOpsExamples/blob/main/.github/workflows/main_build-aspnetcore.yml).
175+
> Pay attention to whether or not you are including any secrets in your final image. You can run your container to explore the files (and env vars in Exec) to make sure.
170176
171177
### Telerik License Approaches
172178

@@ -177,7 +183,6 @@ Depending on how you're building our code, there are several ways to introduce t
177183
- [In a YAML Pipeline](https://github.com/LanceMcCarthy/DevOpsExamples?tab=readme-ov-file#yaml-pipeline)
178184
- [In a Classic Pipeline](https://github.com/LanceMcCarthy/DevOpsExamples?tab=readme-ov-file#classic-pipeline)
179185

180-
181186
#### Approach 1 - Using a Variable
182187

183188
This is by far the easiest and safest way. You can use a secret (GitHub Action secret or AzDO Variable secret) and set the `TELERIK_LICENSE` environment variable before the project is compiled.

0 commit comments

Comments
 (0)