-
Notifications
You must be signed in to change notification settings - Fork 0
/
dokku
executable file
·32 lines (26 loc) · 1.62 KB
/
dokku
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
read -p "App name (lowercase, letters, numbers, hyphen only): " APP_NAME
read -p "Host domain for the instance: " DOMAIN
read -p "Contact email to use for LetsEncrypt SSL registration: " LETSENCRYPT_EMAIL
read -p "Instance type [t3a.small]: " INSTANCE_TYPE
INSTANCE_TYPE=${INSTANCE_TYPE:=t3a.small}
# determine architecture type from instance type
if [[ "$INSTANCE_TYPE" =~ g\. ]]; then
TARGET_ARCH=arm64
else
TARGET_ARCH=amd64
fi
# get the appropriate Debian 12 (Bookworm) AMI for the current region and architecture
IMAGE_ID=`aws ssm get-parameters-by-path --path /aws/service/debian/release/bookworm/latest --output text | grep -m 1 -oP "${TARGET_ARCH}[[:blank:]]+String[[:blank:]]+\K(ami-[^[:blank:]]+)"`
aws cloudformation create-stack --capabilities CAPABILITY_NAMED_IAM --stack-name dokku-${APP_NAME} --template-body file://./dokku.json --parameters ParameterKey=ApplicationName,ParameterValue=$APP_NAME ParameterKey=LetsEncryptEmail,ParameterValue=$LETSENCRYPT_EMAIL ParameterKey=DokkuHostname,ParameterValue="$DOMAIN" ParameterKey=InstanceImageId,ParameterValue="$IMAGE_ID" ParameterKey=InstanceType,ParameterValue="$INSTANCE_TYPE"
# wait for key pair to become available
while : ; do
KEY_NAME=`aws ec2 describe-key-pairs --filters Name=key-name,Values=dokku-${APP_NAME}-key-pair --query KeyPairs[*].KeyPairId --output text`
if [ "$KEY_NAME" != "" ]; then
break
fi
sleep 1
done
# download into a pem file in ~/.ssh
aws ssm get-parameter --name /ec2/keypair/${KEY_NAME} --with-decryption --query Parameter.Value --output text > ~/.ssh/dokku-${APP_NAME}-key-pair.pem
chmod 600 ~/.ssh/dokku-${APP_NAME}-key-pair.pem