Simple setup to use SSH as the way to transfer the docker image instead of using a registry
Last active
February 3, 2024 20:57
-
-
Save barelyhuman/fe994f85b78ee2ecf2132857ed4ef947 to your computer and use it in GitHub Desktop.
This file contains 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 | |
APP_NAME="demo" | |
IMAGE_NAME="demo:latest" | |
SSH_USER="deploy" | |
SSH_HOST=example.com | |
PREPARE_COMMANDS=""" | |
set -euxo pipefail | |
mkdir -p ~/$APP_NAME | |
""" | |
ssh ${SSH_USER}@${SSH_HOST} "/bin/bash -c '$PREPARE_COMMANDS'" | |
# Build Image | |
docker build . --platform=linux/amd64 -t ${IMAGE_NAME} | |
docker save ${APP_NAME}:latest | gzip > ${APP_NAME}-latest.tar.gz | |
rsync --progress ${APP_NAME}-latest.tar.gz ${SSH_USER}@${SSH_HOST}:~/$APP_NAME | |
COMMANDS=""" | |
set -euxo pipefail | |
cd ~/${APP_NAME} | |
docker image load < ${APP_NAME}-latest.tar.gz | |
docker stop \$(docker container ls --all --filter=ancestor="${IMAGE_NAME}" --format "{{.ID}}") | |
docker run -d -p '3000:3000' -v='./:/usr/bin/app' ${IMAGE_NAME} | |
""" | |
ssh ${SSH_USER}@${SSH_HOST} "/bin/bash -c '$COMMANDS'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment