为什么砸在我的docker建立文件返回腐败json?

0

的问题

为什么是docker建立破坏id in$VSS_NUGET_EXTERNAL_FEED_ENDPOINTS?

我使用 本条 (spefically例2,其使用 Buildkit多克建设秘密),以帮助填充我个命令.. 该进程将:

  • 通过拍过 docker build,
  • 山PAT作为一个秘密,
  • 出口逃JSON字符串中使用的秘密(通过 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

输出的回声命令(通知后结束拍附后id闭括号):

{"endpointCredentials": [{"endpoint":"https://<my private feed URL>/nuget/v3/index.json", "username":"docker", "password":"qwak...jiq5"}]}vtzkzv4a

当我运行命令在庆典(在窗子系统,用于Linux)它的工作只是罚款:

~ 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建设命令:

docker build --no-cache --progress=plain --secret id=pat,src=./pat -t discovery-api:dev -f src\Discovery.Api\Dockerfile .

docker--的版本

Docker version 20.10.8, build 3967b7d

我正在运行docker在linux上的容器。

bash docker json nuget
2021-11-23 21:26:24
1

最好的答案

0

按咨询意见@格伦*杰克曼和@丹在评论中,我发现的 /pat 文件有一个newline结束时的文件。 删除newline解决id问题。

2021-11-24 03:30:54

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................