Skip to content

Instantly share code, notes, and snippets.

@aur3l14no
Last active June 6, 2023 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aur3l14no/c271148b2d499faadea812ded625054e to your computer and use it in GitHub Desktop.
Save aur3l14no/c271148b2d499faadea812ded625054e to your computer and use it in GitHub Desktop.
Initialize fly.io volume with local data · GitHub
#!/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