firq-dev-website/.gitlab-ci.yml

82 lines
2.3 KiB
YAML
Raw Normal View History

stages:
2023-03-17 01:01:20 +00:00
- build
2023-03-11 00:15:01 +00:00
- deploy
- notification
2023-03-17 01:01:20 +00:00
build-site:
image: node:lts
stage: build
cache:
paths:
- node_modules/
only:
- main
script:
- npm install
- npm run build
- rm -r public/assets/data/
- cp serve.json public
artifacts:
paths:
- public
expire_in: 1 day
deploy-site:
stage: deploy
2023-03-17 01:01:20 +00:00
only:
- main
before_script:
- '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"
script:
2023-03-17 01:01:20 +00:00
- echo "Getting artifacts"
- ls public
2023-03-18 00:54:10 +00:00
- echo "Stopping screen session, enabling maintenance mode, cleaning"
- ssh $DEPLOY_USER@$DEPLOY_HOST "screen -X -S website-firq-npx kill; rm -r -f public/*; screen -S maintenance -dm npx serve maintenance/ -p 9000 -c serve.json"
2023-03-17 01:01:20 +00:00
- echo "Copying to proxmox machine"
- rsync -az --stats public $DEPLOY_USER@$DEPLOY_HOST:~/.
2023-03-18 00:54:10 +00:00
- echo "Ending maintenance mode"
- ssh $DEPLOY_USER@$DEPLOY_HOST "screen -X -S maintenance kill;"
2023-03-17 01:01:20 +00:00
- echo "Restarting screen session"
- ssh $DEPLOY_USER@$DEPLOY_HOST "screen -S website-firq-npx -dm npx serve public/ -p 9000 -c serve.json"
2023-03-17 01:01:20 +00:00
- echo "Website is up on https://firq.dev/"
success_notification:
stage: notification
2023-03-11 00:04:56 +00:00
before_script:
2023-03-11 00:10:19 +00:00
- apk update
2023-03-17 01:01:20 +00:00
- apk add rsync
2023-03-11 00:10:19 +00:00
- apk add curl
- apk add git
2023-03-11 00:31:48 +00:00
- apk add bash
script:
2023-03-11 00:31:48 +00:00
- wget https://raw.githubusercontent.com/DiscordHooks/gitlab-ci-discord-webhook/master/send.sh
- chmod +x send.sh
- ./send.sh success $WEBHOOK_URL
when: on_success
2023-03-17 17:56:34 +00:00
failure_notification:
stage: notification
2023-03-11 00:04:56 +00:00
before_script:
2023-03-11 00:10:19 +00:00
- apk update
- apk add curl
- apk add git
2023-03-11 00:31:48 +00:00
- apk add bash
script:
2023-03-11 00:31:48 +00:00
- wget https://raw.githubusercontent.com/DiscordHooks/gitlab-ci-discord-webhook/master/send.sh
- chmod +x send.sh
- ./send.sh failure $WEBHOOK_URL
when: on_failure