1+ # To get around the bug in https://github.com/moby/buildkit/issues/1366 on windows hosts, you can either:
2+ # 1. Enable long file path support in windows
3+ # 2. Use the \\?\ prefix when specifying the path in the docker build command. e.g.
4+ # docker build \\?\C:\path -f .\Dockerfile
5+ # See https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
6+ FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build-env
7+
8+ ARG MS_NUGET_URL=https://nuget.pkg.github.com/microsoft/index.json
9+ ARG MSGRAPH_NUGET_URL=https://nuget.pkg.github.com/microsoftgraph/index.json
10+
11+ WORKDIR /app
12+
13+ COPY ./src ./msgraph-cli/src
14+ COPY ./msgraph-cli-core ./msgraph-cli/msgraph-cli-core
15+ WORKDIR /app/msgraph-cli
16+
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
20+
21+ 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
22+
23+ FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine as runtime
24+
25+ # Change this password by providing a different value when running the container
26+ ENV KEYRING_PASSWORD="password"
27+
28+ RUN apk add --no-cache libsecret dbus gnome-keyring libcap &&\
29+ dbus-uuidgen > /var/lib/dbus/machine-id &&\
30+ setcap cap_ipc_lock=+ep $(which gnome-keyring-daemon)
31+
32+ RUN addgroup mgc &&\
33+ adduser -D -G mgc -h /app mgc
34+
35+ WORKDIR /app
36+
37+ COPY --from=build-env /app/output ./dist
38+
39+ RUN ln -s /app/dist/mgc /usr/bin/mgc
40+
41+ USER mgc
42+
43+ COPY --chown=mgc:mgc ./docker/* ./dist/
44+
45+ RUN mkdir -p /app/.mgc /app/.local/share/.IdentityService /app/.local/share/keyrings &&\
46+ chmod +x /app/dist/init.sh
47+
48+ VOLUME [ "/app/.mgc" , "/app/.local/share/.IdentityService" , "/app/.local/share/keyrings" ]
49+
50+ ENTRYPOINT ["./dist/init.sh" ]
51+
52+ LABEL description="# Welcome to the Microsoft Graph CLI \
53+ [Source dockerfile](https://github.com/microsoftgraph/msgraph-cli/blob/main/Dockerfile)"
0 commit comments