Update .gitlab-ci.yml file
This commit is contained in:
parent
1a8084211f
commit
b427d07b2e
1 changed files with 113 additions and 5 deletions
116
.gitlab-ci.yml
116
.gitlab-ci.yml
|
@ -1,11 +1,119 @@
|
|||
stages:
|
||||
- lint
|
||||
- validate
|
||||
- build
|
||||
- deploy
|
||||
- post_deploy
|
||||
- scripts
|
||||
|
||||
.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_gitlab
|
||||
- chmod 600 ~/.ssh/key_gitlab
|
||||
- echo "Host $DEPLOY_HOST" >> ~/.ssh/config
|
||||
- echo $'\n\tIdentityFile ~/.ssh/key_gitlab' >> ~/.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"
|
||||
|
||||
linter:
|
||||
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/node:latest
|
||||
stage: lint
|
||||
linting:
|
||||
image: node:lts
|
||||
stage: validate
|
||||
only:
|
||||
- main
|
||||
before_script:
|
||||
- yarn install
|
||||
script:
|
||||
- echo "Running linter"
|
||||
- yarn lint
|
||||
|
||||
build-site:
|
||||
image: node:lts
|
||||
stage: build
|
||||
when: on_success
|
||||
cache:
|
||||
paths:
|
||||
- node_modules/
|
||||
only:
|
||||
- main
|
||||
script:
|
||||
- yarn install
|
||||
- yarn build
|
||||
artifacts:
|
||||
paths:
|
||||
- public
|
||||
expire_in: 1 day
|
||||
|
||||
deploy-site:
|
||||
stage: deploy
|
||||
when: on_success
|
||||
only:
|
||||
- main
|
||||
before_script:
|
||||
- *ssh_default
|
||||
script:
|
||||
- echo "Getting artifacts"
|
||||
- ls public
|
||||
- echo "Stopping screen session, cleaning"
|
||||
- ssh $DEPLOY_USER@$DEPLOY_HOST "screen -X -S stellaris kill; rm -r -f public/*;"
|
||||
- echo "Copying to proxmox machine"
|
||||
- rsync -az --stats public $DEPLOY_USER@$DEPLOY_HOST:~/.
|
||||
- echo "Restarting screen session"
|
||||
- ssh $DEPLOY_USER@$DEPLOY_HOST "find maintenance public -maxdepth 1 -printf '%p\n'; screen -S stellaris -dm yarn start"
|
||||
- echo "Website is up on https://stellaris.neshweb.net/"
|
||||
|
||||
success_notification:
|
||||
stage: post_deploy
|
||||
before_script:
|
||||
- apk update
|
||||
- apk add rsync
|
||||
- apk add curl
|
||||
- apk add git
|
||||
- apk add bash
|
||||
script:
|
||||
- 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
|
||||
|
||||
failure_notification:
|
||||
stage: post_deploy
|
||||
before_script:
|
||||
- apk update
|
||||
- apk add curl
|
||||
- apk add git
|
||||
- apk add bash
|
||||
script:
|
||||
- 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
|
||||
|
||||
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 stellaris kill;"
|
||||
- echo "Enabeling maintenance mode"
|
||||
- ssh $DEPLOY_USER@$DEPLOY_HOST "screen -S stellaris -dm yarn start"
|
||||
- echo "Maintenance Website is up on https://stellaris.neshweb.net/"
|
||||
|
||||
redeploy-site:
|
||||
stage: scripts
|
||||
when: manual
|
||||
before_script:
|
||||
- *ssh_default
|
||||
script:
|
||||
- echo "Stopping screen session"
|
||||
- ssh $DEPLOY_USER@$DEPLOY_HOST "screen -X -S stellaris kill" || true
|
||||
- echo "Restarting screen session"
|
||||
- ssh $DEPLOY_USER@$DEPLOY_HOST "screen -S stellaris -dm yarn start"
|
||||
- echo "Website is up on https://stellaris.neshweb.net/"
|
||||
|
|
Reference in a new issue