Skip to content

Commit 8cda30c

Browse files
authored
Merge pull request #530 from EspressoSystems/release-ami
AMI release workflow and packer init.
2 parents 72c0999 + 032c490 commit 8cda30c

File tree

6 files changed

+278
-0
lines changed

6 files changed

+278
-0
lines changed

.github/workflows/ami-release.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Release Timeboost AMI
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build-ami:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v5
14+
with:
15+
submodules: recursive
16+
fetch-depth: 0
17+
18+
- name: Install Rust
19+
uses: actions-rs/toolchain@v1
20+
with:
21+
toolchain: stable
22+
override: true
23+
24+
- name: Install nightly rustfmt
25+
run: rustup component add --toolchain nightly rustfmt
26+
27+
- name: Install Foundry
28+
uses: foundry-rs/foundry-toolchain@v1
29+
30+
- name: Install protobuf compiler
31+
run: |
32+
sudo apt-get update
33+
sudo apt-get install -y protobuf-compiler
34+
35+
- name: Install just
36+
uses: taiki-e/install-action@just
37+
38+
- name: Install Packer
39+
uses: hashicorp/setup-packer@v2
40+
with:
41+
version: "1.9.0"
42+
43+
- name: Configure AWS credentials
44+
uses: aws-actions/configure-aws-credentials@v2
45+
with:
46+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
47+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
48+
aws-region: eu-central-1
49+
50+
- name: Build AMI
51+
run: |
52+
cd packer
53+
packer init .
54+
just build
55+
just make-overlay
56+
VERSION=${GITHUB_REF_NAME} just make-image

packer/justfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version := env("VERSION", "0.1.0")
2+
vector-version := "0.50.0"
3+
overlay-archive := "timeboost-overlay.tar.gz"
4+
5+
init:
6+
packer init .
7+
8+
clean:
9+
rm -f {{overlay-archive}}
10+
11+
format:
12+
packer fmt .
13+
14+
build:
15+
cargo build --release --bin timeboost
16+
17+
make-overlay:
18+
#!/usr/bin/env bash
19+
set -e
20+
if [[ -f {{overlay-archive}} ]]; then
21+
rm {{overlay-archive}}
22+
fi
23+
dir=$(mktemp -d)
24+
cp -R overlay $dir/
25+
mkdir -p $dir/overlay/usr/local/bin
26+
cp ../target/release/timeboost $dir/overlay/usr/local/bin/timeboost
27+
tar czf {{overlay-archive}} -C $dir/overlay/ .
28+
29+
validate:
30+
packer validate \
31+
--var version={{version}} \
32+
--var vector-version={{vector-version}} \
33+
--var overlay-archive={{overlay-archive}} \
34+
timeboost.pkr.hcl
35+
36+
make-image: validate
37+
packer build \
38+
--var version={{version}} \
39+
--var vector-version={{vector-version}} \
40+
--var overlay-archive={{overlay-archive}} \
41+
timeboost.pkr.hcl
42+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=Timeboost
3+
After=network.target
4+
Requires=network-online.target
5+
6+
[Service]
7+
ExecStart=/usr/local/bin/timeboost --config /etc/timeboost/timeboost.toml
8+
Restart=always
9+
RestartSec=5
10+
11+
[Install]
12+
WantedBy=multi-user.target
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[Unit]
2+
Description=Vector
3+
Documentation=https://vector.dev
4+
After=network-online.target
5+
Requires=network-online.target
6+
StartLimitInterval=10
7+
StartLimitBurst=5
8+
9+
[Service]
10+
User=vector
11+
Group=vector
12+
ExecStartPre=/usr/bin/vector validate
13+
ExecStart=/usr/bin/vector -c /etc/vector/vector.toml
14+
ExecReload=/usr/bin/vector validate --no-environment
15+
ExecReload=/bin/kill -HUP $MAINPID
16+
Restart=always
17+
AmbientCapabilities=CAP_NET_BIND_SERVICE
18+
EnvironmentFile=-/etc/default/vector
19+
20+
[Install]
21+
WantedBy=multi-user.target
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[sources.vector]
2+
type = "internal_logs"
3+
4+
# Host
5+
6+
[sources.host]
7+
type = "host_metrics"
8+
collectors = ["memory"]
9+
scrape_interval_secs = 30
10+
11+
[transforms.filtered-host]
12+
type = "filter"
13+
inputs = ["host"]
14+
condition = { type = "vrl", source = ".name == \"memory_used_bytes\"" }
15+
16+
# Service
17+
18+
[sources.timeboost]
19+
type = "journald"
20+
include_units = ["timeboost"]
21+
22+
[transforms.to-json]
23+
type = "remap"
24+
inputs = ["timeboost"]
25+
source = '''
26+
.message = object!(parse_json!(string!(.message)))
27+
28+
if exists(.message.span) {
29+
span = object!(del(.message.span))
30+
.message = merge!(.message, span)
31+
}
32+
'''
33+
34+
[transforms.with-metadata]
35+
type = "aws_ec2_metadata"
36+
inputs = ["to-json"]
37+
fields = [
38+
"ami-id",
39+
"availability-zone",
40+
"instance-id",
41+
"instance-type",
42+
"local-ipv4",
43+
"region",
44+
"subnet-id",
45+
"vpc-id",
46+
"role-name",
47+
]
48+
49+
# Outputs
50+
51+
[sinks.console]
52+
type = "console"
53+
inputs = ["vector"]
54+
encoding.codec = "text"
55+
56+
[sinks.aws-cloudwatch]
57+
type = "aws_cloudwatch_logs"
58+
inputs = ["with-metadata"]
59+
region = "eu-central-1"
60+
group_name = "timeboost"
61+
encoding.codec = "json"
62+
stream_name = "{{{{raw}}}}{{ host }}{{{{/raw}}}}"
63+
64+
[sinks.aws-cloudwatch-metrics]
65+
type = "aws_cloudwatch_metrics"
66+
inputs = ["filtered-host"]
67+
region = "eu-central-1"
68+
default_namespace = "timeboost"

packer/timeboost.pkr.hcl

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
packer {
2+
required_plugins {
3+
amazon = {
4+
version = ">= 1.2.0"
5+
source = "github.com/hashicorp/amazon"
6+
}
7+
}
8+
}
9+
10+
variable "version" {
11+
type = string
12+
}
13+
14+
variable "vector-version" {
15+
type = string
16+
}
17+
18+
variable "overlay-archive" {
19+
type = string
20+
}
21+
22+
source "amazon-ebs" "al2" {
23+
ami_name = "timeboost-${var.version}"
24+
instance_type = "t3a.micro"
25+
region = "eu-central-1"
26+
27+
source_ami_filter {
28+
filters = {
29+
name = "amzn2-ami-hvm-*-x86_64-gp2"
30+
root-device-type = "ebs"
31+
virtualization-type = "hvm"
32+
}
33+
owners = ["amazon"]
34+
most_recent = true
35+
}
36+
37+
launch_block_device_mappings {
38+
device_name = "/dev/xvda"
39+
volume_size = 16
40+
volume_type = "gp3"
41+
delete_on_termination = true
42+
}
43+
44+
ssh_username = "ec2-user"
45+
}
46+
47+
build {
48+
sources = ["source.amazon-ebs.al2"]
49+
50+
provisioner "shell" {
51+
inline = [
52+
"echo upgrading base and installing dependencies ...",
53+
"sudo yum update -y",
54+
"sudo rpm -i https://yum.vector.dev/stable/vector-0/x86_64/vector-${var.vector-version}-1.x86_64.rpm"
55+
]
56+
}
57+
58+
provisioner "file" {
59+
source = "${var.overlay-archive}"
60+
destination = "/tmp/${var.overlay-archive}"
61+
}
62+
63+
provisioner "shell" {
64+
inline = [
65+
"echo extracting overlay ...",
66+
"sudo tar xzf /tmp/${var.overlay-archive} -C /",
67+
"sudo chown -R ec2-user:ec2-user /usr/local/bin/timeboost",
68+
"sudo rm /tmp/${var.overlay-archive}"
69+
]
70+
}
71+
72+
provisioner "shell" {
73+
inline = [
74+
"sudo systemctl daemon-reload",
75+
"sudo systemctl enable vector",
76+
"sudo systemctl enable timeboost"
77+
]
78+
}
79+
}

0 commit comments

Comments
 (0)