| 1 |
# syntax = docker/dockerfile:1.2.1 |
| 2 |
FROM python:3.12-windowsservercore-ltsc2022 |
| 3 |
SHELL ["powershell"] |
| 4 |
|
| 5 |
# using docker env doesn't seem to work fully correctly. The environment variable is set in the powershell |
| 6 |
# but somehow it is not present during pip install process, which will cause the ipyparallel installation |
| 7 |
# to fail. Therefore, we use the SetEnvironmentVariable command (for the machine) to make this 'permanent'. |
| 8 |
# See run command below. |
| 9 |
ENV IPP_DISABLE_JS=1 |
| 10 |
|
| 11 |
# the following env variable values will be 'statically' replaced by the corresponding github workflow script |
| 12 |
# if the values aren't replaced the container hosts file isn't changed which is typically no problem in a local |
| 13 |
# environment. but it's a necessity for github runners, since the host name resolution inside the container doesn't |
| 14 |
# work correctly while trying to register with the ipyparallel controller (for linux runners this isn't an issue) |
| 15 |
ENV docker_host_ip ${docker_host_ip} |
| 16 |
ENV docker_host_name ${docker_host_name} |
| 17 |
|
| 18 |
# set IPP_DISABLE_JS=1 and install latest node js version |
| 19 |
RUN [System.Environment]::SetEnvironmentVariable('IPP_DISABLE_JS','1', [EnvironmentVariableTarget]::Machine); \ |
| 20 |
#add the docker host name and ip to the container hosts file (needed for the github runners since the docker host name resolution doesn't work there) |
| 21 |
$hostsfile='C:\Windows\System32\drivers\etc\hosts'; \ |
| 22 |
$line=\"$env:docker_host_ip $env:docker_host_name\"; \ |
| 23 |
if ($line.Trim().Length -eq 0) { \ |
| 24 |
Write-Host 'Environment variables docker_host_[name|ip] not set. Hosts file unchanged!'; \ |
| 25 |
} else { \ |
| 26 |
Write-Host 'Adapting hosts file '; \ |
| 27 |
$h=(Get-Content $hostsfile)+$line; \ |
| 28 |
echo $h | out-file -encoding ASCII $hostsfile; \ |
| 29 |
type $hostsfile; \ |
| 30 |
} |
| 31 |
|
| 32 |
RUN Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'; \ |
| 33 |
Write-Host 'Install OpenSSH Server...'; \ |
| 34 |
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0; \ |
| 35 |
Write-Host 'Initializing OpenSSH Server...'; \ |
| 36 |
Start-Service sshd; \ |
| 37 |
Stop-Service sshd |
| 38 |
|
| 39 |
|
| 40 |
# create ciuser including key pair |
| 41 |
RUN Write-Host 'Create user ciuser...';\ |
| 42 |
NET USER ciuser /add |
| 43 |
USER ciuser |
| 44 |
RUN Write-Host 'Create key pair and copy public key...';\ |
| 45 |
ssh-keygen -t rsa -N '\"\"' -f $env:USERPROFILE/.ssh/id_rsa; \ |
| 46 |
cp $env:USERPROFILE/.ssh/id_rsa.pub $env:USERPROFILE/.ssh/authorized_keys |
| 47 |
|
| 48 |
# switch back to the admin user |
| 49 |
USER containeradministrator |
| 50 |
|
| 51 |
# This is apparently the only way to keep the sshd service running. |
| 52 |
# Running sshd in the foreground in the context of a user (as it is done for linux), doesn't work under Windows. |
| 53 |
# Even if it is started as admin user, errors occur during logon (lack of some system rights) |
| 54 |
CMD powershell -NoExit -Command "Start-Service sshd" |