Files
josufh a7eb08a61c
Deploy / deploy (push) Successful in 1m15s
Reduce deploy workflow log output
2026-06-07 19:23:25 +09:00

72 lines
2.0 KiB
YAML

name: Deploy
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy to Oracle VM
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
DEPLOY_REPO: ${{ secrets.DEPLOY_REPO }}
run: |
set -eu
apt-get update -qq
apt-get install -y -qq --no-install-recommends openssh-client ca-certificates
DEPLOY_PORT="${DEPLOY_PORT:-22}"
DEPLOY_PATH="${DEPLOY_PATH:-/home/ubuntu/low-level-guy.com}"
DEPLOY_REPO="${DEPLOY_REPO:-https://git.low-level-guy.com/josufh/low-level-guy.com.git}"
mkdir -p ~/.ssh
chmod 700 ~/.ssh
printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -p "$DEPLOY_PORT" "$DEPLOY_HOST" >> ~/.ssh/known_hosts
ssh \
-o BatchMode=yes \
-o ConnectTimeout=20 \
-o ServerAliveInterval=15 \
-o ServerAliveCountMax=2 \
-i ~/.ssh/deploy_key \
-p "$DEPLOY_PORT" \
"$DEPLOY_USER@$DEPLOY_HOST" << EOF
set -eu
if [ ! -d "$DEPLOY_PATH/.git" ]; then
rm -rf "$DEPLOY_PATH"
mkdir -p "$DEPLOY_PATH"
git clone "$DEPLOY_REPO" "$DEPLOY_PATH"
fi
cd "$DEPLOY_PATH"
git fetch origin main
git reset --hard origin/main
docker build --quiet -t lowlevelguycom:latest .
docker stop low-level-guy-com || true
docker rm low-level-guy-com || true
docker run -d \
--name low-level-guy-com \
--restart unless-stopped \
-p 5000:5000 \
lowlevelguycom:latest
docker ps --filter name=low-level-guy-com --format '{{.Names}} {{.Status}} {{.Ports}}'
EOF