-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ECS Agent & Alloy configurations (#7)
* feat: refactor alloy configs * fix: remove unused input from alloy module * fix(alloy): name for otlp exporter was invalid, fix * fix: update casing for ecs-agent alloy config * fix(alloy): get config working 🎉 * feat(ci): deploy on main branch * fix(ci): drop ifs for testing porpoises * fix(ci): add --quiet to aws s3 cp call * fix(ci): reintroduce if: main branch checks * fix(ci): reintroduce cachix action * feat(ci): make the workflow cleaner to read * feat(ci): job-end summary * fix(ci): remove check to test with * fix(ci): add check back in
- Loading branch information
Showing
9 changed files
with
171 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
bucket="$1" | ||
profile="$2" | ||
|
||
ci="${CI:-false}" | ||
|
||
current_group="" | ||
group() { | ||
# Starts a group (GitHub Actions) | ||
current_group="$1" | ||
if [[ "$ci" == "true" ]]; then | ||
echo "::group::$1"; | ||
else | ||
echo "> $1" | ||
fi | ||
} | ||
|
||
endgroup() { | ||
# Ends the group (GitHub Actions) | ||
if [[ "$ci" == "true" ]]; then | ||
echo "::endgroup::" | ||
else | ||
echo "> Finished $current_group" | ||
fi | ||
current_group="" | ||
} | ||
|
||
ciout() { | ||
# Sets the value as a job output | ||
if [[ "$ci" == "true" ]]; then echo "$1=$2" >> "$GITHUB_OUTPUT"; fi | ||
} | ||
|
||
cisum() { | ||
if [[ "$ci" == "true" ]]; then | ||
echo "$@" >> "$GITHUB_STEP_SUMMARY" | ||
fi | ||
} | ||
|
||
build_time=$(date +%s) | ||
image_name="altf4llc-$profile-$build_time" | ||
ciout image_name "$image_name" | ||
|
||
group "Building source VHD" | ||
derivation=$(just build "$profile") | ||
output=$(echo "$derivation" | jq -r '.[].outputs.out') | ||
image_path=$(cd "$output" && ls -- *.vhd) | ||
endgroup | ||
|
||
group "Uploading VHD to S3" | ||
aws s3 cp "$output/$image_path" "s3://$bucket/$image_name.vhd" --quiet | ||
endgroup | ||
|
||
group "Importing VHD as snapshot in EC2" | ||
task_id=$(aws ec2 import-snapshot --disk-container "Format=VHD,UserBucket={S3Bucket=$bucket,S3Key=$image_name.vhd}" --output json | jq -r ".ImportTaskId") | ||
|
||
echo "Waiting for snapshot import to complete." | ||
until [[ $(aws ec2 describe-import-snapshot-tasks --import-task-ids "$task_id" --output json | jq -r '.ImportSnapshotTasks[].SnapshotTaskDetail.Status') == "completed" ]]; do | ||
echo "Snapshot is not imported yet, waiting..." | ||
sleep 5 | ||
done | ||
|
||
snapshot_id=$(aws ec2 describe-import-snapshot-tasks --import-task-ids "$task_id" --output json | jq -r '.ImportSnapshotTasks[].SnapshotTaskDetail.SnapshotId') | ||
|
||
echo "New snapshot is $snapshot_id." | ||
ciout snapshot_id "$snapshot_id" | ||
endgroup | ||
|
||
echo "::group::Registering new AMI" | ||
ami_id=$(aws ec2 register-image --architecture x86_64 --ena-support --name "$image_name" --description "A NixOS AMI: {{profile}}" --block-device-mappings "DeviceName=/dev/sda1,Ebs={SnapshotId=$snapshot_id}" --root-device-name /dev/sda1 | jq .ImageId) | ||
echo "AMI is registered: $ami_id" | ||
ciout ami_id "$ami_id" | ||
echo "::endgroup::" | ||
|
||
echo "::group::Cleaning up image VHD from bucket" | ||
aws s3 rm "s3://$bucket/$image_name.vhd" | ||
echo "::endgroup::" | ||
|
||
cisum "# :rocket: AMI build successful" | ||
cisum "" | ||
cisum "An image was successfully built for Nix profile \`$profile\`." | ||
cisum "" | ||
cisum "- Build time: \`$build_time\`" | ||
cisum "- VHD import job ID: \`$task_id\`" | ||
cisum "- AMI ID: \`$ami_id\`" | ||
cisum "- Snapshot ID: \`$snapshot_id\`" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{config, ...}: { | ||
{...}: { | ||
# see TODO further down | ||
imports = [../docker]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
prometheus.exporter.cadvisor "cadvisor" { | ||
docker_host = "unix:///var/run/docker.sock" | ||
storage_duration = "5m" | ||
} | ||
|
||
prometheus.scrape "cadvisor" { | ||
targets = prometheus.exporter.cadvisor.cadvisor.targets | ||
forward_to = [prometheus.relabel.instance.receiver] | ||
scrape_interval = "30s" | ||
} | ||
|
||
// vim:ft=hcl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
{...}: { | ||
virtualisation.docker.enable = true; | ||
virtualisation.oci-containers.backend = "docker"; | ||
|
||
# Monitoring | ||
environment.etc."alloy/docker.alloy" = { | ||
source = ./config.alloy; | ||
mode = "0440"; | ||
user = "root"; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{pkgs, ...}: { | ||
{...}: { | ||
imports = [ | ||
../docker | ||
../alloy | ||
|