diff --git a/aws/bootstrap b/aws/bootstrap new file mode 100755 index 0000000..a6664aa --- /dev/null +++ b/aws/bootstrap @@ -0,0 +1,4 @@ +#!/bin/sh -l + +cd CONFIG_DIR +./tailcall \ No newline at end of file diff --git a/aws/tailcall.tf b/aws/tailcall.tf index 0e660a3..70da039 100644 --- a/aws/tailcall.tf +++ b/aws/tailcall.tf @@ -51,6 +51,10 @@ variable "TERRAFORM_WORKSPACE" { type = string } +variable "TAILCALL_PATH" { + type = string +} + provider "aws" { region = var.AWS_REGION access_key = var.AWS_ACCESS_KEY_ID @@ -89,8 +93,30 @@ data "http" "bootstrap" { } resource "local_sensitive_file" "bootstrap" { + content_base64 = filebase64("bootstrap") + filename = "config/bootstrap" +} + +resource "local_sensitive_file" "tailcall" { content_base64 = data.http.bootstrap.response_body_base64 - filename = "BOOTSTRAP_PATH" + filename = var.TAILCALL_PATH +} + +resource "local_sensitive_file" "config" { + for_each = fileset(path.module, "config/**") + content_base64 = filebase64("${each.key}") + filename = "${each.key}" +} + +data "archive_file" "tailcall" { + type = "zip" + depends_on = [ + local_sensitive_file.bootstrap, + local_sensitive_file.config, + local_sensitive_file.tailcall + ] + source_dir = "config" + output_path = "tailcall.zip" } resource "aws_lambda_function" "tailcall" { @@ -102,7 +128,7 @@ resource "aws_lambda_function" "tailcall" { function_name = var.AWS_LAMBDA_FUNCTION_NAME runtime = "provided.al2" architectures = ["x86_64"] - handler = "bootstrap" + handler = "start" filename = data.archive_file.tailcall.output_path source_code_hash = data.archive_file.tailcall.output_base64sha256 } diff --git a/scripts/create-tf-zip.sh b/scripts/create-tf-zip.sh deleted file mode 100755 index f52c4e3..0000000 --- a/scripts/create-tf-zip.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -l - -depends_on="[ local_sensitive_file.bootstrap,"; -for file_path in $(find config -type f); do - echo "Path: $file_path" - name=$(basename $file_path | tr '.' '_') - - resource="resource \"local_sensitive_file\" \"$name\" {\n content_base64 = filebase64(\"$file_path\") \n filename = \"$file_path\"\n }" - - printf "\n$resource\n" >> /aws/tailcall.tf - - depends_on="$depends_on local_sensitive_file.$name," - echo $resource -done -depends_on="$depends_on ]" - -archive_file="data \"archive_file\" \"tailcall\" { \n depends_on = $depends_on \n type = \"zip\" \n source_dir = \"config\" \n output_path = \"tailcall.zip\"\n }" -printf "\n$archive_file\n" >> /aws/tailcall.tf - -echo "tailcall.tf" -cat /aws/tailcall.tf diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index b7b3d38..430ab63 100755 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -19,11 +19,12 @@ get_latest_version() { curl https://api.github.com/repos/$1/$2/releases/latest -s | jq .name -r } -echo "DIRS: $(ls)" +echo "DIRS: $(ls -R)" mkdir -p /app cp -r ./* /app TC_CONFIG_DIR_ROOT=/app -TC_CONFIG_DIR=$(dirname $TAILCALL_CONFIG) +TC_CONFIG_DIR=$(dirname $TAILCALL_CONFIG | sed 's|^\./||') +echo $TC_CONFIG_DIR TC_CONFIG_NAME=$(basename $TAILCALL_CONFIG) EXTENSION=$(echo $TC_CONFIG_NAME | tr '.' '\n' | tail -n 1) @@ -38,6 +39,7 @@ export TF_VAR_AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID export TF_VAR_AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY export TF_VAR_TERRAFORM_ORG=$TERRAFORM_ORG export TF_VAR_TERRAFORM_WORKSPACE=$TERRAFORM_WORKSPACE +export TF_VAR_TAILCALL_PATH="config/$TC_CONFIG_DIR/tailcall" export TF_TOKEN_app_terraform_io=$TERRAFORM_API_TOKEN @@ -79,15 +81,15 @@ deploy() { # todo: handle name collisions mkdir -p /aws/config cp -r /app/* /aws/config + awk -v config_dir="$TC_CONFIG_DIR" "{sub(/CONFIG_DIR/,config_dir)}1" /aws/bootstrap > /tmp/bootstrap + mv /tmp/bootstrap /aws/bootstrap cd /aws echo "List: $(find /app -type f)" - /scripts/create-tf-zip.sh - echo "List: $(find /app -type f)" setup_terraform awk -v org="\"$TERRAFORM_ORG\"" "{sub(/var.TERRAFORM_ORG/,org)}1" /aws/tailcall.tf > /tmp/temp1.tf awk -v workspace="\"$TERRAFORM_WORKSPACE\"" "{sub(/var.TERRAFORM_WORKSPACE/,workspace)}1" /tmp/temp1.tf > /tmp/temp2.tf - awk -v boot_strap_path="config/$TC_CONFIG_DIR/bootstrap" "{sub(/BOOTSTRAP_PATH/,workspace)}1" /tmp/temp2.tf > /tmp/temp3.tf - mv /tmp/temp3.tf tailcall.tf + mv /tmp/temp2.tf tailcall.tf + echo "list: $(ls -R)" terraform init echo "List: $(find /app -type f)" TF_LOG=DEBUG terraform apply -auto-approve