Skip to content
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
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ RUN rm -f /etc/machine-id /var/lib/dbus/machine-id && \
ln -sf /etc/machine-id /var/lib/dbus/machine-id

RUN ssh-keygen -A
RUN sed -i -e 's/^#\?UseDNS .*/UseDNS no/' \
-e 's/^#\?GSSAPIAuthentication .*/GSSAPIAuthentication no/' \
/etc/ssh/sshd_config
RUN echo 'root:rootpwd' | chpasswd

COPY third-party/docker-systemctl-replacement/systemctl3.py /usr/local/bin/systemctl
Expand Down
1 change: 1 addition & 0 deletions ansible/roles/dependencies/tasks/retrieve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
force: true
depth: 1
version: token
accept_newhostkey: true


- name: Fetch the repository token value
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/key_exchange/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
hostvars[item.0][item.1]
~ ' '
~ (
lookup('pipe', 'ssh-keyscan -T 5 -t ecdsa ' ~ hostvars[item.0].ansible_host).split()[1:] | join(' ')
lookup('pipe', 'ssh-keyscan -q -T 5 -t ecdsa ' ~ hostvars[item.0].ansible_host).split()[1:3] | join(' ')
)
}}
with_nested:
Expand Down
27 changes: 23 additions & 4 deletions deployment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def sshLogin(ip, user='root'):
f'{user}@{ip}',
'-o',
'PasswordAuthentication=false',
'-o',
'BatchMode=yes',
'-o',
'ConnectTimeout=5',
'"exit"'
],
stdout=STDOUT,
Expand Down Expand Up @@ -386,6 +390,10 @@ def _vagrantList():
return [m.decode().strip().replace('discos_', '') for m in machines]

def _vboxList():
import shutil
if not shutil.which('vboxmanage'):
# VirtualBox not installed, e.g. Docker-only hosts
return []
cmd = subprocess.Popen(
"vboxmanage list vms | awk '{print $1}' | sed 's/\"//g'",
shell=True,
Expand All @@ -409,7 +417,7 @@ def machineList(inventory='development'):
return machines

def isRunning(name, inventory='development'):
if name not in machineList():
if name not in machineList() and name not in dockerMachineList(inventory):
error(f'Machine {name} unknown!')
return ping(getIp(name, inventory))

Expand Down Expand Up @@ -545,6 +553,15 @@ def dockerContainerRunning(name):
sp = _docker_output(['inspect', '-f', '{{.State.Running}}', name])
return sp.returncode == 0 and sp.stdout.strip() == 'true'

def dockerMachineList(inventory='development'):
"""Return the inventory machines that exist as Docker containers."""
try:
hosts, _, _ = parseInventory(inventory)
return [m for m in hosts if dockerContainerExists(m)]
except OSError:
# Docker not installed
return []

def dockerEnsureContainer(
name,
ip,
Expand All @@ -553,9 +570,11 @@ def dockerEnsureContainer(
):
"""Create container if missing, otherwise start it."""
if dockerContainerExists(name):
if dockerContainerRunning(name):
return 0
return dockerStartContainer(name, ip=ip)
if not dockerContainerRunning(name):
rc = dockerStartContainer(name, ip=ip)
if rc != 0:
return rc
return dockerInjectRSAKey(name)

rc = _docker([
'run', '-d',
Expand Down
4 changes: 3 additions & 1 deletion scripts/discos-login
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ parser.add_argument(
required=False,
default='discos'
)
parser.add_argument('machine', choices=deployment.machineList())
vms = list(deployment.machineList())
containers = [m for m in deployment.dockerMachineList() if m not in vms]
parser.add_argument('machine', choices=vms + containers)
args = parser.parse_args()

if deployment.isRunning(args.machine):
Expand Down
10 changes: 9 additions & 1 deletion scripts/discos-vnc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
$ discos-vnc -u observer console
"""
import os
import shutil
import subprocess
from multiprocessing import Process
from argparse import ArgumentParser
Expand All @@ -17,7 +18,8 @@ users = {
'discos': 1,
'observer': 2
}
machines = deployment.machineList()
machines = list(deployment.machineList())
machines += [m for m in deployment.dockerMachineList() if m not in machines]
try:
machines.remove('storage')
except:
Expand Down Expand Up @@ -61,6 +63,12 @@ def detach(vnc_command, ssh_command):
shell=True
)

if not shutil.which('vncviewer'):
deployment.error(
'vncviewer not found, install a TigerVNC viewer '
'(e.g. "sudo apt install tigervnc-viewer").'
)

if deployment.isRunning(args.machine):
remote_port = remote_starting_port + users[args.user]
local_port = local_starting_port
Expand Down
43 changes: 43 additions & 0 deletions scripts/discos.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#Requires -Version 7.3
<#
.SYNOPSIS
PowerShell wrappers for the DISCOS deployment tools installed in WSL2.

.DESCRIPTION
Ansible cannot run on Windows, so discos-deploy and the other tools run
inside a WSL2 distribution. These functions forward each call to that
distribution, passing the arguments through unchanged.

Requirements inside the distribution:
- the deployment package installed, so the tools are on the login
PATH (~/.local/bin);
- the Docker engine installed in the distribution itself, not Docker
Desktop: with Docker Desktop the container IPs (192.168.56.0/24)
are not reachable from WSL;
- REPOSITORY_TOKEN exported in ~/.profile, since a non-interactive
login shell does not read ~/.bashrc.

File arguments must be WSL paths (/mnt/d/... or ~/...), not Windows ones.

.EXAMPLE
. D:\Work\Develop\deployment\scripts\discos.ps1
discos-deploy manager:development --docker
discos-container status
discos-login manager

Add the first line to $PROFILE to load the functions in every session.
Set $env:DISCOS_WSL_DISTRO to use a distribution other than 'Ubuntu-26.04'.
#>

$DiscosWslDistro = if ($env:DISCOS_WSL_DISTRO) { $env:DISCOS_WSL_DISTRO } else { 'Ubuntu-26.04' }

# A login shell loads PATH and REPOSITORY_TOKEN from ~/.profile;
# "$0" "$@" hands the arguments over without re-parsing them.
$DiscosWslPrefix = @(
'-d', $DiscosWslDistro, '--cd', '~', '--exec',
'bash', '-lc', 'exec "$0" "$@"'
)

function discos-deploy { wsl.exe @DiscosWslPrefix discos-deploy @args }
function discos-container { wsl.exe @DiscosWslPrefix discos-container @args }
function discos-login { wsl.exe @DiscosWslPrefix discos-login @args }
Loading