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

Windows Tests via Docker #781

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
35 changes: 35 additions & 0 deletions .github/docker/rez-win-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# escape=`

# Please Note: Any " requires \" in the Dockerfile for windows.

# The windows version has to match the host system.
# 1809 -> 10.0.17763.805 -> windows-2019
# Compare: https://hub.docker.com/_/microsoft-windows-servercore
ARG WINDOWS_VERSION=1809-amd64

FROM mcr.microsoft.com/windows/servercore:$WINDOWS_VERSION

SHELL ["powershell.exe", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "ByPass"]

ARG GIT_VERSION=2.23.0
ARG CMAKE_VERSION=3.15.4
ARG PWSH_VERSION=6.2.2

# ------------------------------------------------------------------------------------------------------------
# Install:
# - Chocolatey
# - Git
# - Cmake
# - PowerShellCore
#
ENV chocolateyUseWindowsCompression false
RUN iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')); `
choco feature disable --name showDownloadProgress; `
choco install git.install --yes --version=${ENV:GIT_VERSION}; `
choco install cmake --yes --version=${ENV:CMAKE_VERSION} --installargs 'ADD_CMAKE_TO_PATH=System'; `
choco install pwsh --yes --version=${PWSH_VERSION}; `
choco install --yes choco-cleaner; `
C:\ProgramData\chocolatey\bin\choco-cleaner.ps1; `
choco uninstall --yes choco-cleaner

ENTRYPOINT ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "ByPass"]
51 changes: 51 additions & 0 deletions .github/docker/rez-win-py/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# escape=`

# Tag of base image to use
ARG BASE_TAG

# Base image windows version
FROM rez-win-base:$BASE_TAG

# NOTE: Any " requires \" in the Dockerfile for windows.
# NOTE: The order matters. ARG after the shell command will allow access via
# the PowerShell environment like ${ENV:PYTHON_VERSION}.
SHELL ["powershell.exe", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "ByPass"]

# Python version to install (full chocolatey compatible version required)
# For example: 3.7.5
#
ARG PYTHON_VERSION

# ------------------------------------------------------------------------------------------------------------
# Python
#
# Installs given Python version to C:\Python
# Python 2.x uses msi while 3.x has an exe with separate arguments
# Verifies the installation by running python explicitly and via `python`
#
RUN ${PYTHON_INSTALL_PATH} = 'C:\Python'; `
bfloch marked this conversation as resolved.
Show resolved Hide resolved
${PYTHON_MAJOR_VERSION} = ${ENV:PYTHON_VERSION}.Split('.')[0]; `
if (${PYTHON_MAJOR_VERSION} -eq "2") { `
${INSTALLARGS} = \"'/qn /norestart ADDLOCAL=ALL ALLUSERS=1 TARGETDIR=`\"\" + ${PYTHON_INSTALL_PATH} + \"`\"'\"; `
} else { `
${INSTALLARGS} = \"'/quiet InstallAllUsers=1 PrependPath=1 TargetDir=`\"\" + ${PYTHON_INSTALL_PATH} + \"`\"'\"; `
} `
choco install python${PYTHON_MAJOR_VERSION} --yes --version=\"${ENV:PYTHON_VERSION}\" --override --installargs=${INSTALLARGS}; `
if (-not $?) {exit 1};

# ------------------------------------------------------------------------------------------------------------
# Verify Python
#
RUN $python_relative_ver = (& python --version 2>&1).ToString().Trim().Split(" ")[1]; `
$python_explicit_ver = (& C:\python\python.exe --version 2>&1).ToString().Trim().Split(" ")[1]; `
if (-not $?) {exit 1}; `
$python_relative_ver = (& python --version 2>&1).ToString().Trim().Split(" ")[1]; `
$python_explicit_ver = (& C:\python\python.exe --version 2>&1).ToString().Trim().Split(" ")[1]; `
if (-not ($python_explicit_ver -eq $python_relative_ver -and $python_explicit_ver -eq ${ENV:PYTHON_VERSION})) {exit 1}; `
choco install --yes choco-cleaner; `
C:\ProgramData\chocolatey\bin\choco-cleaner.ps1; `
choco uninstall --yes choco-cleaner

COPY entrypoint.ps1 /entrypoint.ps1

ENTRYPOINT ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "ByPass", "-File", "/entrypoint.ps1"]
53 changes: 53 additions & 0 deletions .github/docker/rez-win-py/entrypoint.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# Entrypoint that installs given python version and runs tests from commit.
#
# $repo is the repository like 'nerdvegas/rez'
# $commit is the revision to test
param( $repo, $commit )

# Stop on errors; .exe has to be checked manually
Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"

echo "Testing $repo at $commit"

# Fixes encoding issue on Windows 10 local docker run.
#
${ENV:PYTHONIOENCODING} = "UTF-8"

# Verify Python
#
python --version
if (-not $?) {exit 1}

# Verify cmake
#
cmake.exe --version
if (-not $?) {exit 1}

#Verify pwsh
pwsh --version
if (-not $?) {exit 1}

#Verify git
git --version
if (-not $?) {exit 1}

# Clone repo
git clone https://github.com/$repo rez
if (-not $?) {exit 1}
cd rez
git checkout $commit
if (-not $?) {exit 1}

# Install rez
mkdir build
python install.py build
if (-not $?) {exit 1}

# Run Rez Tests
#
.\build\Scripts\rez\rez-selftest.exe

# Pass on exit code to runner
exit $LASTEXITCODE
11 changes: 10 additions & 1 deletion .github/workflows/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
# * Platform dependent.
#
name: Core
on: [push, pull_request]
on:
# Do not run if Docker image has been updated
pull_request:
paths-ignore:
- '.github/docker/**'
- '.github/workflows/windows-docker-image.yaml'
push:
paths-ignore:
- '.github/docker/**'
- '.github/workflows/windows-docker-image.yaml'

jobs:
main:
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/mac.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
name: MacOS
on: [push, pull_request]
on:
# Do not run if Docker image has been updated
pull_request:
paths-ignore:
- '.github/docker/**'
- '.github/workflows/windows-docker-image.yaml'
push:
paths-ignore:
- '.github/docker/**'
- '.github/workflows/windows-docker-image.yaml'

jobs:
main:
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/ubuntu.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
name: Ubuntu
on: [push, pull_request]
on:
# Do not run if Docker image has been updated
pull_request:
paths-ignore:
- '.github/docker/**'
- '.github/workflows/windows-docker-image.yaml'
push:
paths-ignore:
- '.github/docker/**'
- '.github/workflows/windows-docker-image.yaml'

jobs:
main:
Expand Down
102 changes: 102 additions & 0 deletions .github/workflows/windows-docker-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#
# Create base docker image and python version specific images for windows.
# Currently uses hub.docker.com as registry.
#
# Requires a DOCKERHUB_TOKEN secret and username/repository to match the github
# repository. For example: nerdvegas/rez -> User/Repository: nerdvegas
#
# Commit to windows-docker-image.yaml or .github/docker/** separately
# to trigger a image build. This Image will be used in consecutive commits.
#
# TODO:
# - Better way to pass the variables throughout steps
# - The reason for using docker is that the github supplied containers have
# a bloated PATH environment variable that can not be changed:
# https://github.community/t5/GitHub-Actions/Windows-image-bloat-in-PATH-disables-cmd-prompt-usage/m-p/36004#M2414
# - Github offers its own package registry. Pushing to is broken in the BETA
# https://github.community/t5/GitHub-Actions/Docker-Push-to-Package-Registry-from-Windows/m-p/36393#M2560

name: Compose Windows Docker Image

on:
push:
# Will only trigger building a docker image if any of these changed
paths:
- '.github/docker/rez-win-base/**'
- '.github/docker/rez-win-py/**'
- '.github/workflows/windows-docker-image.yaml'

jobs:

# ----------------------------------------------------------------------------
# Create base image if necessary
#
# State depends on .github\docker\rez-win-base\** and this file
base:
runs-on: windows-2019

steps:
- name: Login to docker repository
run: |
${gh_user} = ("${{ github.repository }}" -Split '/')[0]
'${{ secrets.DOCKERHUB_TOKEN }}' | docker login -u ${gh_user} --password-stdin

# TODO: Represent the conditional build as steps?
# https://github.community/t5/GitHub-Actions/Fallback-via-if-failure-without-failing-the-job/m-p/36596#M2636
#
# By using dockers experimental CLI features we don't need to pull an
# image to check if it exists.
- uses: actions/checkout@v1
- name: Build docker image if needed
run: |
${Env:LAST_DOCKER_BASE_REVISION} = $( git log -n 1 --author-date-order --pretty=format:%H -- .\.github\docker\rez-win-base\ .\.github\workflows\windows-docker-image.yaml ).SubString(0, 8)
${gh_user} = ("${{ github.repository }}" -Split '/')[0]
docker manifest inspect ${gh_user}/rez-win-base:${ENV:LAST_DOCKER_BASE_REVISION} | Out-Null
if (-not $?) {
cd .github\docker\rez-win-base
docker build --tag ${gh_user}/rez-win-base:${ENV:LAST_DOCKER_BASE_REVISION} .
docker push ${gh_user}/rez-win-base:${ENV:LAST_DOCKER_BASE_REVISION}
}

env:
DOCKER_CLI_EXPERIMENTAL: enabled

# ----------------------------------------------------------------------------
# Create python images off base image
# Each image will have a single python version installed as defined in the
# strategy-matrix.
#
python:
runs-on: windows-2019
needs: base

strategy:
matrix:
python-version:
- '2.7.17'
- '3.6.8'
- '3.7.5'
fail-fast: false

steps:
- name: Login to docker repository
run: |
${gh_user} = ("${{ github.repository }}" -Split '/')[0]
'${{ secrets.DOCKERHUB_TOKEN }}' | docker login -u ${gh_user} --password-stdin

- uses: actions/checkout@v1
- name: Pull base docker image
run: |
${Env:LAST_DOCKER_BASE_REVISION} = $( git log -n 1 --author-date-order --pretty=format:%H -- .\.github\docker\rez-win-base\ .\.github\workflows\windows-docker-image.yaml ).SubString(0, 8)
${gh_user} = ("${{ github.repository }}" -Split '/')[0]
docker pull ${gh_user}/rez-win-base:${ENV:LAST_DOCKER_BASE_REVISION}
docker tag ${gh_user}/rez-win-base:${ENV:LAST_DOCKER_BASE_REVISION} rez-win-base:${ENV:LAST_DOCKER_BASE_REVISION}

- name: Build and push Docker image
run: |
${gh_user} = ("${{ github.repository }}" -Split '/')[0]
${ENV:DOCKER_TAG} = "${{ github.sha }}".Substring(0, 8)
${Env:LAST_DOCKER_BASE_REVISION} = $( git log -n 1 --author-date-order --pretty=format:%H -- .\.github\docker\rez-win-base\ .\.github\workflows\windows-docker-image.yaml ).SubString(0, 8)
cd .github\docker\rez-win-py
docker build --tag ${gh_user}/rez-win-py:${{ matrix.python-version }}-${ENV:DOCKER_TAG} --build-arg PYTHON_VERSION="${{ matrix.python-version }}" --build-arg BASE_TAG=${ENV:LAST_DOCKER_BASE_REVISION} .
docker push ${gh_user}/rez-win-py:${{ matrix.python-version }}-${ENV:DOCKER_TAG}
56 changes: 56 additions & 0 deletions .github/workflows/windows-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
instinct-vfx marked this conversation as resolved.
Show resolved Hide resolved
# Picks up docker image from hub.docker.com as repository.
#
# Requires a DOCKERHUB_TOKEN secret and username/repository to match the github
# repository. For example: nerdvegas/rez -> User/Repository: nerdvegas
#
# Uses image tagged as **latest** commit revision of any file within:
# .github/docker/windows/**
# .github/workflows/windows-docker-image.yaml
#

name: Windows Docker

on:
# Do not run if Docker image has been updated
pull_request:
paths-ignore:
- '.github/docker/**'
- '.github/workflows/windows-docker-image.yaml'
push:
paths-ignore:
- '.github/docker/**'
- '.github/workflows/windows-docker-image.yaml'

jobs:
main:
runs-on: windows-2019

strategy:
matrix:
# Needs to match python version of images (see windows-docker-image.yaml)
python-version:
- '2.7.17'
- '3.6.8'
- '3.7.5'
fail-fast: false

steps:
- uses: actions/checkout@v1
- name: Login to docker repository
run: |
${gh_user} = ("${{ github.repository }}" -Split '/')[0]
'${{ secrets.DOCKERHUB_TOKEN }}' | docker login -u ${gh_user} --password-stdin

- name: Pull docker image
run: |
${gh_user} = ("${{ github.repository }}" -Split '/')[0]
${Env:LAST_DOCKER_REVISION} = $( git log -n 1 --author-date-order --pretty=format:%H -- .\.github\docker\rez-win-py\ .\.github\workflows\windows-docker-image.yaml ).SubString(0, 8)
echo "Pulling rez-win-py:${{ matrix.python-version }}-${Env:LAST_DOCKER_REVISION}"
docker pull ${gh_user}/rez-win-py:${{ matrix.python-version }}-${Env:LAST_DOCKER_REVISION}

- name: Run the Docker image
run: |
${gh_user} = ("${{ github.repository }}" -Split '/')[0]
${Env:LAST_DOCKER_REVISION} = $( git log -n 1 --author-date-order --pretty=format:%H -- .\.github\docker\rez-win-py\ .\.github\workflows\windows-docker-image.yaml ).SubString(0, 8)
docker run ${gh_user}/rez-win-py:${{ matrix.python-version }}-${Env:LAST_DOCKER_REVISION} ${{ github.repository }} ${{ github.sha }}
45 changes: 0 additions & 45 deletions .github/workflows/windows.yaml

This file was deleted.

Loading