Created
January 17, 2019 13:18
-
-
Save brbarnett/c55c80dd63b89465cfd9bc6b74c0548e to your computer and use it in GitHub Desktop.
Accessing Azure Artifacts from a docker container in a Pipelines build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources: | |
- repo: self | |
queue: | |
name: Hosted Ubuntu 1604 | |
variables: | |
- group: Artifacts | |
steps: | |
- task: Docker@1 | |
displayName: 'Build an image' | |
inputs: | |
azureSubscriptionEndpoint: 'DemoSPNConnection' | |
azureContainerRegistry: demo.azurecr.io | |
arguments: '--build-arg ARTIFACTS_ENDPOINT=$(artifactsEndpoint) --build-arg ACCESS_TOKEN=$(artifactsAccessToken)' | |
- task: Docker@1 | |
displayName: 'Push an image' | |
inputs: | |
azureSubscriptionEndpoint: 'DemoSPNConnection' | |
azureContainerRegistry: demo.azurecr.io | |
command: 'Push an image' | |
trigger: | |
batch: true | |
branches: | |
include: | |
- master | |
paths: | |
exclude: | |
- readme.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources: | |
- repo: self | |
queue: | |
name: Hosted Ubuntu 1604 | |
variables: | |
- group: Artifacts | |
steps: | |
- task: Docker@1 | |
displayName: 'Build an image' | |
inputs: | |
azureSubscriptionEndpoint: 'DemoSPNConnection' | |
azureContainerRegistry: demo.azurecr.io | |
arguments: '--build-arg ARTIFACTS_ENDPOINT=$(artifactsEndpoint) --build-arg ACCESS_TOKEN=$(artifactsAccessToken)' | |
trigger: none |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM microsoft/dotnet:2.2.100-sdk AS build-env | |
WORKDIR /app | |
# Credit: https://stackoverflow.com/questions/53419491/azure-artifacts-gives-unauthorized-when-trying-to-build-dockerfile/53510966#53510966 | |
# Personal access token to access Artifacts feed | |
ARG ACCESS_TOKEN | |
ARG ARTIFACTS_ENDPOINT | |
# Install the Credential Provider to configure the access | |
RUN wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash | |
# Configure the environment variables | |
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true | |
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS "{\"endpointCredentials\": [{\"endpoint\":\"${ARTIFACTS_ENDPOINT}\", \"password\":\"${ACCESS_TOKEN}\"}]}" | |
# copy everything and build the project | |
COPY ./src ./ | |
RUN dotnet restore -s ${ARTIFACTS_ENDPOINT} api/*.csproj | |
RUN dotnet publish api/*.csproj -c Release -o out | |
# build runtime image | |
FROM microsoft/dotnet:2.2-aspnetcore-runtime | |
WORKDIR /app | |
COPY --from=build-env /app/api/out ./ | |
ENTRYPOINT ["dotnet", "api.dll"] | |
EXPOSE 443 |
Instead of creating and using Access Token you can use NuGetAuthenticate task and then use VSS_NUGET_ACCESSTOKEN env variable.
- task: NuGetAuthenticate@0
- task: Docker@2
inputs:
...
arguments: '--build-arg ACCESS_TOKEN=$(VSS_NUGET_ACCESSTOKEN)'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how the processes of build works in terms of containerized application because in our case it is magneto image which is 1.6GB and building that size of image is taking too much time how we can overcome this?