stages: - build - test - 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 == "main"' 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 == "main"' 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 < .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" - ssh -i ~/.ssh/deploy_key -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes "${DEPLOY_USER}@${DEPLOY_HOST}" "cd ${DEPLOY_PATH} && docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile" - echo "Deployment finished. Caddy configuration reloaded successfully." smoketest: stage: test image: node:20 rules: - if: '$CI_PIPELINE_SOURCE == "schedule"' script: - cd privat/CV/andreknie.de - npm ci - node scripts/smoketest.js artifacts: paths: - privat/CV/andreknie.de/public-dashboard/ expire_in: 1 week pages: stage: deploy image: alpine:latest rules: - if: '$CI_PIPELINE_SOURCE == "schedule"' dependencies: - smoketest script: - mv privat/CV/andreknie.de/public-dashboard public artifacts: paths: - public expire_in: 1 week