Skip to content

Commit 642a88e

Browse files
committed
env/linux-arm64/aws: add linux-arm64-aws builder image
This adds the ability for linux-arm64 builder images to be created on AWS. Instead of writing a bash script which would create an image with all of the dependencies on it, this experiments with using packer to create the image. The image is configured to install and daemonize rundockerbuildlet. Rundockerbuildlet will download and run the latest stage0 image. Stage0 then downloads the latest buildlet and begins processing jobs. A follow-up change will enable rundockerbuildlet to initialize the buildlet without setting it in reverse mode. Updates golang/go#36841 Change-Id: Iee07c2600e2b91d34f5e6a1e062f763833d79904 Reviewed-on: https://go-review.googlesource.com/c/build/+/228799 Run-TryBot: Carlos Amedee <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Alexander Rakoczy <[email protected]>
1 parent 916311c commit 642a88e

File tree

7 files changed

+221
-1
lines changed

7 files changed

+221
-1
lines changed

cmd/buildlet/stage0/stage0.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ Download:
232232
}
233233
sleepFatalf("Error running buildlet: %v", err)
234234
}
235-
236235
}
237236

238237
// reverseHostTypeArgs returns the default arguments for the buildlet

env/linux-arm64/aws/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2020 The Go Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
5+
FROM debian:buster
6+
7+
ENV DEBIAN_FRONTEND noninteractive
8+
9+
RUN apt-get update && \
10+
apt-get install --yes \
11+
gcc curl strace \
12+
ca-certificates netbase \
13+
procps lsof psmisc \
14+
openssh-server
15+
16+
RUN mkdir /usr/local/go-bootstrap && \
17+
curl --silent https://storage.googleapis.com/go-builder-data/gobootstrap-linux-arm64.tar.gz | \
18+
tar -C /usr/local/go-bootstrap -zxv
19+
20+
ENV GOROOT_BOOTSTRAP /usr/local/go-bootstrap
21+
RUN curl -o /usr/local/bin/stage0 https://storage.googleapis.com/go-builder-data/buildlet-stage0.linux-arm64 && \
22+
chmod +x /usr/local/bin/stage0
23+
24+
ENV GO_BUILDER_ENV host-linux-arm64-aws
25+
26+
CMD ["/usr/local/bin/stage0"]

env/linux-arm64/aws/Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2020 The Go Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
5+
# Compiled stage0 binary must be in working dir.
6+
7+
STAGING_BUCKET=dev-go-builder-data
8+
PROD_BUCKET=go-builder-data
9+
10+
staging: Dockerfile
11+
docker build --build-arg -t gobuilder-arm64-aws:latest .
12+
13+
prod: Dockerfile
14+
docker build --build-arg -t gobuilder-arm64-aws:latest .
15+
16+
env-var-check:
17+
ifndef AWS_ACCESS_KEY_ID
18+
$(error AWS_ACCESS_KEY_ID env var is not set)
19+
endif
20+
21+
ifndef AWS_SECRET_ACCESS_KEY
22+
$(error AWS_SECRET_ACCESS_KEY env var is not set)
23+
endif
24+
25+
create-aws-image: env-var-check
26+
packer build packer_image_aws_arm64.json

env/linux-arm64/aws/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# AWS Linux ARM64 Builders
2+
3+
## Machines
4+
5+
The AWS builders use the a1 instance types which are arm64 based machines of varying specifications.
6+
The base type used will be a1.xlarge 4 vCPUs, 8192 MiB.
7+
8+
## Machine Image
9+
10+
Machine images are stored on AWS EBS service as a snapshot. New VMs can use the snapshot as an image
11+
by providing the AMI ID as the base image when a new VM is created. The machine image will be configured
12+
to install and initialize rundockerbuildlet.
13+
14+
### Creating a New Image
15+
16+
Requirements:
17+
18+
Two environmental variables are required to be set before initiating the command:
19+
`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` should be set with the appropriate values.
20+
21+
The [packer](https://www.packer.io) binary should be in `PATH`.
22+
23+
Command:
24+
25+
`make create-aws-image`
26+
27+
or
28+
29+
`AWS_ACCESS_KEY_ID=<id> AWS_SECRET_ACCESS_KEY=<secret> make create-aws-image`
30+
31+
## Buildlet Image
32+
33+
Buildlet images with stage0 installed can be created via:
34+
35+
Prod:
36+
37+
`make prod`
38+
39+
Staging:
40+
41+
`make staging`
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"variables": {
3+
"aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}",
4+
"aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",
5+
"region": "us-east-2"
6+
},
7+
"builders": [
8+
{
9+
"type": "amazon-ebs",
10+
"access_key": "{{user `aws_access_key`}}",
11+
"ami_name": "go-linux-arm64-{{timestamp}}",
12+
"ami_description": "Image for linux-arm64 Go builder",
13+
"instance_type": "a1.medium",
14+
"region": "{{user `region`}}",
15+
"secret_key": "{{user `aws_secret_key`}}",
16+
"source_ami": "ami-0b1808bb4e7ed5ff5",
17+
"decode_authorization_messages": true,
18+
"ssh_username": "admin",
19+
"tags": {
20+
"Name": "Debian",
21+
"Created": "{{isotime \"2006-01-02\"}}",
22+
"OS": "Debian 10 Buster",
23+
"Release": "Latest",
24+
"Base_AMI_Name": "{{ .SourceAMIName }}",
25+
"Extra": "{{ .SourceAMITags.TagName }}",
26+
"Description": "{{user `description`}}"
27+
},
28+
"launch_block_device_mappings": [
29+
{
30+
"device_name": "/dev/xvda",
31+
"volume_size": 10,
32+
"volume_type": "gp2",
33+
"delete_on_termination": true
34+
}
35+
]
36+
}
37+
],
38+
"provisioners": [
39+
{
40+
"type": "file",
41+
"source": "./rundockerbuildlet.service",
42+
"destination": "/tmp/rundockerbuildlet.service"
43+
},
44+
{
45+
"type": "shell",
46+
"script": "./prepare_image.sh"
47+
}
48+
]
49+
}

env/linux-arm64/aws/prepare_image.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2020 The Go Authors. All rights reserved.
4+
# Use of this source code is governed by a BSD-style
5+
# license that can be found in the LICENSE file.
6+
7+
#
8+
# Installs all dependencies for a Debian 10 linux arm64 Host.
9+
#
10+
11+
set -euxo pipefail
12+
13+
TMP_DIR="$(mktemp -d)"
14+
GO_PATH="$TMP_DIR/gopath"
15+
16+
sudo apt-get update && sudo apt-get upgrade -y
17+
18+
sudo apt-get install -y \
19+
apt-transport-https \
20+
ca-certificates \
21+
curl \
22+
gnupg-agent \
23+
gnupg2 \
24+
jq \
25+
software-properties-common
26+
27+
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
28+
29+
sudo add-apt-repository "deb [arch=arm64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
30+
31+
sudo apt-get update
32+
33+
sudo apt-get install -y \
34+
docker-ce \
35+
docker-ce-cli \
36+
containerd.io
37+
38+
# retrieve the latest version of Go
39+
GO_VERSION="$(curl -s https://golang.org/dl/?mode=json | jq --raw-output '.[0].version')"
40+
GO_PACKAGE="$GO_VERSION.linux-arm64.tar.gz"
41+
GO_SHA="$(curl -s https://golang.org/dl/?mode=json | jq --raw-output '.[0].files | map(select(.arch == "arm64")) | .[0].sha256')"
42+
43+
# download Go package
44+
curl -o $TMP_DIR/$GO_PACKAGE" -L "https://golang.org/dl/$GO_PACKAGE"
45+
46+
# verify sha256 shasum"
47+
echo "$GO_SHA $TMP_DIR/$GO_PACKAGE" | sha256sum --check --status
48+
49+
# unzip Go package
50+
tar -xvf "$TMP_DIR/$GO_PACKAGE" -C "$TMP_DIR"
51+
52+
# build rundockerbuildlet
53+
mkdir -p "$GO_PATH"
54+
GOPATH="$GO_PATH" "$TMP_DIR/go/bin/go" get -u golang.org/x/build/cmd/rundockerbuildlet
55+
GOPATH="$GO_PATH" "$TMP_DIR/go/bin/go" build -o "$TMP_DIR/rundockerbuildlet" golang.org/x/build/cmd/rundockerbuildlet
56+
sudo mv "$TMP_DIR/rundockerbuildlet" /usr/local/bin/rundockerbuildlet
57+
58+
sudo mv /tmp/rundockerbuildlet.service /etc/systemd/user/rundockerbuildlet.service
59+
sudo systemctl enable /etc/systemd/user/rundockerbuildlet.service
60+
sudo systemctl start rundockerbuildlet
61+
62+
# remove temporary directory
63+
rm -fr "$TMP_DIR"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[Unit]
2+
Description=Run Buildlets in Docker
3+
After=network.target
4+
5+
[Install]
6+
WantedBy=network-online.target
7+
8+
[Service]
9+
Type=simple
10+
ExecStart=/usr/local/bin/rundockerbuildlet \
11+
-env=host-linux-arm64-aws \
12+
-memory=7g \
13+
-image=gobuilder-arm64-aws
14+
Restart=always
15+
RestartSec=2
16+
StartLimitInterval=0

0 commit comments

Comments
 (0)