Commit 0e9c3c16 authored by Jean-Francois Rey's avatar Jean-Francois Rey
Browse files

add vagrantfile and ansible provisining

Add CI/CD
parent f5c80a7a
stages:
- build
- deploy
Gen-VM:
tags:
- "virtualbox"
- "ansible"
- "vagrant"
stage: build
scripts:
- Vagrant up
- Vagrant halt windows10R4
Deploy-VM:
tags:
- "virtualbox"
- "ansible"
- "vagrant"
stage: deploy
when: on_success
scripts:
- vboxmanager unregistervm --delete win10R4
- vboxmanager modifyvm windows10R4 --name win10R4
Vagrant.configure("2") do |config|
config.vm.box = "GAEV/win10"
config.vm.boot_timeout = 600
# Configure Vagrant to use WinRM instead of SSH
config.vm.communicator = "winrm"
# Configure WinRM Connectivity
config.winrm.basic_auth_only = true
config.winrm.username = "vagrant"
config.winrm.password = "vagrant"
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = false
vb.name = "windows10R4"
vb.customize ["modifyvm", :id, "--memory", 4096]
vb.customize ["modifyvm", :id, "--cpus", 4]
vb.customize ["modifyvm", :id, "--vram", 128]
vb.customize ["modifyvm", :id, "--graphicscontroller","vboxsvga"]
vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
vb.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
end
config.vm.provision "ansible" do |ansible|
ansible.playbook = "ansible_provisioning/playbook.yml"
ansible.inventory_path = "ansible_provisioning/group_vars/inventory.yml"
ansible.verbose = "-vv"
ansible.limit= "windows"
end
end
#!/bin/sh
## execute using bash C:\Rtools\usr\bin\bash.exe
# Add repository
sed -i.bak -e "s/^#\[msys\]/\[msys\]/" -e "s/^#Include/Include/" /etc/pacman.conf
echo -e "Server = http://repo.msys2.org/mingw/\$arch/" >> /etc/pacman.d/mirrorlist.msys
echo -e "Server = http://repo.msys2.org/mingw/x86_64/" >> /etc/pacman.d/mirrorlist.mingw64
# Update server gpg key
curl -O http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz
curl -O http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig
pacman-key --verify msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig
pacman -U msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz --noconfirm
pacman --noconfirm -U --config <(echo) msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz
# Update msys2 (just one time to keep Rtools dependences versions)
pacman -Syuu --noconfirm
#pacman -S openssh cygrunsrv mingw-w64-x86_64-editrights --noconfirm
# Install R Tools 4.0
Write-Output "Installing GitLab Runners"
Write-Output "Downloading Gitlab Runners Last Version"
## download last relase name
$url = "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-windows-amd64.exe"
$output = 'C:\GitLab-Runner\gitlab-runner.exe'
$wcR = New-Object System.Net.WebClient
Write-Output "Downloading $url"
#Download the exe
$wcR.DownloadFile($url, $output)
Write-Output "Download completed $url"
# Add GitLab to PATH
$oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
$newPath = "$oldpath;C:\GitLab-Runner\\"
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
# Install miktex for latex support
Write-Output "Installing MiKTeX"
Write-Output "Downloading installer"
## download last relase name
$url = "https://miktex.org/download/win/miktexsetup-x64.zip"
$output = 'c:\Windows\Temp\miktex.zip'
$wcR = New-Object System.Net.WebClient
Write-Output "Downloading $url"
#Download the exe
$wcR.DownloadFile($url, $output)
Write-Output "Download completed $url"
Write-Output "unzip"
Expand-Archive -LiteralPath $output -DestinationPath 'C:\Windows\Temp\' InvoiceUnzipped
Write-Output "Download repository"
miktexsetup --verbose --local-package-repository=C:\Windows\Temp\miktex --package-set=complete download
Write-Output "Install "
C:\Windows\Temp\miktex\miktexsetup.exe --quiet --local-package-repository=C:\Windows\Temp\miktex --package-set=basic --shared=yes --common-install='C:\miktex' install
Write-Output "MiKTeX installed into C:\miktex"
#if ( Test-Path "HKLM:\Software\R-core\Rtools" ) {
# $Rtoolsver = (Get-ItemProperty -Path "HKLM:\Software\R-core\Rtools")."Current Version"
# Write-Output "Rtools version $Rtoolsver installed"
#}
#else {
# throw "ERROR: Can't install R $urlRtools"
#}
# Add miktex to PATH
#$oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
#$newPath = "$oldpath;C:\miktek\bin"
#Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
#!/bin/sh
#
# msys2-sshd-setup.sh — configure sshd on MSYS2 and run it as a Windows service
#
# Replaces ssh-host-config <https://github.com/openssh/openssh-portable/blob/master/contrib/cygwin/ssh-host-config>
# Adapted from <https://ghc.haskell.org/trac/ghc/wiki/Building/Windows/SSHD> by Sam Hocevar <sam@hocevar.net>
# Adapted from <https://gist.github.com/samhocevar/00eec26d9e9988d080ac> by David Macek
#
# Prerequisites:
# — a 64-bit installation of MSYS2 itself: https://msys2.org
# — some packages: pacman -S openssh cygrunsrv mingw-w64-x86_64-editrights
#
# Gotchas:
# — the log file will be /var/log/msys2_sshd.log
# — if you get error “sshd: fatal: seteuid XXX : No such device or address”
# in the logs, try “passwd -R” (with admin privileges)
# — if you get error “chown(/dev/pty1, XXX, YYY) failed: Invalid argument”
# in the logs, make sure your account and group names are detectable (see
# `id`); issues are often caused by having /etc/{passwd,group} or having
# a modified /etc/nsswitch.conf
#
# Changelog:
# 09 May 2020 — completely remove additional privileged user
# 16 Apr 2020 — remove additional privileged user
# — only touch /etc/{passwd,group} if they exist
# 27 Jun 2019 — rename service to msys2_sshd to avoid conflicts with Windows OpenSSH
# — use mkgroup.exe as suggested in the comments
# — fix a problem with CRLF and grep
# 24 Aug 2015 — run server with -e to redirect logs to /var/log/sshd.log
#
pacman -Syy
pacman -S openssh cygrunsrv mingw-w64-x86_64-editrights --noconfirm
set -e
#
# Configuration
#
UNPRIV_USER=sshd # DO NOT CHANGE; this username is hardcoded in the openssh code
UNPRIV_NAME="Privilege separation user for sshd"
EMPTY_DIR=/var/empty
#
# Check installation sanity
#
if ! /mingw64/bin/editrights -h >/dev/null; then
echo "ERROR: Missing 'editrights'. Try: pacman -S mingw-w64-x86_64-editrights."
exit 1
fi
if ! cygrunsrv -v >/dev/null; then
echo "ERROR: Missing 'cygrunsrv'. Try: pacman -S cygrunsrv."
exit 1
fi
if ! ssh-keygen -A; then
echo "ERROR: Missing 'ssh-keygen'. Try: pacman -S openssh."
exit 1
fi
#
# The unprivileged sshd user (for privilege separation)
#
add="$(if ! net user "${UNPRIV_USER}" >/dev/null; then echo "//add"; fi)"
if ! net user "${UNPRIV_USER}" ${add} //fullname:"${UNPRIV_NAME}" \
//homedir:"$(cygpath -w ${EMPTY_DIR})" //active:no; then
echo "ERROR: Unable to create Windows user ${UNPRIV_USER}"
exit 1
fi
#
# Add or update /etc/passwd entries
#
if test -f /etc/passwd; then
sed -i -e '/^'"${UNPRIV_USER}"':/d' /etc/passwd
SED='/^'"${UNPRIV_USER}"':/s?^\(\([^:]*:\)\{5\}\).*?\1'"${EMPTY_DIR}"':/bin/false?p'
mkpasswd -l -u "${UNPRIV_USER}" | sed -e 's/^[^:]*+//' | sed -ne "${SED}" \
>> /etc/passwd
mkgroup.exe -l > /etc/group
fi
#
# Finally, register service with cygrunsrv and start it
#
cygrunsrv -R msys2_sshd || true
cygrunsrv -I msys2_sshd -d "MSYS2 sshd" -p /usr/bin/sshd.exe -a "-D -e" -y tcpip
# The SSH service should start automatically when Windows is rebooted. You can
# manually restart the service by running `net stop msys2_sshd` + `net start msys2_sshd`
if ! net start msys2_sshd; then
echo "ERROR: Unable to start msys2_sshd service"
exit 1
fi
# Install miktex for latex support
Write-Output "Installing pandoc"
Write-Output "Downloading installer"
## download
$url = "https://github.com/jgm/pandoc/releases/download/2.10.1/pandoc-2.10.1-windows-x86_64.zip"
$output = 'c:\Windows\Temp\pandoc.zip'
$wcR = New-Object System.Net.WebClient
Write-Output "Downloading $url"
#Download the exe
$wcR.DownloadFile($url, $output)
Write-Output "Download completed $url"
$pandocDir = 'C:\pandoc\'
Write-Output "Install $output into $pandocDir"
Expand-Archive -LiteralPath $output -DestinationPath $pandocDir InvoiceUnzipped
if (Test-Path 'C:\pandoc\pandoc.exe')
{
Write-Output "pandoc installed"
}
else
{
throw "ERROR: Can't install pandoc"
}
# Add pandoc to PATH
$oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
$newPath = "$oldpath;C:\pandoc"
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
#!/bin/bash
echo "Installing system dependencies with pacman"
pacman --noconfirm -S mingw-w64-{i686,x86_64}-fftw \
mingw-w64-{i686,x86_64}-gdal \
mingw-w64-{i686,x86_64}-geos \
mingw-w64-{i686,x86_64}-libxml2 \
mingw-w64-{i686,x86_64}-tools-git \
mingw-w64-{i686,x86_64}-tools \
msys/vim
echo "Installing R packages"
echo "dir.create(Sys.getenv('R_LIBS_USER'), recursive=TRUE); \
.libPaths( c(Sys.getenv('R_LIBS_USER'), .libPaths()) ) ; \
install.packages(c( \
'deSolve', \
'sp', \
'rgeos', \
'fields', \
'MASS', \
'Matrix', \
'deldir', \
'pracma', \
'raster', \
'fftwtools', \
'mvtnorm', \
'rgdal', \
'sf', \
'splancs', \
'knitr', \
'rmarkdown', \
'testthat', \
'Rcpp', \
'RcppArmadillo', \
'fasterize', \
'roxygen2', \
'shiny', \
'htmltools', \
'shinydashboard', \
'ggplot2', \
'dplyr', \
'dbplyr', \
'DT', \
'magrittr', \
'devtools', \
'shinyjs', \
'stringi', \
'stringr', \
'jsonlite', \
'data.table', \
'htmlwidgets', \
'RSQLite', \
'BiocManager', \
'foreach', \
'doParallel', \
'mvtnorm', \
'mapdata', \
'proj4', \
'gstat', \
'automap', \
'RCALI', \
'rgenoud', \
'purrr' \
), \
dependencies=TRUE, \
repos='https://cran.biotools.fr')" > /c/Windows/Temp/install.R \
Rscript /c/Windows/Temp/install.R
Rscript -e "BiocManager::install(c('Biostrings', ask=FALSE))"
Rscript -e "update.packages(ask=FALSE, repos='https://cran.biotools.fr')"
# Install R
Write-Output "Installing R"
Write-Output "Downloading R Last Version"
## Download R engine for Windows machine
## download last relase name
$urlR = "https://cran.biotools.fr/bin/windows/base/release.html"
$outputR = 'c:\Windows\Temp\R-win.exe'
$wcR = New-Object System.Net.WebClient
$res = $wcR.DownloadString($urlR)
## get release name in the HTML page
$pos1 = $res.IndexOf("URL=")
$pos2 = $res.LastIndexOf('"')
$Rexe = $res.Substring($pos1+4, $pos2-$pos1-4)
$urlR = "https://cran.biotools.fr/bin/windows/base/" + $Rexe
Write-Output "Downloading $($urlR)"
#Download the exe
$wcR.DownloadFile($urlR, $outputR)
Write-Output "Download completed $Rexe"
$RDir = 'C:\R\'
Write-Output "Install $outputR into $RDir"
Start-Process -FilePath $outputR -ArgumentList "/VERYSILENT /DIR=$RDir" -Wait -NoNewWindow
if ( Test-Path "HKLM:\Software\R-core\R" ) {
$Rver = (Get-ItemProperty -Path "HKLM:\Software\R-core\R")."Current Version"
Write-Output "R version $($Rver) installed"
}
else {
throw "ERROR: Can't install R $($urlR)"
}
# Add R to PATH
$oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
$newPath = "$oldpath;C:\R\bin"
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
# Install R Tools 4.0
Write-Output "Installing Rtools 4.0"
Write-Output "Downloading Rtools Last Version"
## download last relase name
$urlRtools = "https://cran.biotools.fr/bin/windows/Rtools/rtools40-x86_64.exe"
$outputRtools = 'c:\Windows\Temp\Rtools-win.exe'
$wcR = New-Object System.Net.WebClient
Write-Output "Downloading $urlRtools"
#Download the exe
$wcR.DownloadFile($urlRtools, $outputRtools)
Write-Output "Download completed $urlRtools"
$RtoolsDir = 'C:\Rtools\'
Write-Output "Install $outputRtools into $RtoolsDir"
Start-Process -FilePath $outputRtools -ArgumentList "/VERYSILENT /DIR=$RtoolsDir" -Wait -NoNewWindow
if ( Test-Path "HKLM:\Software\R-core\Rtools" ) {
$Rtoolsver = (Get-ItemProperty -Path "HKLM:\Software\R-core\Rtools")."Current Version"
Write-Output "Rtools version $Rtoolsver installed"
}
else {
throw "ERROR: Can't install R $urlRtools"
}
# Add R to PATH
$oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
$newPath = "$oldpath;C:\Rtools\usr\bin"
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
[System.Environment]::SetEnvironmentVariable('MSYS2_PATH_TYPE', 'inherit', [System.EnvironmentVariableTarget]::Machine)
windows:
hosts:
windows10:
ansible_host: 127.0.0.1
vars:
ansible_user: vagrant
ansible_password: vagrant
ansible_port: 55985
ansible_connection: winrm
ansible_winrm_transport: basic
ansible_winrm_server_cert_validation: ignore
ansible_winrm_scheme: http
---
- name: Windows R tools
hosts: windows10
#remote_user: vagrant
#vars:
# ansible_user: vagrant
# ansible_password: vagrant
# ansible_connection: winrm
# ansible_winrm_transport: basic
# ansible_winrm_server_cert_validation: ignore
tasks:
- name: ping
win_ping:
- name: Install security updates
win_updates:
category_names:
- SecurityUpdates
use_scheduled_task: yes
- name: copy R script
win_copy:
src: ./files/install-r.ps1
dest: 'C:\Windows\Temp\'
remote_src: no
- name: Install R
win_command: powershell.exe -File C:\Windows\Temp\install-r.ps1
- name: copy Rtools script
win_copy:
src: ./files/install-rtools.ps1
dest: 'C:\Windows\Temp\'
remote_src: no
- name: Install Rtools4
win_command: powershell.exe -File C:\Windows\Temp\install-rtools.ps1
- name: copy msys2 config script
win_copy:
src: ./files/configure-msys2.sh
dest: 'C:\Windows\Temp\'
remote_src: no
- name: Configure MSYS2
win_command: C:\Rtools\usr\bin\bash.exe -l C:\Windows\Temp\configure-msys2.sh
- name: copy msys2 sshd install script
win_copy:
src: ./files/install-msys2-sshd.sh
dest: 'C:\Windows\Temp\'
remote_src: no
- name: Install MSYS2 ssh deamon
win_command: C:\Rtools\usr\bin\bash.exe -l C:\Windows\Temp\install-msys2-sshd.sh
- name: Enable Firewall for sshd
win_shell: |
netsh advfirewall firewall add rule name="SSHD" dir=in action=allow service=msys2_sshd enable=yes
netsh advfirewall firewall add rule name="SSHD" dir=in action=allow program="C:\Rtools\usr\bin\sshd.exe" enable=yes
netsh advfirewall firewall add rule name="ssh" dir=in action=allow protocol=TCP localport=22
- name: copy R packages script
win_copy:
src: ./files/install-r-packages.sh
dest: 'C:\Windows\Temp\'
remote_src: no
- name: Install R packages
win_command: C:\Rtools\usr\bin\bash.exe -l C:\Windows\Temp\install-r-packages.sh
- name: copy GitLab install script
win_copy:
src: ./files/install-gitlab-runner.ps1
dest: 'C:\Windows\Temp\'
remote_src: no
- name: Install GitLab Runner
win_command: powershell.exe -File C:\Windows\Temp\install-gitlab-runner.ps1
- name: copy MiKTeX install script
win_copy:
src: ./files/install-miktex.ps1
dest: 'C:\Windows\Temp\'
remote_src: no
- name: Install MiKTeX
win_command: powershell.exe -File C:\Windows\Temp\install-miktex.ps1
- name: copy pandoc install script
win_copy:
src: ./files/install-pandoc.ps1
dest: 'C:\Windows\Temp\'
remote_src: no
- name: Install Pandoc
win_command: powershell.exe -File C:\Windows\Temp\install-pandoc.ps1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment