Last active
June 6, 2023 10:07
-
-
Save aur3l14no/c271148b2d499faadea812ded625054e to your computer and use it in GitHub Desktop.
Initialize fly.io volume with local data · GitHub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
YOUR_APP="" # eg. my-app | |
YOUR_VOL="" # eg. app-data | |
YOUR_REGION="" # eg. hkg | |
LOCAL_PATH="" # eg. /tmp/data/* | |
REMOTE_PATH="" # eg. /data/ | |
echo 'Run this script after fly launch and fly vol create. C-c to abort.' | |
read | |
# spin up tmp | |
fly machine run -r ${YOUR_REGION} -v ${YOUR_VOL}:${REMOTE_PATH} --entrypoint "tail -f /dev/null" alpine -n tmp | |
id=$(fly m ls | awk 'NR==6 {print $1}') | |
ip=$(fly m ls | awk 'NR==6 {print $6}') | |
# connect to tmp - proxy | |
fly proxy 10022:22 ${ip} -a ${YOUR_APP} & | |
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT | |
sleep 3 | |
# connect to tmp - key | |
[ -f ~/.ssh/fly ] && rm -f ~/.ssh/{fly,fly-cert.pub} | |
fly ssh issue personal ~/.ssh/fly --hours 1 | |
# copy to tmp | |
ssh -o "StrictHostKeyChecking=no" \ | |
-o "UserKnownHostsFile=/dev/null" \ | |
-p 10022 -i ~/.ssh/fly root@localhost "apk add openssh-client" | |
scp -o "StrictHostKeyChecking=no" \ | |
-o "UserKnownHostsFile=/dev/null" \ | |
-P 10022 -i ~/.ssh/fly -r ${LOCAL_PATH} root@localhost:${REMOTE_PATH} | |
# destroy tmp | |
fly machine destroy --force ${id} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment