65 lines
2.5 KiB
YAML
65 lines
2.5 KiB
YAML
stages:
|
|
- build
|
|
- deploy
|
|
|
|
variables:
|
|
DEPLOY_HOST: "217.160.174.2"
|
|
DEPLOY_USER: "root"
|
|
DEPLOY_PATH: "/opt/andreknie"
|
|
|
|
.ssh_setup: &ssh_setup
|
|
before_script:
|
|
- apt-get update -qq && apt-get install -y openssh-client rsync
|
|
- install -d -m 700 ~/.ssh
|
|
- echo "$VPS_SSH_KEY" > ~/.ssh/deploy_key
|
|
- chmod 600 ~/.ssh/deploy_key
|
|
- ssh-keyscan -H "${DEPLOY_HOST}" > ~/.ssh/known_hosts
|
|
- chmod 600 ~/.ssh/known_hosts
|
|
|
|
build-frontend:
|
|
stage: build
|
|
image: node:20
|
|
script:
|
|
- cd privat/CV/andreknie.de
|
|
- npm ci
|
|
- npm run build
|
|
artifacts:
|
|
paths:
|
|
- privat/CV/andreknie.de/dist/
|
|
expire_in: 1 day
|
|
rules:
|
|
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
|
changes:
|
|
- "privat/CV/andreknie.de/**/*"
|
|
|
|
deploy-andreknie:
|
|
stage: deploy
|
|
image: alpine:latest
|
|
<<: *ssh_setup
|
|
dependencies:
|
|
- build-frontend
|
|
rules:
|
|
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
|
changes:
|
|
- "privat/CV/andreknie.de/**/*"
|
|
script:
|
|
- ssh -i ~/.ssh/deploy_key -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes "${DEPLOY_USER}@${DEPLOY_HOST}" "install -d -m 755 ${DEPLOY_PATH}/site ${DEPLOY_PATH}/server ${DEPLOY_PATH}/server/data"
|
|
- cd privat/CV/andreknie.de
|
|
- |
|
|
cat <<EOF > .env
|
|
PORT=3003
|
|
NODE_ENV=production
|
|
BASE_URL=https://andreknie.de
|
|
SMTP_HOST=$SMTP_HOST
|
|
SMTP_PORT=587
|
|
SMTP_USER=$SMTP_USER
|
|
SMTP_PASS=$SMTP_PASS
|
|
STAKEHOLDER_EMAIL=kontakt@d-hive.de
|
|
EOF
|
|
- rsync -az --delete -e "ssh -i ~/.ssh/deploy_key -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes" dist/ "${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/site/"
|
|
- rsync -az --delete -e "ssh -i ~/.ssh/deploy_key -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes" server/ "${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/server/"
|
|
- rsync -az -e "ssh -i ~/.ssh/deploy_key -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes" package.json package-lock.json Dockerfile docker-compose.yml Caddyfile .env "${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/"
|
|
- ssh -i ~/.ssh/deploy_key -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes "${DEPLOY_USER}@${DEPLOY_HOST}" "cd ${DEPLOY_PATH} && docker compose up -d --build"
|
|
# Note: Caddy configuration needs to be reloaded manually if it's the first time.
|
|
- echo "Deployment finished. Remember to include ${DEPLOY_PATH}/Caddyfile in your global /etc/caddy/Caddyfile and reload caddy if you haven't yet!"
|