Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Base Image to Amazon Linux 2023 #1122

Merged
merged 39 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9cc368e
Switch base AMI to Amazon Linux 2023
triarius Mar 20, 2023
0a59a3b
Bump packer to v1.8.6
triarius Mar 21, 2023
2a72f01
Remove python2 and install aws-cli v2 from repos
triarius Mar 21, 2023
883da24
Replace docker-gc cron jobs with systemd timers
triarius May 30, 2023
6c6bd3e
Remove docker-compose v1
triarius May 30, 2023
25a9da8
Remove qemu and qemu-user-static packages
triarius May 30, 2023
23b3db8
Remove upgrade of signature
triarius Jun 5, 2023
6ca45e4
Switch to manual install of goss and install dgoss as well
triarius Jun 5, 2023
4f99405
Fewer tabs in bk-install-elastic-stack.sh
triarius Jun 5, 2023
2143bda
Use a single command to start and enable systemd units
triarius Jun 5, 2023
eca2fe2
Bump docker compose to v2.18.1 and install docker from repos
triarius Jun 5, 2023
3c57da5
Convert refresh authorized_keys cron into systemd timer
triarius Jun 5, 2023
9c0d053
Use curl instead of ec2-metadata tool
triarius Jun 5, 2023
2d32dfc
Consolidate packer install scripts
triarius Jun 5, 2023
734e9ce
Install all utils in single command
triarius Jun 5, 2023
214f529
Remove ssm plugin
triarius Jun 5, 2023
b8a23e1
Update sshd home dir expectation
triarius Jun 5, 2023
e8e41a8
Update expected docker group id
triarius Jun 5, 2023
6ecfbf0
Replace cloud-boothook with x-shellscript
triarius Jun 5, 2023
f12eed1
Update subgid for docker group
triarius Jun 5, 2023
406d9ff
Fix logging and standardise formatting in some startup scripts
triarius Jun 5, 2023
07a7a1b
Add a comment about userns
triarius Jun 6, 2023
6a7667c
Remove unnecessary quotes in goss file
triarius Jun 6, 2023
198c8bc
Add checks that docker is configured correctly
triarius Jun 6, 2023
96510d4
Remove docker info goss test and update comments
triarius Jun 6, 2023
da56b78
Escape go templating
triarius Jun 6, 2023
b4be589
Restart docker daemon after setting userns
triarius Jun 6, 2023
2e25e00
Remove default instance in systemd
triarius Jun 6, 2023
e1e9479
Install, start, and enable ssm-agent
triarius Jun 6, 2023
c0b6d97
Print more informative steps during docker installation
triarius Jun 6, 2023
d290926
Install qemu-binfmt using docker container on boot
triarius Jun 6, 2023
7755a93
Add GOSS test for amazon-ssm-agent
triarius Jun 6, 2023
974b2b9
Remove goss timeouts
triarius Jun 6, 2023
b4afa48
Test multiarch with goss
triarius Jun 6, 2023
3e4cd66
Rightsize test instances
triarius Jun 6, 2023
00e7a8b
Add explicit 30s timeout to all goss assertions that pull docker images
triarius Jun 6, 2023
9272fb7
Change docker info output to show which elements of a list are presen…
triarius Jun 7, 2023
d0bb6f2
Fix goss docker info commands
triarius Jun 7, 2023
3c7c3a5
Use case statement to determine ARCH in packer/linux/conf/bin/bk-inst…
triarius Jun 7, 2023
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
10 changes: 5 additions & 5 deletions .buildkite/steps/launch.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -eu
set -euo pipefail

os="${1:-linux}"
arch="${2:-amd64}"
Expand All @@ -22,16 +22,16 @@ echo "Using AMI $image_id for $os/$arch"
service_role="$(buildkite-agent meta-data get service-role-arn)"
echo "Using service role ${service_role}"

instance_type="t3.nano"
instance_type="t3.small"
instance_disk="10"

if [[ "$os" == "windows" ]] ; then
if [[ "$os" == "windows" ]]; then
instance_type="m5.large"
instance_disk="100"
fi

if [[ "$arch" == "arm64" ]] ; then
instance_type="m6g.large"
if [[ "$arch" == "arm64" ]]; then
instance_type="t4g.small"
fi

cat << EOF > config.json
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
VERSION = $(shell git describe --tags --candidates=1)
SHELL = /bin/bash -o pipefail

PACKER_VERSION ?= 1.6.2
PACKER_VERSION ?= 1.8.6
PACKER_LINUX_FILES = $(exec find packer/linux)
PACKER_WINDOWS_FILES = $(exec find packer/windows)

Expand Down
64 changes: 48 additions & 16 deletions goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ service:
enabled: true
running: true

amazon-ssm-agent:
enabled: true
running: true

docker:
enabled: true
running: true
Expand Down Expand Up @@ -73,7 +77,7 @@ user:
gid: 74
groups:
- sshd
home: /var/empty/sshd
home: /usr/share/empty.sshd
shell: /sbin/nologin

group:
Expand All @@ -83,7 +87,7 @@ group:

docker:
exists: true
gid: 1001
gid: 993

sshd:
exists: true
Expand All @@ -100,34 +104,62 @@ process:
running: true

command:
"aws --version":
aws --version:
exit-status: 0

"git --version":
git --version:
exit-status: 0

"git-lfs --version":
git-lfs --version:
exit-status: 0

"/etc/cron.hourly/docker-low-disk-gc":
systemctl is-enabled docker-gc.timer:
exit-status: 0

"/etc/cron.hourly/docker-gc":
/usr/local/bin/docker-gc:
exit-status: 0

# Checks that docker is running
"docker info":
systemctl is-enabled docker-low-disk-gc.timer:
exit-status: 0
timeout: 30000 # it can take some time for the daemon to start

# Checks that docker containers can run
"docker run --rm -v /var/run/docker.sock:/var/run/docker.sock docker:latest version":
/usr/local/bin/docker-low-disk-gc:
exit-status: 0
timeout: 30000 # it can take some time to download the image

# Checks that permissions
'sh -c "docker run --rm -v \"$PWD:/pwd\" alpine:latest touch /pwd/test && stat -c %U:%G test"':
# Check docker userns is enabled
docker info --format='{{ `{{range .SecurityOptions}}{{if eq . "name=userns"}}{{"success"}}{{end}}{{end}}` }}':
triarius marked this conversation as resolved.
Show resolved Hide resolved
exit-status: 0
timeout: 30000 # it can take some time to download the image
timeout: 30000
stdout:
- success
triarius marked this conversation as resolved.
Show resolved Hide resolved

# Check docker plugins are installed
docker info --format=$'{{ `{{range .ClientInfo.Plugins}}{{if eq .Name "buildx"}}success\n{{end}}{{if eq .Name "compose" }}success{{end}}{{end}}` }}':
exit-status: 0
timeout: 30000
stdout:
- success
- success
triarius marked this conversation as resolved.
Show resolved Hide resolved

# Check that docker containers can run
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock docker:latest version:
exit-status: 0
timeout: 30000

# Check that userns allows writing as buildkite-agent
sh -c 'docker run --rm -v "$PWD:/pwd" alpine:latest touch /pwd/test && stat -c %U:%G test' && rm test:
exit-status: 0
timeout: 30000
stdout:
- buildkite-agent:docker

docker run --rm -t arm64v8/ubuntu uname -m:
exit-status: 0
timeout: 30000
stdout:
- aarch64

docker run --rm -t amd64/ubuntu uname -m:
exit-status: 0
timeout: 30000
stdout:
- x86_64
30 changes: 4 additions & 26 deletions packer/linux/buildkite-ami.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"region": "{{user `region`}}",
"source_ami_filter": {
"filters": {
"name": "amzn2-ami-kernel-5.10-hvm-2.0.*-gp2",
"name": "al2023-ami-minimal-2023.0.*.*-kernel-*",
"architecture": "{{user `arch`}}",
"virtualization-type": "hvm"
},
Expand All @@ -21,7 +21,7 @@
"instance_type": "{{user `instance_type`}}",
"ssh_username": "ec2-user",
"ami_name": "buildkite-stack-linux-{{user `arch`}}-{{isotime | clean_resource_name}}",
"ami_description": "Buildkite Elastic Stack (Amazon Linux 2 LTS w/ docker)",
"ami_description": "Buildkite Elastic Stack (Amazon Linux 2023 w/ docker)",
"ami_groups": ["all"]
}
],
Expand All @@ -44,10 +44,6 @@
"type": "shell",
"script": "scripts/install-cloudwatch-agent.sh"
},
{
"type": "shell",
"script": "scripts/install-lifecycled.sh"
},
{
"type": "shell",
"script": "scripts/install-docker.sh"
Expand All @@ -58,29 +54,11 @@
},
{
"type": "shell",
"script": "scripts/install-s3secrets-helper.sh"
},
{
"type": "shell",
"script": "scripts/install-git-lfs.sh"
},
{
"type": "shell",
"script": "scripts/install-session-manager-plugin.sh"
},
{
"type": "shell",
"script": "scripts/install-nvme-cli.sh"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of these have been folded into other scripts.

},
{
"type": "shell",
"script": "scripts/upgrade-kernel.sh"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

"script": "scripts/install-buildkite-utils.sh"
},
{
"type": "shell",
"inline": [
"rm /home/ec2-user/.ssh/authorized_keys"
]
"inline": ["rm /home/ec2-user/.ssh/authorized_keys"]
}
]
}
12 changes: 7 additions & 5 deletions packer/linux/conf/bin/bk-configure-docker.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#!/bin/bash
# shellcheck disable=SC2094
set -euo pipefail
set -euxo pipefail

## Configures docker before system starts

# Write to system console and to our log file
# See https://alestic.com/2010/12/ec2-user-data-output/
exec > >(tee -a /var/log/elastic-stack.log|logger -t user-data -s 2>/dev/console) 2>&1
exec > >(tee -a /var/log/elastic-stack.log | logger -t user-data -s 2>/dev/console) 2>&1

# Set user namespace remapping in config
if [[ "${DOCKER_USERNS_REMAP:-false}" == "true" ]] ; then
if [[ "${DOCKER_USERNS_REMAP:-false}" == "true" ]]; then
cat <<< "$(jq '."userns-remap"="buildkite-agent"' /etc/docker/daemon.json)" > /etc/docker/daemon.json
fi

# Set experimental in config
if [[ "${DOCKER_EXPERIMENTAL:-false}" == "true" ]] ; then
if [[ "${DOCKER_EXPERIMENTAL:-false}" == "true" ]]; then
cat <<< "$(jq '.experimental=true' /etc/docker/daemon.json)" > /etc/docker/daemon.json
fi

# Move docker root to the ephemeral device
if [[ "${BUILDKITE_ENABLE_INSTANCE_STORAGE:-false}" == "true" ]] ; then
if [[ "${BUILDKITE_ENABLE_INSTANCE_STORAGE:-false}" == "true" ]]; then
cat <<< "$(jq '."data-root"="/mnt/ephemeral/docker"' /etc/docker/daemon.json)" > /etc/docker/daemon.json
fi

# Customise address pools
cat <<<"$(jq '."default-address-pools"=[{"base":"172.17.0.0/12","size":20},{"base":"192.168.0.0/16","size":24}]' /etc/docker/daemon.json)" >/etc/docker/daemon.json

systemctl restart docker
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to restart docker to get the new settings.

Loading