Skip to content

Commit e62b83d

Browse files
committed
fix(ubuntu-24.04): make Ubuntu example work
* Switch to using the upstream deb archive for Docker * use awscli v2 * Provide a user-specific override for systemd * use machinectl to launch rootless docker
1 parent 5cb7209 commit e62b83d

File tree

2 files changed

+66
-60
lines changed

2 files changed

+66
-60
lines changed

examples/multi-runner/README.md

+27-26
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ terraform apply -var=module_version=<VERSION>
3232
cd -
3333
```
3434

35-
3635
Before running Terraform, ensure the GitHub app is configured. See the [configuration details](https://philips-labs.github.io/terraform-aws-github-runner/configuration/) for more details.
3736

3837
```bash
@@ -47,47 +46,49 @@ terraform output -raw webhook_secret
4746
```
4847

4948
<!-- BEGIN_TF_DOCS -->
49+
5050
## Requirements
5151

52-
| Name | Version |
53-
|------|---------|
54-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
55-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 5.27 |
56-
| <a name="requirement_local"></a> [local](#requirement\_local) | ~> 2.0 |
57-
| <a name="requirement_random"></a> [random](#requirement\_random) | ~> 3.0 |
52+
| Name | Version |
53+
| ------------------------------------------------------------------------ | -------- |
54+
| <a name="requirement_terraform"></a> [terraform](#requirement_terraform) | >= 1.3.0 |
55+
| <a name="requirement_aws"></a> [aws](#requirement_aws) | ~> 5.27 |
56+
| <a name="requirement_local"></a> [local](#requirement_local) | ~> 2.0 |
57+
| <a name="requirement_random"></a> [random](#requirement_random) | ~> 3.0 |
5858

5959
## Providers
6060

61-
| Name | Version |
62-
|------|---------|
63-
| <a name="provider_random"></a> [random](#provider\_random) | 3.6.0 |
61+
| Name | Version |
62+
| --------------------------------------------------------- | ------- |
63+
| <a name="provider_random"></a> [random](#provider_random) | 3.6.0 |
6464

6565
## Modules
6666

67-
| Name | Source | Version |
68-
|------|--------|---------|
69-
| <a name="module_base"></a> [base](#module\_base) | ../base | n/a |
70-
| <a name="module_runners"></a> [runners](#module\_runners) | ../../modules/multi-runner | n/a |
71-
| <a name="module_webhook_github_app"></a> [webhook\_github\_app](#module\_webhook\_github\_app) | ../../modules/webhook-github-app | n/a |
67+
| Name | Source | Version |
68+
| ----------------------------------------------------------------------------------------- | -------------------------------- | ------- |
69+
| <a name="module_base"></a> [base](#module_base) | ../base | n/a |
70+
| <a name="module_runners"></a> [runners](#module_runners) | ../../modules/multi-runner | n/a |
71+
| <a name="module_webhook_github_app"></a> [webhook_github_app](#module_webhook_github_app) | ../../modules/webhook-github-app | n/a |
7272

7373
## Resources
7474

75-
| Name | Type |
76-
|------|------|
75+
| Name | Type |
76+
| ----------------------------------------------------------------------------------------------------- | -------- |
7777
| [random_id.random](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource |
7878

7979
## Inputs
8080

81-
| Name | Description | Type | Default | Required |
82-
|------|-------------|------|---------|:--------:|
83-
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region to deploy to | `string` | `"eu-west-1"` | no |
84-
| <a name="input_environment"></a> [environment](#input\_environment) | Environment name, used as prefix | `string` | `null` | no |
85-
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br/> id = string<br/> key_base64 = string<br/> })</pre> | n/a | yes |
81+
| Name | Description | Type | Default | Required |
82+
| ------------------------------------------------------------------ | -------------------------------- | --------------------------------------------------------------------- | ------------- | :------: |
83+
| <a name="input_aws_region"></a> [aws_region](#input_aws_region) | AWS region to deploy to | `string` | `"eu-west-1"` | no |
84+
| <a name="input_environment"></a> [environment](#input_environment) | Environment name, used as prefix | `string` | `null` | no |
85+
| <a name="input_github_app"></a> [github_app](#input_github_app) | GitHub for API usages. | <pre>object({<br/> id = string<br/> key_base64 = string<br/> })</pre> | n/a | yes |
8686

8787
## Outputs
8888

89-
| Name | Description |
90-
|------|-------------|
91-
| <a name="output_webhook_endpoint"></a> [webhook\_endpoint](#output\_webhook\_endpoint) | n/a |
92-
| <a name="output_webhook_secret"></a> [webhook\_secret](#output\_webhook\_secret) | n/a |
89+
| Name | Description |
90+
| ----------------------------------------------------------------------------------- | ----------- |
91+
| <a name="output_webhook_endpoint"></a> [webhook_endpoint](#output_webhook_endpoint) | n/a |
92+
| <a name="output_webhook_secret"></a> [webhook_secret](#output_webhook_secret) | n/a |
93+
9394
<!-- END_TF_DOCS -->

examples/multi-runner/templates/user-data.sh

+39-34
Original file line numberDiff line numberDiff line change
@@ -15,67 +15,72 @@ set -x
1515
${pre_install}
1616

1717
# Install AWS CLI
18-
apt-get update
19-
DEBIAN_FRONTEND=noninteractive apt-get install -y \
20-
awscli \
18+
apt-get -q update
19+
DEBIAN_FRONTEND=noninteractive apt-get install -q -y \
2120
build-essential \
21+
ca-certificates \
2222
curl \
2323
git \
2424
iptables \
2525
jq \
26+
systemd-container \
2627
uidmap \
2728
unzip \
2829
wget
2930

31+
install -m 0755 -d /etc/apt/keyrings
32+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
33+
chmod a+r /etc/apt/keyrings/docker.asc
34+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" > /etc/apt/sources.list.d/docker.list
35+
apt-get -q update
36+
apt-get -q -y install docker-ce docker-ce-cli containerd.io docker-ce-rootless-extras docker-buildx-plugin docker-compose-plugin
37+
systemctl disable --now docker.socket docker.service
38+
39+
# avoid /tmp, might be mounted no-exec
40+
curl -fsSL -o "awscliv2.zip" "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"
41+
unzip -q awscliv2.zip
42+
aws/install
43+
rm -rf aws awscliv2.zip
44+
3045
user_name=ubuntu
3146
user_id=$(id -ru $user_name)
3247

3348
# install and configure cloudwatch logging agent
34-
wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
35-
dpkg -i -E ./amazon-cloudwatch-agent.deb
36-
amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c ssm:${ssm_key_cloudwatch_agent_config}
49+
curl -fsSL -o "/tmp/amazon-cloudwatch-agent.deb" https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
50+
dpkg -i -E /tmp/amazon-cloudwatch-agent.deb
51+
rm -f /tmp/amazon-cloudwatch-agent.deb
52+
amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c "ssm:${ssm_key_cloudwatch_agent_config}"
3753

3854
# configure systemd for running service in users accounts
39-
cat >/etc/systemd/[email protected] <<-EOF
40-
41-
[Unit]
42-
Description=User Manager for UID %i
43-
After=user-runtime-dir@%i.service
44-
Wants=user-runtime-dir@%i.service
45-
46-
[Service]
47-
LimitNOFILE=infinity
48-
LimitNPROC=infinity
49-
User=%i
50-
PAMName=systemd-user
51-
Type=notify
52-
53-
[Install]
54-
WantedBy=default.target
55-
55+
mkdir -p /etc/systemd/system/user-$user_id.slice.d
56+
cat > /etc/systemd/system/user-$user_id.slice.d/resources.conf <<- EOF
57+
[Slice]
58+
TasksMax=infinity
5659
EOF
57-
58-
echo export XDG_RUNTIME_DIR=/run/user/$user_id >>/home/$user_name/.bashrc
60+
mkdir -p /home/$user_name/.config/systemd/
61+
cat > /home/$user_name/.config/systemd/user.conf <<- EOF
62+
[Manager]
63+
DefaultLimitNOFILE=infinity
64+
DefaultLimitNPROC=infinity
65+
EOF
66+
chown $user_name:$user_name /home/$user_name/.config/systemd/user.conf /home/$user_name/.config/systemd /home/$user_name/.config/
5967

6068
systemctl daemon-reload
61-
systemctl enable [email protected]
62-
systemctl start [email protected]
6369

64-
curl -fsSL https://get.docker.com/rootless >>/opt/rootless.sh && chmod 755 /opt/rootless.sh
65-
su -l $user_name -c /opt/rootless.sh
66-
echo export DOCKER_HOST=unix:///run/user/$user_id/docker.sock >>/home/$user_name/.bashrc
67-
echo export PATH=/home/$user_name/bin:$PATH >>/home/$user_name/.bashrc
70+
echo export XDG_RUNTIME_DIR="/run/user/$user_id" >> "/home/$user_name/.bashrc"
6871

6972
# Run docker service by default
7073
loginctl enable-linger $user_name
71-
su -l $user_name -c "systemctl --user enable docker"
74+
machinectl shell "$user_name@.host" /usr/bin/dockerd-rootless-setuptool.sh install
75+
echo export DOCKER_HOST="unix:///run/user/$user_id/docker.sock" >> "/home/$user_name/.bashrc"
76+
echo export PATH="/home/$user_name/bin:$PATH" >> "/home/$user_name/.bashrc"
7277

7378
${install_runner}
7479

7580
# config runner for rootless docker
7681
cd /opt/actions-runner/
77-
echo DOCKER_HOST=unix:///run/user/$user_id/docker.sock >>.env
78-
echo PATH=/home/$user_name/bin:$PATH >>.env
82+
echo DOCKER_HOST="unix:///run/user/$user_id/docker.sock" >> .env
83+
echo PATH="/home/$user_name/bin:$PATH" >> .env
7984

8085
${post_install}
8186

0 commit comments

Comments
 (0)