#!/usr/bin/env bash # Builds the image locally and ships it to the server (Docker Hub is unreliable # from mainland China, so the server never pulls images itself). # # deploy/deploy.sh build, upload, restart # HOST=root@1.2.3.4 deploy/deploy.sh set -euo pipefail HOST=${HOST:-root@8.133.23.131} DIR=/opt/billing cd "$(dirname "$0")/.." docker buildx build --platform linux/amd64 -t billing:latest --load . echo "uploading image…" docker save billing:latest | gzip -1 | ssh "$HOST" 'gunzip | docker load' ssh "$HOST" "mkdir -p $DIR/data" scp deploy/docker-compose.yml "$HOST:$DIR/docker-compose.yml" ssh "$HOST" "test -f $DIR/.env" || scp deploy/env.example "$HOST:$DIR/.env" # docker-compose 1.29 cannot recreate containers on Docker 25+ (KeyError: 'ContainerConfig'), # so remove the old container first; data lives in the mounted ./data directory. ssh "$HOST" "cd $DIR && docker rm -f billing >/dev/null 2>&1; docker-compose up -d && docker image prune -f >/dev/null" echo "deployed"