Backing #68
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
name: Backing | |
on: | |
workflow_dispatch: | |
jobs: | |
build-upload: | |
runs-on: self-hosted | |
steps: | |
- uses: actions/checkout@v4 | |
- name: "Setup yq" | |
uses: dcarbone/[email protected] | |
- name: "Configure AWS credentials" | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
mask-aws-account-id: true | |
- name: "Install Rust toolchain" | |
uses: dtolnay/rust-toolchain@stable | |
- name: "Install Zig toolchain" | |
uses: korandoru/setup-zig@v1 | |
with: | |
zig-version: 0.11.0 | |
- name: "Install Cargo Lambda" | |
uses: jaxxstorm/[email protected] | |
with: | |
repo: "cargo-lambda/cargo-lambda" | |
platform: linux | |
arch: x86_64 | |
- name: Set up cargo cache | |
uses: Swatinem/rust-cache@v2 | |
- name: "Build backing and upload" | |
env: | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
run: | | |
parameters_json=$(yq -o=json '.' parameters.yml) | |
bucket_name=$(jq -r '.bucket_name' <<< $parameters_json) | |
bucket_status=$(aws s3api head-bucket --bucket $bucket_name --region $AWS_REGION 2>&1) || true | |
if echo $bucket_status | grep -q 'Not Found'; then | |
echo "Bucket '$bucket_name' does not exist. Creating..." | |
aws s3api create-bucket \ | |
--bucket $bucket_name \ | |
--region $AWS_REGION \ | |
--create-bucket-configuration LocationConstraint=$AWS_REGION | |
else | |
echo "Bucket $bucket_name exists" | |
fi | |
build_lambdas() { | |
bin_names=("$@") | |
for bin_name in "${bin_names[@]}"; do | |
echo "Building lambda: $bin_name" | |
cargo lambda build --release --bin "$bin_name" --arm64 --output-format zip | |
done | |
} | |
build_lambdas log_processor report_generator | |
for src in $(find target/lambda -name "bootstrap.zip"); do | |
name=$(basename "$(dirname "$src")") | |
s3_key="backing/${name}.zip" | |
dst="s3://$bucket_name/$s3_key" | |
aws s3 cp "$src" "$dst" > /dev/null 2>&1 | |
echo "Uploaded '$src' to 's3://$bucket_name/$s3_key'" | |
function_name="benchmark-$name" | |
if aws lambda get-function --function-name "$function_name" > /dev/null 2>&1; then | |
aws lambda update-function-code --function-name "$function_name" --s3-bucket "$bucket_name" --s3-key "$s3_key" > /dev/null 2>&1 | |
echo "Function '$function_name' code updated" | |
fi | |
done |