@@ -0,0 +1,62 @@
|
||||
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
|
||||
apt-get install -y --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 -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 -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
|
||||
EOF
|
||||
Reference in New Issue
Block a user