Skip to content

Commit

Permalink
Back port a few fixes from mw-projects (#187)
Browse files Browse the repository at this point in the history
* Back port a few fixes from mw-projects
* Fix the scope of the workflow and move the helper script
* Ensure the repo is set as an env. variable
---------

Signed-off-by: Benoit Donneaux <[email protected]>
  • Loading branch information
btlogy authored Sep 16, 2024
1 parent 8ef829e commit 58d2d9f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 65 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/_ansible_e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ jobs:
- name: Start Vagrant boxe(s)
id: vagrant_start
run: |
# Start the Vagrant guest(s) if needed
# Prepare an env. variable required for the Vagrantfile
export DEPLOYMENT_REPO="$(echo ${{ github.repository }} | cut -d/ -f2)"
echo "DEPLOYMENT_REPO=${DEPLOYMENT_REPO}" >> $GITHUB_ENV
# Start the Vagrant guest(s)
vagrant up --provider=libvirt --no-tty
# Save the SSH config for later
vagrant ssh-config | grep -v -E "(User|IdentityFile|IdentitiesOnly)" > ssh.conf
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/ansible_e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@
name: Ansible e2e

on:
push:
branches:
- main
- stable
paths:
- '.github/workflows/ansible.yml'
- 'ansible/**'
- 'docker/ansible*/*'
pull_request:
paths:
- '.github/workflows/ansible.yml'
- '.github/workflows/*ansible_e2e.yml'
- 'ansible/**'
- 'docker/ansible*/*'
- 'helpers/bootstrap-deployment.sh'

jobs:
call-workflow-passing-data:
Expand Down
47 changes: 41 additions & 6 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,65 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

host_name = ENV.has_key?('DEPLOYMENT_TARGET') ? ENV['DEPLOYMENT_TARGET'] : 'base-local'
repo_name = ENV.has_key?('DEPLOYMENT_REPO') ? ENV['DEPLOYMENT_REPO'] : abort("Repo is undefinned!")
ssh_key = ENV.has_key?('DEPLOYMENT_SSH_KEY') ? ENV['DEPLOYMENT_SSH_KEY'] : abort("SSH key is undefined!")

# Get a dedicated LibVirt pool name or use default one
pool_name = ENV.has_key?('POOL_NAME') ? ENV['POOL_NAME'] : 'default'
# For instance, one could create such pool beforehand as follows:
# export POOL_NAME=morph_local_$(id -un)
# POOL_PATH="/path/to/your/storage"
# mkdir -p "${POOL_PATH}"
# sudo virsh pool-define-as ${POOL_NAME} --type dir --target "${POOL_PATH}"
# sudo virsh pool-autostart ${POOL_NAME}
# sudo virsh pool-start ${POOL_NAME}

Vagrant.configure("2") do |config|
config.vm.define ENV['DEPLOYMENT_TARGET']
config.vm.hostname = ENV['DEPLOYMENT_TARGET']
config.vm.define host_name
config.vm.hostname = host_name
config.vm.box = "debian/bookworm64"
config.vm.box_version = "12.20240905.1"
config.vm.box_check_update = false

# Tune LibVirt/QEmu guests
config.vm.provider :libvirt do |domain|
# The default of one CPU should work
# Increase to speed up boot/push/deploy
domain.cpus = 2
# The default memory size should work in most case
domain.memory = 2048

# Using a specific pool helps to manage the disk space
domain.storage_pool_name = pool_name
domain.snapshot_pool_name = pool_name

# No need of graphics - better use serial
# domain.graphics_type = "none"
# domain.video_type = "none"
end

# Avoid the default synchronization
config.vm.synced_folder ".", "/vagrant", disabled: true

# Provision the repo where the deployment script expects it
config.vm.synced_folder ".", "/root/#{ENV['DEPLOYMENT_REPO']}",
config.vm.synced_folder ".", "/root/#{repo_name}",
type: "nfs",
nfs_version: 4,
nfs_udp: false

config.vm.provision "shell", name: "Private key to checkout the code",
inline: <<EOS
sudo test -d /root/.ssh || { sudo mkdir /root/.ssh; sudo chmod 0700 /root/.ssh; }
sudo sh -c "cat - > /root/.ssh/deploy_key" <<EOF
#{ENV['DEPLOYMENT_SSH_KEY']}
#{ssh_key}
EOF
sudo chmod 0600 /root/.ssh/deploy_key
EOS

config.vm.provision "shell", name: "Requirements for pull-mode deployment",
path: "ansible/files/prepare-deployment",
path: "helpers/bootstrap-deployment.sh",
args: [
"/root/#{ENV['DEPLOYMENT_REPO']}/ansible/files/update-deployment",
"/root/#{repo_name}/ansible/files/update-deployment",
]
end
46 changes: 0 additions & 46 deletions ansible/files/prepare-deployment

This file was deleted.

4 changes: 2 additions & 2 deletions ansible/files/update-deployment
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ test -d "${HOME}/.ssh" || mkdir "${HOME}/.ssh"
echo "${url_host} ${url_host_key}" > "${HOME}/.ssh/known_hosts"

# Generate an ssh key to checkout the code if not provided
test -f "${git_ssh_key}" || ssh-keygen -q -t ed25519 -f "${git_ssh_key}" -N=""
test -f "${git_ssh_key}" || ssh-keygen -q -t ed25519 -f "${git_ssh_key}" -N ""
export GIT_SSH_COMMAND="ssh -i ${git_ssh_key}"
# Derive the public key if not provided
test -f "${git_ssh_key}.pub" || ssh-keygen -y -f /root/.ssh/git_deploy_key -P="" \
test -f "${git_ssh_key}.pub" || ssh-keygen -y -f /root/.ssh/git_deploy_key -P "" \
> "${git_ssh_key}.pub"
# Print the public key, in case it has not been yet authorized to checkout
echo "Public key used to access ${url_host}:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ chmod +x /usr/local/sbin/update-deployment

echo "Generate public part of the key if needed"
test -f "${deploy_key}.pub" \
|| ssh-keygen -y -f "${deploy_key}" -P="" > "${deploy_key}.pub"
|| ssh-keygen -y -f "${deploy_key}" -P "" > "${deploy_key}.pub"

echo "Create a the deployment user"
adduser --disabled-password --gecos "" "${deploy_user}"
Expand Down
File renamed without changes.

0 comments on commit 58d2d9f

Please sign in to comment.