Skip to content

Instantly share code, notes, and snippets.

@vtml
Created September 7, 2021 14:11
Show Gist options
  • Save vtml/ccb8f5e39251e689d3b7c38c00684eb2 to your computer and use it in GitHub Desktop.
Save vtml/ccb8f5e39251e689d3b7c38c00684eb2 to your computer and use it in GitHub Desktop.
Sample Docker File that installs Certificates to the Root Store. Example of Solution Dockerfile from Sitecore's Docker Examples repo
# escape=`
ARG BASE_IMAGE
ARG BUILD_IMAGE
FROM ${BUILD_IMAGE} AS prep
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# Gather only artifacts necessary for NuGet restore, retaining directory structure
COPY *.sln nuget.config Directory.Build.targets Packages.props \nuget\
COPY src\ \temp\
RUN Invoke-Expression 'robocopy C:\temp C:\nuget\src /s /ndl /njh /njs *.csproj *.scproj packages.config'
FROM ${BUILD_IMAGE} AS builder
ARG BUILD_CONFIGURATION
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# Install Root Cert, located at certs\root folder in the host machine, relative to the path of the Solution Dockerfile
WORKDIR C:\certs
COPY certs\root .\
RUN Get-ChildItem -File | Foreach { Import-Certificate -FilePath $_.fullname -CertStoreLocation Cert:\LocalMachine\Root }
# Create an empty working directory
WORKDIR C:\build
# Copy prepped NuGet artifacts, and restore as distinct layer to take better advantage of caching
COPY --from=prep .\nuget .\
RUN nuget restore
# Copy remaining source code
COPY src\ .\src\
# Copy transforms, retaining directory structure
RUN Invoke-Expression 'robocopy C:\build\src C:\out\transforms /s /ndl /njh /njs *.xdt'
# Build website with file publish
RUN msbuild .\src\DockerExamples.Website\DockerExamples.Website.csproj /p:Configuration=$env:BUILD_CONFIGURATION /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:PublishUrl=C:\out\website
# Build XConnect with file publish
RUN msbuild .\src\DockerExamples.XConnect\DockerExamples.XConnect.csproj /p:Configuration=$env:BUILD_CONFIGURATION /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:PublishUrl=C:\out\xconnect
FROM ${BASE_IMAGE}
WORKDIR C:\artifacts
# Copy final build artifacts
COPY --from=builder C:\out\website .\website\
COPY --from=builder C:\out\transforms .\transforms\
COPY --from=builder C:\out\xconnect .\xconnect\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment