Skip to content

Commit

Permalink
fix: cloud init (#25)
Browse files Browse the repository at this point in the history
* fix: cloud init script race condition problems

* test: fixup tests

* chore: increment version
  • Loading branch information
yanksyoon authored Sep 11, 2024
1 parent f154fc0 commit e256be4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[project]
name = "github-runner-image-builder"
version = "0.5.2"
version = "0.5.3"
authors = [
{ name = "Canonical IS DevOps", email = "[email protected]" },
]
Expand Down
22 changes: 15 additions & 7 deletions src/github_runner_image_builder/templates/cloud-init.sh.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

function configure_proxy() {
local proxy="$1"
if [[ -z "$proxy" ]]; then
Expand All @@ -25,6 +27,8 @@ table ip aproxy {
EOF
echo "Configuring aproxy"
/usr/bin/sudo snap set aproxy proxy=${proxy} listen=:8444;
echo "Wait for aproxy to start"
sleep 5
}

function install_apt_packages() {
Expand Down Expand Up @@ -53,7 +57,8 @@ function configure_system_users() {
/usr/bin/id -u ubuntu &>/dev/null || useradd --create-home ubuntu
echo "PATH=\$PATH:/home/ubuntu/.local/bin" >> /home/ubuntu/.profile
echo "PATH=\$PATH:/home/ubuntu/.local/bin" >> /home/ubuntu/.bashrc
/usr/sbin/groupadd microk8s
/usr/sbin/groupadd -f microk8s
/usr/sbin/groupadd -f docker
/usr/sbin/usermod --append --groups docker,microk8s,lxd,sudo ubuntu
}

Expand All @@ -69,11 +74,12 @@ function install_yarn() {
}

function install_yq() {
/usr/bin/sudo snap install go --classic
/usr/bin/git clone https://github.com/mikefarah/yq.git
/snap/bin/go build -C yq -o /usr/bin/yq
/usr/bin/rm -rf yq
/usr/bin/sudo snap remove go
/usr/bin/sudo -E /usr/bin/snap install go --classic
/usr/bin/sudo -E /usr/bin/git clone https://github.com/mikefarah/yq.git
/usr/bin/sudo -E /snap/bin/go mod tidy -C yq
/usr/bin/sudo -E /snap/bin/go build -C yq -o /usr/bin/yq
/usr/bin/sudo -E /usr/bin/rm -rf yq
/usr/bin/sudo -E /usr/bin/snap remove go
}

function install_github_runner() {
Expand Down Expand Up @@ -108,5 +114,7 @@ disable_unattended_upgrades
configure_system_users
configure_usr_local_bin
install_yarn
install_yq
# install yq with ubuntu user due to GOPATH related go configuration settings
export -f install_yq
su ubuntu -c "bash -c 'install_yq'"
install_github_runner "$github_runner_version" "$github_runner_arch"
22 changes: 15 additions & 7 deletions tests/unit/test_openstack_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ def test__generate_cloud_init_script():
# pylint: disable=R0801
== """#!/bin/bash
set -e
function configure_proxy() {
local proxy="$1"
if [[ -z "$proxy" ]]; then
Expand All @@ -489,6 +491,8 @@ def test__generate_cloud_init_script():
EOF
echo "Configuring aproxy"
/usr/bin/sudo snap set aproxy proxy=${proxy} listen=:8444;
echo "Wait for aproxy to start"
sleep 5
}
function install_apt_packages() {
Expand Down Expand Up @@ -518,7 +522,8 @@ def test__generate_cloud_init_script():
/usr/bin/id -u ubuntu &>/dev/null || useradd --create-home ubuntu
echo "PATH=\\$PATH:/home/ubuntu/.local/bin" >> /home/ubuntu/.profile
echo "PATH=\\$PATH:/home/ubuntu/.local/bin" >> /home/ubuntu/.bashrc
/usr/sbin/groupadd microk8s
/usr/sbin/groupadd -f microk8s
/usr/sbin/groupadd -f docker
/usr/sbin/usermod --append --groups docker,microk8s,lxd,sudo ubuntu
}
Expand All @@ -534,11 +539,12 @@ def test__generate_cloud_init_script():
}
function install_yq() {
/usr/bin/sudo snap install go --classic
/usr/bin/git clone https://github.com/mikefarah/yq.git
/snap/bin/go build -C yq -o /usr/bin/yq
/usr/bin/rm -rf yq
/usr/bin/sudo snap remove go
/usr/bin/sudo -E /usr/bin/snap install go --classic
/usr/bin/sudo -E /usr/bin/git clone https://github.com/mikefarah/yq.git
/usr/bin/sudo -E /snap/bin/go mod tidy -C yq
/usr/bin/sudo -E /snap/bin/go build -C yq -o /usr/bin/yq
/usr/bin/sudo -E /usr/bin/rm -rf yq
/usr/bin/sudo -E /usr/bin/snap remove go
}
function install_github_runner() {
Expand Down Expand Up @@ -577,7 +583,9 @@ def test__generate_cloud_init_script():
configure_system_users
configure_usr_local_bin
install_yarn
install_yq
# install yq with ubuntu user due to GOPATH related go configuration settings
export -f install_yq
su ubuntu -c "bash -c 'install_yq'"
install_github_runner "$github_runner_version" "$github_runner_arch"\
"""
)
Expand Down

0 comments on commit e256be4

Please sign in to comment.