Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
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
49 changes: 49 additions & 0 deletions build/pack-docs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

<#
.SYNOPSIS
Packs documentation for IQ# using a newly built Dockerfile and the
build_docs.py script. See build/docs/README.md.
#>

param(

);

$ErrorActionPreference = 'Stop';
& "$PSScriptRoot/set-env.ps1";

# If we can, pack docs using the documentation build container.
# We use the trick at https://blog.ropnop.com/plundering-docker-images/#extracting-files
# to build a new image containing all the docs we care about, then `docker cp`
# them out.
$tempTag = New-Guid | Select-Object -ExpandProperty Guid;
# When building in release mode, we also want to document additional
# packages that contribute IQ# magic commands.
if ("$Env:BUILD_RELEASETYPE" -eq "release") {
$extraPackages = "--package Microsoft.Quantum.Katas --package Microsoft.Quantum.Chemistry.Jupyter";
} else {
$extraPackages = "";
}
# Note that we want to use a Dockerfile read from stdin so that we can more
# easily inject the right base image into the FROM line. In doing so,
# the build context should include the build_docs.py script that we need.
$dockerfile = @"
FROM ${Env:DOCKER_PREFIX}iqsharp-base:${Env:BUILD_BUILDNUMBER}

USER root
RUN pip install click ruamel.yaml
WORKDIR /workdir
RUN chown -R `${USER} /workdir

USER `${USER}
COPY build_docs.py /workdir
RUN python build_docs.py \
/workdir/drops/docs/iqsharp-magic \
microsoft.quantum.iqsharp.magic-ref \
$extraPackages
"@;
$dockerfile | docker build -t $tempTag -f - (Join-Path $PSScriptRoot "docs");
$tempContainer = docker create $tempTag;
docker cp "${tempContainer}:/workdir/drops/docs/iqsharp-magic" (Join-Path $Env:DOCS_OUTDIR "iqsharp-magic")
52 changes: 13 additions & 39 deletions build/pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ function Pack-Image() {
[string] $Dockerfile
);

if (($Env:AGENT_OS -ne $null) -and ($Env:AGENT_OS.StartsWith("Win"))) {
Write-Host "--> Cannot create docker image on Windows."
return
}

Try {
docker version
} Catch {
Expand Down Expand Up @@ -143,47 +138,26 @@ if ($Env:ENABLE_PYTHON -eq "false") {
Pack-Wheel '../src/Python/'
}

# Figure out if we can run Docker or not.

if ($Env:ENABLE_DOCKER -eq "false") {
Write-Host "##vso[task.logissue type=warning;]Skipping Creating Docker Image. Env:ENABLE_DOCKER was set to 'false'."
$runDocker = $false;
} elseif (("$Env:AGENT_OS" -ne "") -and ($Env:AGENT_OS.StartsWith("Win"))) {
Write-Host "--> Cannot create docker image on Windows."
$runDocker = $false;
} else {
$runDocker = $true;
}

if ($runDocker) {
Write-Host "##[info]Packing Docker image..."
Pack-Image -RepoName "iqsharp-base" -Dockerfile '../images/iqsharp-base/Dockerfile'
}

if (($Env:ENABLE_DOCKER -eq "false") -or ($Env:ENABLE_PYTHON -eq "false")) {
if (-not $runDocker -or ($Env:ENABLE_PYTHON -eq "false")) {
Write-Host "##vso[task.logissue type=warning;]Skipping IQ# magic command documentation, either ENABLE_DOCKER or ENABLE_PYTHON was false.";
} else {
# If we can, pack docs using the documentation build container.
# We use the trick at https://blog.ropnop.com/plundering-docker-images/#extracting-files
# to build a new image containing all the docs we care about, then `docker cp`
# them out.
$tempTag = New-Guid | Select-Object -ExpandProperty Guid;
# When building in release mode, we also want to document additional
# packages that contribute IQ# magic commands.
if ("$Env:BUILD_RELEASETYPE" -eq "release") {
$extraPackages = "--package Microsoft.Quantum.Katas --package Microsoft.Quantum.Chemistry.Jupyter";
} else {
$extraPackages = "";
}
# Note that we want to use a Dockerfile read from stdin so that we can more
# easily inject the right base image into the FROM line. In doing so,
# the build context should include the build_docs.py script that we need.
$dockerfile = @"
FROM ${Env:DOCKER_PREFIX}iqsharp-base:${Env:BUILD_BUILDNUMBER}

USER root
RUN pip install click ruamel.yaml
WORKDIR /workdir
RUN chown -R `${USER} /workdir

USER `${USER}
COPY build_docs.py /workdir
RUN python build_docs.py \
/workdir/drops/docs/iqsharp-magic \
microsoft.quantum.iqsharp.magic-ref \
$extraPackages
"@;
$dockerfile | docker build -t $tempTag -f - (Join-Path $PSScriptRoot "docs");
$tempContainer = docker create $tempTag;
docker cp "${tempContainer}:/workdir/drops/docs/iqsharp-magic" (Join-Path $Env:DOCS_OUTDIR "iqsharp-magic")
Write-Host "##[info]Packing IQ# reference docs..."
& (Join-Path $PSScriptRoot "pack-docs.ps1");
}