Skip to content

Commit

Permalink
Merge branch 'debug'
Browse files Browse the repository at this point in the history
  • Loading branch information
shashitnak committed Jun 11, 2024
2 parents b06fd6a + 6a3b371 commit 3af97cf
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 23 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ FROM alpine:latest as builder
COPY scripts /scripts
COPY aws /aws
COPY fly /fly
COPY config.json /fly/config.json
COPY config.json /extras/config.json

RUN export FLY_APP_NAME="$(echo FLY_APP_NAME | tr '/' '_')"
RUN apk upgrade --no-cache && apk update --no-cache
RUN apk add --no-cache curl jq
RUN apk add --no-cache curl jq py-pip ripgrep
RUN pip install toml-cli --break-system-packages

ENTRYPOINT /bin/sh /scripts/entrypoint.sh
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ inputs:
fly-app-name:
description: 'Fly.io App Name'
required: false
default: "${{ github.repository_owner }}-${{ github.event.repository.name }}"
fly-region:
description: 'Fly.io Region'
required: false
Expand Down
15 changes: 0 additions & 15 deletions aws/tailcall.tf
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,6 @@ resource "local_sensitive_file" "bootstrap" {
filename = "config/bootstrap"
}

resource "local_sensitive_file" "config" {
content_base64 = filebase64("config.graphql")
filename = "config/config.graphql"
}

data "archive_file" "tailcall" {
depends_on = [
local_sensitive_file.bootstrap,
local_sensitive_file.config
]
type = "zip"
source_dir = "config"
output_path = "tailcall.zip"
}

resource "aws_lambda_function" "tailcall" {
depends_on = [
data.archive_file.tailcall
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"links": [{
"type": "Config",
"src": "./config.graphql"
"src": "config/config.graphql"
}
]
}
3 changes: 2 additions & 1 deletion fly/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ FROM alpine:latest
COPY --from=builder /app /app
COPY --from=builder /usr/local/bin/tailcall /usr/local/bin/tailcall

CMD TC_TRACKER=false tailcall start /app/config.json
WORKDIR /app
CMD TC_TRACKER=false tailcall start config.json
21 changes: 21 additions & 0 deletions scripts/create-tf-zip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/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
42 changes: 38 additions & 4 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@ setup_tailcall() {

validate_tailcall_config() {
setup_tailcall
echo "TAILCALL_CONFIG: $TAILCALL_CONFIG"
TC_TRACER=false tailcall check $TAILCALL_CONFIG
}

get_latest_version() {
curl https://api.github.com/repos/$1/$2/releases/latest -s | jq .name -r
}

mkdir -p /app
cp -r ./* /app
TC_CONFIG_DIR_ROOT=/app
TC_CONFIG_DIR=$(dirname $TAILCALL_CONFIG)
TC_CONFIG_NAME=$(basename $TAILCALL_CONFIG)
EXTENSION=$(echo $TC_CONFIG_NAME | tr '.' '\n' | tail -n 1)

mv "$TC_CONFIG_DIR_ROOT/$TC_CONFIG_DIR/$TC_CONFIG_NAME" "$TC_CONFIG_DIR_ROOT/config.$EXTENSION"
export TAILCALL_CONFIG="$TC_CONFIG_DIR_ROOT/config.$EXTENSION"
validate_tailcall_config
export TF_VAR_AWS_REGION=$AWS_REGION
export TF_VAR_AWS_IAM_ROLE=$AWS_IAM_ROLE
Expand Down Expand Up @@ -54,20 +64,44 @@ extract_urls() {
grep -oE 'http[s]?://[^ "]+'
}

create_fly_toml() {
touch fly.toml
toml set --toml-path fly.toml app $FLY_APP_NAME
toml set --toml-path fly.toml primary_region $FLY_REGION
toml add_section --toml-path fly.toml http_service
export PORT=$(rg -o '@server\([^)]*port:\s*(\d+)[^)]*\)' --replace '$1' $TAILCALL_CONFIG || echo 8080)
echo "PORT: $PORT"
toml set --toml-path fly.toml http_service.internal_port $PORT --to-int
cat fly.toml
}

deploy() {
if [ "$PROVIDER" = "aws" ]; then
# todo: handle name collisions
mkdir -p /aws/config
cp -r /app/* /aws/config
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" tailcall.tf > /tmp/temp1.tf
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
mv /tmp/temp2.tf tailcall.tf
terraform init
terraform apply -auto-approve
echo "List: $(find /app -type f)"
TF_LOG=DEBUG terraform apply -auto-approve
elif [ "$PROVIDER" = "fly" ]; then
mkdir -p /fly/config
# todo: handle name collisions
cp -r /app/* /fly/config
cp /extras/config.json /fly/config.json
setup_flyctl
cd /fly
fly apps list | tail -n +2 | awk '{print $1}' | grep -w tailcall > /dev/null && fly apps destroy $FLY_APP_NAME --auto-confirm
flyctl launch --name $FLY_APP_NAME --region $FLY_REGION --local-only
export FLY_APP_NAME="$(echo $FLY_APP_NAME | tr '_' '-')"
fly apps list | tail -n +2 | awk '{print $1}' | grep -w tailcall > /dev/null && fly apps destroy $FLY_APP_NAME --auto-confirm || echo "App not found"
create_fly_toml
flyctl launch --local-only --copy-config
fi
}

Expand Down

0 comments on commit 3af97cf

Please sign in to comment.