Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit c25d4c4

Browse files
committed
Use buildkit secret mount support on dockerfile
1 parent 4a6fa1f commit c25d4c4

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build-env
77

88
ARG MS_NUGET_URL=https://nuget.pkg.github.com/microsoft/index.json
99
ARG MSGRAPH_NUGET_URL=https://nuget.pkg.github.com/microsoftgraph/index.json
10-
ARG NUGET_USER
11-
ARG NUGET_PASSWORD
1210

1311
WORKDIR /app
1412

1513
COPY ./src ./msgraph-cli/src
1614
COPY ./msgraph-cli-core ./msgraph-cli/msgraph-cli-core
1715
WORKDIR /app/msgraph-cli
1816

19-
RUN dotnet nuget add source ${MS_NUGET_URL} -n ms-gh -u ${NUGET_USER} -p ${NUGET_PASSWORD} --store-password-in-clear-text &&\
20-
dotnet nuget add source ${MSGRAPH_NUGET_URL} -n msgraph-gh -u ${NUGET_USER} -p ${NUGET_PASSWORD} --store-password-in-clear-text
17+
RUN --mount=type=secret,id=user,required=true --mount=type=secret,id=token,required=true \
18+
dotnet nuget add source ${MS_NUGET_URL} -n ms-gh -u $(cat /run/secrets/user) -p $(cat /run/secrets/token) --store-password-in-clear-text &&\
19+
dotnet nuget add source ${MSGRAPH_NUGET_URL} -n msgraph-gh -u $(cat /run/secrets/user) -p $(cat /run/secrets/token) --store-password-in-clear-text
2120

2221
RUN dotnet publish -p:PublishSingleFile=false -p:PublishReadyToRun=true -p:PublishReadyToRunShowWarnings=true ./src/msgraph-cli.csproj --configuration Release --no-self-contained --runtime linux-musl-x64 --output /app/output
2322

docker/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@ $ docker run -it --cap-add=IPC_LOCK --rm msgraph-cli sh
1717
> performs token encryption.
1818
1919
#### Building an image
20-
Set the `NUGET_USER` and `NUGET_TOKEN` environment variables to a token that has pull package access to the [microsoft](https://github.com/microsoft) and [microsoftgraph](https://github.com/microsoftgraph) GitHub organizations.
20+
Ensure you have a docker engine with API access [1.39+](https://docs.docker.com/engine/api/v1.39/) and BuildKit enabled.
21+
Create 2 files `nuget_user.txt` and `nuget_token.txt` and set their content to a username and a matching personal access token
22+
that has pull access to both the [microsoft](https://github.com/microsoft) and [microsoftgraph](https://github.com/microsoftgraph)
23+
GitHub organizations' package registries.
2124

2225
To build an image in windows powershell:
2326
```powershell
24-
$ docker build \\?\$(Get-Location) -f . -t msgraph-cli --build-arg NUGET_USER=$env:NUGET_USER --build-arg NUGET_PASSWORD=$env:NUGET_TOKEN
27+
$ docker build \\?\$(Get-Location) -f . -t msgraph-cli --secret id=user,src=./tmp/nuget_user.txt --secret id=token,src=./tmp/nuget_token.txt
2528
```
2629

2730
> The `\\?\$(Get-Location)` section of the command is used to get around the 260 character
2831
> limitation on windows systems that could cause issues when copying files to the docker
29-
> context. This issue impacts buildkit builds. For more information, check [this issue](https://github.com/moby/buildkit/issues/1366).
32+
> context. This issue impacts buildkit builds. For more information, check
33+
> [this issue](https://github.com/moby/buildkit/issues/1366).
3034
3135
To build an image in linux or WSL:
3236
```sh
33-
$ docker build -t msgraph-cli --build-arg NUGET_USER=$NUGET_USER --build-arg NUGET_PASSWORD=$NUGET_TOKEN .
37+
$ docker build -t msgraph-cli --secret id=user,src=./tmp/nuget_user.txt --secret id=token,src=./tmp/nuget_token.txt .
3438
```

0 commit comments

Comments
 (0)