Skip to content

Instantly share code, notes, and snippets.

@caffeinetiger
Last active April 18, 2022 18:20
Show Gist options
  • Select an option

  • Save caffeinetiger/fed837cbfdd1bb531aa66d1d96c2d80e to your computer and use it in GitHub Desktop.

Select an option

Save caffeinetiger/fed837cbfdd1bb531aa66d1d96c2d80e to your computer and use it in GitHub Desktop.
Example Dockefile to build a ASPNet Core 3.1 project inside a Dockerfile using AWS CodeArtifact. **Required Docker Build Arguments** - AWS_ACCOUNT_ID - Id of the AWS Account of the ECR repository to push to. - AWS_ACCESS_KEY_ID - Specifies an AWS ac
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat
FROM mcr.microsoft.com/dotnet/aspnet:3.1-alpine AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1-alpine AS build
ARG AWS_ACCOUNT_ID
ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY
ARG AWS_DEFAULT_REGION
ENV AWS_ACCOUNT_ID=${AWS_ACCOUNT_ID}
ENV AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
ENV AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
ENV AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
ENV PATH $PATH:/root/.dotnet/tools
RUN apk add --no-cache \
python3 \
py3-pip \
zip \
&& pip3 install --upgrade pip \
&& pip3 install \
awscli \
&& rm -rf /var/cache/apk/*
RUN dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider && dotnet codeartifact-creds install
RUN dotnet nuget add source "https://<domain>-${AWS_ACCOUNT_ID}.d.codeartifact.us-east-1.amazonaws.com/nuget/<repository name>/v3/index.json" -n "<domnain>/<repository name>"
WORKDIR /src
COPY ["<project name>.csproj", "."]
RUN dotnet restore "<project name>.csproj"
COPY . .
WORKDIR "/src/<project name>"
RUN dotnet build "<project name>.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "<project name>.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "<project name>.dll"]
#!/bin/bash
AWS_ACCOUNT_ID=555555555555
AWS_ACCESS_KEY_ID="some-key-value"
AWS_SECRET_ACCESS_KEY="some-secret-access-key"
AWS_DEFAULT_REGION="some-region-like-us-east-1"
IMAGE_TAG="some-value"
docker build -t ${IMAGE_TAG} . \
-f ./Dockerfile \
--build-arg AWS_ACCOUNT_ID=${AWS_ACCOUNT_ID} \
--build-arg AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \
--build-arg AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \
--build-arg AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION} \
--progress=plain \
--no-cache=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment