Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker: Integration tests + Dianoga Docker Assets Images #109

Merged
merged 14 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/actions/publish-docker-hub/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Publish to Docker"
description: "Pushes built artifacts to Docker"
inputs:
build_configuration:
description: "Debug/Release"
required: true
dotnet_version:
description: "net45/net46/net471/net48/etc"
required: true
username:
description: "Docker registry username"
required: true
password:
description: "Docker registry password"
required: true
runs:
using: "composite"
steps:
- uses: mr-smithers-excellent/docker-build-push@v5
name: Build & push Docker image
with:
image: antonytm/dianoga-assets
tags: 6.0.0-beta.2-${{ inputs.dotnet_version }}-${{ inputs.build_configuration }}-${{ github.run_number }}, latest-${{ inputs.dotnet_version }}-${{ inputs.build_configuration }}
registry: docker.io
dockerfile: Dockerfile
username: ${{ inputs.username }}
password: ${{ inputs.password }}
buildArgs: |
BUILD_CONFIGURATION=${{ inputs.build_configuration }}, DOTNET_VERSION_ARG=${{ inputs.dotnet_version }}
20 changes: 20 additions & 0 deletions .github/workflows/Dianoga-Docker-NET452-Debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Dianoga Docker CI, .NET 4.5.2, Debug
on:
push:
branches: [ feature/docker ]
env:
BUILD_CONFIGURATION: Debug
DIANOGA_DOTNET_VERSION: net452
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run custom action
uses: ./.github/actions/publish-docker-hub
with:
build_configuration: ${{ env.BUILD_CONFIGURATION }}
dotnet_version: ${{ env.DIANOGA_DOTNET_VERSION }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/Dianoga-Docker-NET452-Release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Dianoga Docker CI, .NET 4.5.2, Release
on:
push:
branches: [ feature/docker ]
env:
BUILD_CONFIGURATION: Release
DIANOGA_DOTNET_VERSION: net452
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run custom action
uses: ./.github/actions/publish-docker-hub
with:
build_configuration: ${{ env.BUILD_CONFIGURATION }}
dotnet_version: ${{ env.DIANOGA_DOTNET_VERSION }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/Dianoga-Docker-NET462-Debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Dianoga Docker CI, .NET 4.6.2, Debug
on:
push:
branches: [ feature/docker ]
env:
BUILD_CONFIGURATION: Debug
DIANOGA_DOTNET_VERSION: net462
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run custom action
uses: ./.github/actions/publish-docker-hub
with:
build_configuration: ${{ env.BUILD_CONFIGURATION }}
dotnet_version: ${{ env.DIANOGA_DOTNET_VERSION }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/Dianoga-Docker-NET462-Release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Dianoga Docker CI, .NET 4.6.2, Release
on:
push:
branches: [ feature/docker ]
env:
BUILD_CONFIGURATION: Release
DIANOGA_DOTNET_VERSION: net462
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run custom action
uses: ./.github/actions/publish-docker-hub
with:
build_configuration: ${{ env.BUILD_CONFIGURATION }}
dotnet_version: ${{ env.DIANOGA_DOTNET_VERSION }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/Dianoga-Docker-NET471-Debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Dianoga Docker CI, .NET 4.7.1, Debug
on:
push:
branches: [ feature/docker ]
env:
BUILD_CONFIGURATION: Debug
DIANOGA_DOTNET_VERSION: net471
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run custom action
uses: ./.github/actions/publish-docker-hub
with:
build_configuration: ${{ env.BUILD_CONFIGURATION }}
dotnet_version: ${{ env.DIANOGA_DOTNET_VERSION }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/Dianoga-Docker-NET471-Release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Dianoga Docker CI, .NET 4.7.1, Release
on:
push:
branches: [ feature/docker ]
env:
BUILD_CONFIGURATION: Release
DIANOGA_DOTNET_VERSION: net471
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run custom action
uses: ./.github/actions/publish-docker-hub
with:
build_configuration: ${{ env.BUILD_CONFIGURATION }}
dotnet_version: ${{ env.DIANOGA_DOTNET_VERSION }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/Dianoga-Docker-NET48-Debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Dianoga Docker CI, .NET 4.8, Debug
on:
push:
branches: [ feature/docker ]
env:
BUILD_CONFIGURATION: Debug
DIANOGA_DOTNET_VERSION: net48
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run custom action
uses: ./.github/actions/publish-docker-hub
with:
build_configuration: ${{ env.BUILD_CONFIGURATION }}
dotnet_version: ${{ env.DIANOGA_DOTNET_VERSION }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/Dianoga-Docker-NET48-Release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Dianoga Docker CI, .NET 4.8, Release
on:
push:
branches: [ feature/docker ]
env:
BUILD_CONFIGURATION: Release
DIANOGA_DOTNET_VERSION: net48
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run custom action
uses: ./.github/actions/publish-docker-hub
with:
build_configuration: ${{ env.BUILD_CONFIGURATION }}
dotnet_version: ${{ env.DIANOGA_DOTNET_VERSION }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ src/Dianoga.Tests/Optimizers/Pipelines/DianogaSvg/SVGO
# NuGet packages
packages/*
!packages/repositories.config
Build/*.nupkg
Build/*.nupkg
/integration-tests/.env
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# escape=`

ARG BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:1809
ARG BUILD_IMAGE=mcr.microsoft.com/dotnet/framework/sdk:4.8

FROM ${BUILD_IMAGE} AS build-env
ARG BUILD_CONFIGURATION=
ARG DOTNET_VERSION_ARG=

WORKDIR /
# Add Sitecore Nuget source
RUN dotnet nuget add source https://sitecore.myget.org/F/sc-packages/api/v3/index.json

# Copy csproj and restore as distinct layers
COPY *.sln ./
COPY src/Dianoga/Dianoga.csproj ./src/Dianoga/
COPY src/Dianoga.Tests/Dianoga.Tests.csproj ./src/Dianoga.Tests/
RUN dotnet restore

# Copy everything else and build
COPY src ./src
RUN dotnet build -c $env:BUILD_CONFIGURATION
RUN mkdir ./src/bin
RUN Copy ./src/Dianoga/bin/$env:BUILD_CONFIGURATION/$env:DOTNET_VERSION_ARG/Dianoga.* ./src/bin/
RUN Copy ./src/Dianoga/bin/$env:BUILD_CONFIGURATION/$env:DOTNET_VERSION_ARG/System.Threading.Tasks.Dataflow.dll ./src/bin/

FROM ${BASE_IMAGE}

# Copy Dianoga dll and pdb (if present)
COPY --from=build-env /src/bin/ ./module/cd/content/bin/
COPY --from=build-env /src/bin/ ./module/cm/content/bin/


# Copy Dianoga Tools
ARG src="/src/Dianoga/Dianoga Tools"
ARG target="./module/cd/content/App_Data/Dianoga Tools"
COPY --from=build-env ${src} ${target}

ARG src="/src/Dianoga/Dianoga Tools"
ARG target="./module/cd/content/App_Data/Dianoga Tools"
COPY --from=build-env ${src} ${target}

# Copy Configs
ARG src="/src/Dianoga/Default Config Files"
ARG target="./module/cm/content/App_Config/Include/Dianoga"
COPY --from=build-env ${src} ${target}

ARG src="/src/Dianoga/Default Config Files"
ARG target="./module/cd/content/App_Config/Include/Dianoga"
COPY --from=build-env ${src} ${target}
17 changes: 17 additions & 0 deletions integration-tests/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# folders
.git
.gitignore
.vs
.vscode
build
docker
packages
**/bin/
**/obj/
**/out/

# files
*Dockerfile
docker-compose*
**/*.md
*.ps1
49 changes: 49 additions & 0 deletions integration-tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# escape=`

ARG BASE_IMAGE
ARG BUILD_IMAGE

FROM ${BUILD_IMAGE} AS prep
ARG BUILD_CONFIGURATION
RUN echo $env:BUILD_CONFIGURATION
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
RUN echo $env:BUILD_CONFIGURATION

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# 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\src\Dianoga\Dianoga.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\
Loading