diff --git a/.github/workflows/_ansible_e2e.yml b/.github/workflows/_ansible_e2e.yml index ae5cbb2f..5d4b3ec9 100644 --- a/.github/workflows/_ansible_e2e.yml +++ b/.github/workflows/_ansible_e2e.yml @@ -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 diff --git a/.github/workflows/ansible_e2e.yml b/.github/workflows/ansible_e2e.yml index 63847e21..bebef07e 100644 --- a/.github/workflows/ansible_e2e.yml +++ b/.github/workflows/ansible_e2e.yml @@ -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: diff --git a/Vagrantfile b/Vagrantfile index 83587b70..f428c1be 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -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: < /root/.ssh/deploy_key" < /dev/null -apt-get -q install -y --no-install-recommends git python3-pip python3-venv > /dev/null -apt-get -q clean - -echo "Install the deployment script itself" -cp -a "${deploy_script}" /usr/local/sbin/update-deployment -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" - -echo "Create a the deployment user" -adduser --disabled-password --gecos "" "${deploy_user}" -adduser "${deploy_user}" sudo -cat - > /etc/sudoers.d/update-deployment <> /home/${deploy_user}/.ssh/authorized_keys -restrict,command="sudo update-deployment ${deploy_target}" -EOF diff --git a/ansible/files/update-deployment b/ansible/files/update-deployment index 2129a482..498e009a 100644 --- a/ansible/files/update-deployment +++ b/ansible/files/update-deployment @@ -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}:" diff --git a/bootstrap-deployment.sh b/helpers/bootstrap-deployment.sh similarity index 96% rename from bootstrap-deployment.sh rename to helpers/bootstrap-deployment.sh index 91859d1b..40a83747 100644 --- a/bootstrap-deployment.sh +++ b/helpers/bootstrap-deployment.sh @@ -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}" diff --git a/scripts/ssh_loadkey.sh b/helpers/ssh_loadkey.sh similarity index 100% rename from scripts/ssh_loadkey.sh rename to helpers/ssh_loadkey.sh