next/.gitlab-ci.yml

63 lines
2.4 KiB
YAML
Raw Normal View History

# define the stages in this pipeline
stages:
2023-12-18 23:09:44 -05:00
- build
- deploy
# define the build stage
build_stage:
2023-12-18 23:09:44 -05:00
stage: build
# use node docker image as enviroment
image: node:latest
2023-12-18 23:09:44 -05:00
script:
# install & build the NuxtJS application
- apt update
#- apt-get install -y --no-install-recommends python3 build-essential
- npm install
- npm run build
# define artifacts which are shared between stages
artifacts:
paths:
- .output/
2023-12-18 23:09:44 -05:00
# restrict to specific branch
only:
- master
2023-12-18 23:09:44 -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 sshpass
- eval $(ssh-agent -s)
- chmod 600 ${SSH_DEPLOY_KEY}
- ssh-add ${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:
# deploy application and server configuration
2023-12-26 17:09:35 -05:00
# - "cat ${ENV_FILE} | ssh rockfic@${DEPLOY_SERVER} 'cat > ~/rockfic-staging/.env'"
- rsync --archive --delete ${CI_PROJECT_DIR}/ rockfic@${DEPLOY_SERVER}:~/rockfic-staging/
2023-12-26 18:54:12 -05:00
- scp ${ENV_FILE} rockfic@${DEPLOY_SERVER}:rockfic-staging/.env
#- rsync --archive --delete ${CI_PROJECT_DIR}/cnf/ ${DEPLOY_USER}@${DEPLOY_SERVER}:~/cnf/
# 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-28 07:16:13 -05:00
- ssh rockfic@${DEPLOY_SERVER} mongosh mongodb://localhost:27017 <(echo -e "use rockfic_old\ndb.dropDatabase()\nuse \${DB_NAME}\ndb.dropDatabase()")
- ssh rockfic@${DEPLOY_SERVER} mongosh mongodb://localhost:27017/${DB_NAME} --eval 'db.dropDatabase()'
2023-12-26 17:36:18 -05:00
- ssh rockfic@${DEPLOY_SERVER} 'mongorestore --drop -d rockfic_old dump/rockfic'
- ssh rockfic@${DEPLOY_SERVER} 'cd migrator && bun install && NODE_ENV=production bun run ./index.ts'
2023-12-26 20:20:02 -05:00
- ssh rockfic@${DEPLOY_SERVER} 'sed -Ei "s,(hasMigrated = )false,\1true," rockfic-staging/lib/dbconfig.ts'
2023-12-26 18:54:12 -05:00
- ssh rockfic@${DEPLOY_SERVER} node "~/rockfic-staging/.output/server/index.mjs" \&\>/dev/null \& disown \%1
2023-12-28 07:00:25 -05:00
- ssh rockfic@${DEPLOY_SERVER} sudo systemctl reload apache2
environment:
name: staging
url: https://next.rockfic.com
# restrict to specific branch
only:
- master