-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdokku
executable file
·34 lines (28 loc) · 1.77 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
33
34
#!/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}
read -p "Instance root volume size in GB [12]: " VOLUME_SIZE
VOLUME_SIZE=${VOLUME_SIZE:=12}
# 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 ${APP_NAME}-dokku --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" ParameterKey=InstanceRootVolumeSize,ParameterValue="$VOLUME_SIZE"
# wait for key pair to become available
while : ; do
KEY_NAME=`aws ec2 describe-key-pairs --filters Name=key-name,Values=${APP_NAME}-dokku-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/${APP_NAME}-dokku-key-pair.pem
chmod 600 ~/.ssh/${APP_NAME}-dokku-key-pair.pem