78 lines
3.2 KiB
YAML
78 lines
3.2 KiB
YAML
stages:
|
|
- sync
|
|
- deploy
|
|
|
|
variables:
|
|
DEPLOY_HOST: "217.160.174.2"
|
|
DEPLOY_USER: "root"
|
|
DEPLOY_PATH: "/opt/OrgMyLife"
|
|
|
|
.ssh_setup: &ssh_setup
|
|
before_script:
|
|
- apt-get update -qq && apt-get install -y openssh-client rsync curl
|
|
- 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
|
|
|
|
deploy-vps:
|
|
stage: deploy
|
|
image: node:20
|
|
<<: *ssh_setup
|
|
rules:
|
|
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'
|
|
changes:
|
|
- "shared/OrgMyLife/**/*"
|
|
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}"
|
|
- |
|
|
cat <<EOF > .env
|
|
POSTGRES_PASSWORD=$ENV_POSTGRES_PASSWORD
|
|
API_SECRET=$ENV_API_SECRET
|
|
APP_USERNAME=$ENV_APP_USERNAME
|
|
APP_PASSWORD=$ENV_APP_PASSWORD
|
|
NEXTCLOUD_URL=$ENV_NEXTCLOUD_URL
|
|
NEXTCLOUD_USERNAME=$ENV_NEXTCLOUD_USERNAME
|
|
NEXTCLOUD_PASSWORD=$ENV_NEXTCLOUD_PASSWORD
|
|
IMAP_SERVER=$ENV_IMAP_SERVER
|
|
IMAP_PORT=993
|
|
EMAIL_USERNAME=$ENV_EMAIL_USERNAME
|
|
EMAIL_PASSWORD=$ENV_EMAIL_PASSWORD
|
|
EMAIL_WEBMAIL_URL=$ENV_EMAIL_WEBMAIL_URL
|
|
GMAIL_USERNAME=$ENV_GMAIL_USERNAME
|
|
GMAIL_PASSWORD=$ENV_GMAIL_PASSWORD
|
|
EOF
|
|
- rsync -az --delete -e "ssh -i ~/.ssh/deploy_key -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes" shared/OrgMyLife/ "${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/"
|
|
- rsync -az -e "ssh -i ~/.ssh/deploy_key -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes" .env "${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/.env"
|
|
- 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"
|
|
|
|
collect-tasks:
|
|
stage: sync
|
|
image: alpine:latest
|
|
rules:
|
|
- if: '$CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TARGET == "collect-tasks"'
|
|
script:
|
|
- apk add --no-cache curl jq
|
|
- |
|
|
curl -s -u "${ORGMYLIFE_USER}:${ORGMYLIFE_PASS}" \
|
|
-H "Authorization: Bearer ${ORGMYLIFE_API_SECRET}" \
|
|
"https://api.andreknie.de/api/orchestrator/tasks" > /tmp/tasks.json
|
|
- echo "Tasks fetched. Since GitLab handles issues differently, issue creation logic needs to be adapted for GitLab API."
|
|
|
|
backup-dismissed:
|
|
stage: sync
|
|
image: alpine:latest
|
|
rules:
|
|
- if: '$CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TARGET == "backup-dismissed"'
|
|
script:
|
|
- apk add --no-cache curl git
|
|
- |
|
|
curl -s -u "${ORGMYLIFE_USER}:${ORGMYLIFE_PASS}" \
|
|
-H "Authorization: Bearer ${ORGMYLIFE_API_SECRET}" \
|
|
"https://api.andreknie.de/api/tasks/dismissed" > shared/OrgMyLife/dismissed_tasks.json
|
|
- git config user.name "gitlab-ci[bot]"
|
|
- git config user.email "gitlab-ci[bot]@gitlab.dhive.io"
|
|
- git add shared/OrgMyLife/dismissed_tasks.json
|
|
- git diff --cached --quiet || (git commit -m "chore: backup dismissed task IDs [skip ci]" && git push "https://oauth2:${PROJECT_ACCESS_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" HEAD:$CI_COMMIT_BRANCH)
|