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
|
2023-12-25 22:59:31 -05:00
|
|
|
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
|
2023-12-25 21:18:09 -05:00
|
|
|
- apt update
|
2023-12-26 09:04:02 -05:00
|
|
|
#- apt-get install -y --no-install-recommends python3 build-essential
|
2023-12-25 22:59:31 -05:00
|
|
|
- npm install
|
|
|
|
- npm run build
|
2023-12-20 16:06:50 -05:00
|
|
|
# define artifacts which are shared between stages
|
|
|
|
artifacts:
|
|
|
|
paths:
|
2023-12-25 21:18:09 -05:00
|
|
|
- .output/
|
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:
|
2023-12-26 09:04:02 -05:00
|
|
|
- apt-get update && apt-get install --yes --no-install-recommends rsync git openssh-client curl sshpass
|
2023-12-20 16:06:50 -05:00
|
|
|
- eval $(ssh-agent -s)
|
2023-12-25 21:18:09 -05:00
|
|
|
- chmod 600 ${SSH_DEPLOY_KEY}
|
|
|
|
- ssh-add ${SSH_DEPLOY_KEY}
|
2023-12-20 16:06:50 -05:00
|
|
|
- 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
|
2023-12-25 21:18:09 -05:00
|
|
|
- cat ${ENV_FILE} | ssh rockfic@${DEPLOY_SERVER} 'cat > rockfic-staging/.env'
|
|
|
|
- rsync --archive --delete ${CI_PROJECT_DIR}/ rockfic@${DEPLOY_SERVER}:~/rockfic-staging/
|
|
|
|
#- rsync --archive --delete ${CI_PROJECT_DIR}/cnf/ ${DEPLOY_USER}@${DEPLOY_SERVER}:~/cnf/
|
2023-12-20 16:06:50 -05:00
|
|
|
|
|
|
|
# restart Node.js and reload nginx configuration
|
2023-12-26 09:48:05 -05:00
|
|
|
- sshpass -p "${OLDROOTPWD}" ssh root@rockfic.com '~/cp.sh'
|
2023-12-26 09:40:07 -05:00
|
|
|
- ssh rockfic@${DEPLOY_SERVER} "mongosh mongodb://localhost --eval \"use ${DB_NAME}; db.dropDatabase();\""
|
2023-12-26 09:13:13 -05:00
|
|
|
- ssh rockfic@${DEPLOY_SERVER} 'mongorestore -d rockfic_old dump/rockfic
|
2023-12-25 21:18:09 -05:00
|
|
|
- ssh rockfic@${DEPLOY_SERVER} 'cd migrator && bun install && bun run ./index.ts'
|
2023-12-25 22:59:31 -05:00
|
|
|
- ssh rockfic@${DEPLOY_SERVER} node run "~/rockfic-staging/.output/server/index.mjs" \&\>/dev/null \& disown \%1
|
2023-12-25 21:18:09 -05:00
|
|
|
- ssh rockfic@${DEPLOY_SERVER} systemctl reload apache2
|
|
|
|
environment:
|
|
|
|
name: staging
|
|
|
|
url: https://next.rockfic.com
|
2023-12-20 16:06:50 -05:00
|
|
|
# restrict to specific branch
|
|
|
|
only:
|
|
|
|
- master
|