2023-12-20 16:06:50 -05:00
|
|
|
# define the stages in this pipeline
|
|
|
|
stages:
|
2023-12-18 23:09:44 -05:00
|
|
|
- build
|
|
|
|
- deploy
|
|
|
|
|
2023-12-20 16:06:50 -05:00
|
|
|
# define the build stage
|
|
|
|
build_stage:
|
2023-12-18 23:09:44 -05:00
|
|
|
stage: build
|
2023-12-20 16:06:50 -05:00
|
|
|
# use node docker image as enviroment
|
|
|
|
image: node:latest
|
2023-12-18 23:09:44 -05:00
|
|
|
script:
|
2023-12-20 16:06:50 -05:00
|
|
|
# install & build the NuxtJS application
|
|
|
|
- npm install
|
|
|
|
- npm run build
|
|
|
|
# define artifacts which are shared between stages
|
|
|
|
artifacts:
|
|
|
|
paths:
|
|
|
|
- .nuxt/
|
|
|
|
- node_modules/
|
2023-12-18 23:09:44 -05:00
|
|
|
|
2023-12-20 16:06:50 -05:00
|
|
|
# restrict to specific branch
|
|
|
|
only:
|
|
|
|
- master
|
2023-12-18 23:09:44 -05:00
|
|
|
|
2023-12-20 16:06:50 -05:00
|
|
|
# define the deploy stage
|
|
|
|
deploy_stage:
|
|
|
|
stage: deploy
|
|
|
|
# use our deploy image
|
|
|
|
image: ubuntu:latest
|
|
|
|
# install needed packages
|
|
|
|
# add the SSH key from the variable SSH_DEPLOY_KEY and disable StrictHostKeyChecking
|
|
|
|
before_script:
|
|
|
|
- apt-get update && apt-get install --yes --no-install-recommends rsync git openssh-client curl
|
|
|
|
- eval $(ssh-agent -s)
|
|
|
|
- ssh-add <(echo "${SSH_DEPLOY_KEY}")
|
|
|
|
- mkdir -p ~/.ssh
|
|
|
|
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
|
2023-12-18 23:09:44 -05:00
|
|
|
|
|
|
|
script:
|
2023-12-20 16:06:50 -05:00
|
|
|
# deploy application and server configuration
|
|
|
|
- rsync --archive --delete ${CI_PROJECT_DIR}/ ${DEPLOY_USER}@${DEPLOY_SERVER}:~/opsone-demo/
|
|
|
|
- rsync --archive --delete ${CI_PROJECT_DIR}/cnf/ ${DEPLOY_USER}@${DEPLOY_SERVER}:~/cnf/
|
|
|
|
|
|
|
|
# restart Node.js and reload nginx configuration
|
|
|
|
- ssh ${DEPLOY_USER}@${DEPLOY_SERVER} nodejs-restart
|
|
|
|
- ssh ${DEPLOY_USER}@${DEPLOY_SERVER} nginx-reload
|
|
|
|
|
|
|
|
# restrict to specific branch
|
|
|
|
only:
|
|
|
|
- master
|