Skip to content

Commit

Permalink
check versions before uploading to S3
Browse files Browse the repository at this point in the history
  • Loading branch information
spypsy committed Oct 25, 2024
1 parent 7b0e9f3 commit 20776de
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions aztec-up/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,33 @@ resource "null_resource" "upload_public_directory" {
}

provisioner "local-exec" {
command = <<EOT
# Upload latest version to root
aws s3 sync ../bin s3://${aws_s3_bucket.install_bucket.id}/
# Create a version directory and upload files there
interpreter = ["/bin/bash", "-c"]
command = <<EOT
# Function to compare versions
version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
# Read the current version from S3
CURRENT_VERSION=$(aws s3 cp s3://${aws_s3_bucket.install_bucket.id}/VERSION - 2>/dev/null || echo "0.0.0")
# Validate that var.VERSION is a valid semver
if [[ ! "${var.VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Warning: ${var.VERSION} is not a valid semver version. Skipping version comparison."
else
# Check if new version is greater than current version
if version_gt "${var.VERSION}" "$CURRENT_VERSION"; then
echo "Uploading new version ${var.VERSION}"
# Upload new version to root
aws s3 sync ../bin s3://${aws_s3_bucket.install_bucket.id}/
# Update VERSION file
echo "${var.VERSION}" | aws s3 cp - s3://${aws_s3_bucket.install_bucket.id}/VERSION
else
echo "New version ${var.VERSION} is not greater than current version $CURRENT_VERSION. Skipping root upload."
fi
fi
# Always create a version directory and upload files there
aws s3 sync ../bin s3://${aws_s3_bucket.install_bucket.id}/${var.VERSION}/
EOT
}
Expand Down

0 comments on commit 20776de

Please sign in to comment.