CI change, added maintenance fallback if deployment fails
This commit is contained in:
parent
18fd2da104
commit
716e817723
1 changed files with 33 additions and 18 deletions
|
@ -1,7 +1,23 @@
|
||||||
stages:
|
stages:
|
||||||
- build
|
- build
|
||||||
- deploy
|
- deploy
|
||||||
- notification
|
- post_deploy
|
||||||
|
|
||||||
|
.ssh_default: &ssh_default
|
||||||
|
- 'which rsync || ( apk update && apk add rsync )'
|
||||||
|
- 'which ssh-agent || ( apk update && apk add openssh-client)'
|
||||||
|
- eval $(ssh-agent -s)
|
||||||
|
- mkdir -p ~/.ssh
|
||||||
|
- chmod 700 ~/.ssh
|
||||||
|
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' >> ~/.ssh/key_firq
|
||||||
|
- chmod 600 ~/.ssh/key_firq
|
||||||
|
- echo "Host $DEPLOY_HOST" >> ~/.ssh/config
|
||||||
|
- echo $'\n\tIdentityFile ~/.ssh/key_firq' >> ~/.ssh/config
|
||||||
|
- echo $'\n\tStrictHostKeyChecking no\n\tIdentitiesOnly yes\n' >> ~/.ssh/config
|
||||||
|
- chmod 644 ~/.ssh/config
|
||||||
|
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
|
||||||
|
- chmod 644 ~/.ssh/known_hosts
|
||||||
|
- echo "SSH setup completed"
|
||||||
|
|
||||||
build-site:
|
build-site:
|
||||||
image: node:lts
|
image: node:lts
|
||||||
|
@ -26,24 +42,11 @@ deploy-site:
|
||||||
only:
|
only:
|
||||||
- main
|
- main
|
||||||
before_script:
|
before_script:
|
||||||
- 'which rsync || ( apk update && apk add rsync )'
|
- *ssh_default
|
||||||
- 'which ssh-agent || ( apk update && apk add openssh-client)'
|
|
||||||
- eval $(ssh-agent -s)
|
|
||||||
- mkdir -p ~/.ssh
|
|
||||||
- chmod 700 ~/.ssh
|
|
||||||
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' >> ~/.ssh/key_firq
|
|
||||||
- chmod 600 ~/.ssh/key_firq
|
|
||||||
- echo "Host $DEPLOY_HOST" >> ~/.ssh/config
|
|
||||||
- echo $'\n\tIdentityFile ~/.ssh/key_firq' >> ~/.ssh/config
|
|
||||||
- echo $'\n\tStrictHostKeyChecking no\n\tIdentitiesOnly yes\n' >> ~/.ssh/config
|
|
||||||
- chmod 644 ~/.ssh/config
|
|
||||||
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
|
|
||||||
- chmod 644 ~/.ssh/known_hosts
|
|
||||||
- echo "SSH setup completed"
|
|
||||||
script:
|
script:
|
||||||
- echo "Getting artifacts"
|
- echo "Getting artifacts"
|
||||||
- ls public
|
- ls public
|
||||||
- echo "Stopping screen session, enabling maintenance mode, cleaning"
|
- echo "Stopping screen session, cleaning"
|
||||||
- ssh $DEPLOY_USER@$DEPLOY_HOST "screen -X -S website-firq-npx kill; rm -r -f public/*;"
|
- ssh $DEPLOY_USER@$DEPLOY_HOST "screen -X -S website-firq-npx kill; rm -r -f public/*;"
|
||||||
- echo "Copying to proxmox machine"
|
- echo "Copying to proxmox machine"
|
||||||
- rsync -az --stats public $DEPLOY_USER@$DEPLOY_HOST:~/.
|
- rsync -az --stats public $DEPLOY_USER@$DEPLOY_HOST:~/.
|
||||||
|
@ -52,7 +55,7 @@ deploy-site:
|
||||||
- echo "Website is up on https://firq.dev/"
|
- echo "Website is up on https://firq.dev/"
|
||||||
|
|
||||||
success_notification:
|
success_notification:
|
||||||
stage: notification
|
stage: post_deploy
|
||||||
before_script:
|
before_script:
|
||||||
- apk update
|
- apk update
|
||||||
- apk add rsync
|
- apk add rsync
|
||||||
|
@ -66,7 +69,7 @@ success_notification:
|
||||||
when: on_success
|
when: on_success
|
||||||
|
|
||||||
failure_notification:
|
failure_notification:
|
||||||
stage: notification
|
stage: post_deploy
|
||||||
before_script:
|
before_script:
|
||||||
- apk update
|
- apk update
|
||||||
- apk add curl
|
- apk add curl
|
||||||
|
@ -77,3 +80,15 @@ failure_notification:
|
||||||
- chmod +x send.sh
|
- chmod +x send.sh
|
||||||
- ./send.sh failure $WEBHOOK_URL
|
- ./send.sh failure $WEBHOOK_URL
|
||||||
when: on_failure
|
when: on_failure
|
||||||
|
|
||||||
|
maintenance-mode:
|
||||||
|
stage: post_deploy
|
||||||
|
when: on_failure
|
||||||
|
before_script:
|
||||||
|
- *ssh_default
|
||||||
|
script:
|
||||||
|
- echo "Stopping screen session"
|
||||||
|
- ssh $DEPLOY_USER@$DEPLOY_HOST "screen -X -S website-firq-npx kill;"
|
||||||
|
- echo "Enabeling maintenance mode"
|
||||||
|
- ssh $DEPLOY_USER@$DEPLOY_HOST "screen -S website-firq-npx -dm npx serve maintenance/ -p 9000 -c serve.json"
|
||||||
|
- echo "Maintenance Website is up on https://firq.dev/"
|
||||||
|
|
Loading…
Reference in a new issue