Introduction
Create the workflow file .gitlab-ci.yml.
MDBook App workflow
stages:
- build_and_deploy
deploy-kb:
stage: build_and_deploy
image:
name: peaceiris/mdbook:latest
entrypoint: [""]
rules:
- if: $CI_COMMIT_BRANCH == "main"
changes:
- src/**/*
- book.toml
- if: $CI_PIPELINE_SOURCE == "web"
script:
# 1. Build
- mdbook build
# 2. Setup Tools (Added curl for IP discovery)
- apk add --no-cache openssh-client rsync curl
# 3. SSH Agent setup
- eval $(ssh-agent -s)
- chmod 400 "$VPS_PRIVATE_KEY"
- ssh-add "$VPS_PRIVATE_KEY"
- mkdir -p ~/.ssh
- ssh-keyscan -p $VPS_SSH_PORT $VPS_IP >> ~/.ssh/known_hosts
# 4. Sync
- rsync -azq -e "ssh -p $VPS_SSH_PORT" --delete ./book/ $VPS_APP_NAME@$VPS_IP:/var/www/$VPS_APP_NAME/
Plain HTML/CSS/JS App workflow
stages:
- deploy
deploy:
image: alpine:latest
stage: deploy
script:
# 1. Setup Deploy Tools
- apk add --no-cache openssh-client rsync
# 2. SSH Agent setup
- eval $(ssh-agent -s)
- chmod 400 "$VPS_PRIVATE_KEY"
- ssh-add "$VPS_PRIVATE_KEY"
- mkdir -p ~/.ssh
- ssh-keyscan -p $VPS_SSH_PORT $VPS_IP >> ~/.ssh/known_hosts
# 3. Sync
# Using -azq: archive mode, compress, quiet
- rsync -azq -e "ssh -p $VPS_SSH_PORT" --delete --exclude=".git/" . $VPS_APP_NAME@$VPS_IP:/var/www/$VPS_APP_NAME/