왜커를 구축 손에서 사용$VSS_NUGET_EXTERNAL_FEED_ENDPOINTS?
내가 사용하여 이 문서 (spefically 예제 2 사용하는 Buildkit 및 커를 구축 비밀)하는 데 도움이 채워 나가능. 프로세스는:
- 통과하는 동안 PAT
docker build
, - 산 PAT 으로,비밀
- 수출케이 JSON 문자열을 사용하여 비밀(via
cat /pat
용)ENV 고- ^^^위 JSON 손상^^^
- 를 사용하여 환경변수를 호출하 NuGet 개인을 먹기 전에
- 기
dotnet restore
요청을 합니다.
Bash 명령은 질문입니다:
RUN --mount=type=secret,id=pat,dst=/pat export VSS_NUGET_EXTERNAL_FEED_ENDPOINTS="{\"endpointCredentials\": [{\"endpoint\":\"https://<my private feed URL>/nuget/v3/index.json\", \"username\":\"docker\", \"password\":\"`cat /pat`\"}]}" && \
echo $VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
출력 echo 명령어(통행의 끝에 팻은 후 추가 JSON 닫는 중괄호):
{"endpointCredentials": [{"endpoint":"https://<my private feed URL>/nuget/v3/index.json", "username":"docker", "password":"qwak...jiq5"}]}vtzkzv4a
When I 명령을 실행에 bash(Windows 하위 시스템을 위한 리눅스)그림:
~ echo "my-pat-token" >> /pat
~ export MY_ENV_VAR="{\"endpointCredentials\": [{\"endpoint\":\"https://<URL of private feed>/nuget/v3/index.json\", \"username\":\"build\", \"password\":\"`cat /pat`\"}]}"
~ echo $MY_ENV_VAR
{"endpointCredentials": [{"endpoint":"https://<URL of private feed>/nuget/v3/index.json", "username":"build", "password":"my-pat-token"}]}
능:
# syntax=docker/dockerfile:1.2
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
# Install NuGet credential provider
RUN apt-get update && apt-get install -y locales \
&& sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
&& dpkg-reconfigure --frontend=noninteractive locales && update-locale LANG=en_US.UTF-8 \
# Download the artifact credential provider
&& wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash
COPY NuGet.Config .
COPY ["src/Discovery.Api/Discovery.Api.csproj", "src/Discovery.Api/"]
COPY ["src/Discovery.Service/Discovery.Service.csproj", "src/Discovery.Service/"]
COPY ["src/Discovery.Data/Discovery.Data.csproj", "src/Discovery.Data/"]
# Use the secret to set the credential provider variable and run restore.
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
RUN --mount=type=secret,id=pat,dst=/pat export VSS_NUGET_EXTERNAL_FEED_ENDPOINTS="{\"endpointCredentials\": [{\"endpoint\":\"https://<my private feed URL>/nuget/v3/index.json\", \"username\":\"docker\", \"password\":\"`cat /pat`\"}]}" && \
echo $VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
RUN dotnet restore "src/Discovery.Api/Discovery.Api.csproj" --configfile NuGet.Config
COPY . .
WORKDIR "/src/Discovery.Api"
RUN dotnet build "src/Discovery.Api/Discovery.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "src/Discovery.Api/Discovery.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "src/Discovery.Api/Discovery.Api.dll"]
도커 명령을 사용:
docker build --no-cache --progress=plain --secret id=pat,src=./pat -t discovery-api:dev -f src\Discovery.Api\Dockerfile .
docker--version
Docker version 20.10.8, build 3967b7d
나는 실행하는 도커 리눅스에서 컨테이너입니다.