refactor(ci): restructure
use separate pipelines for building for staging and production, respectively streamline repetitive steps into scripts stored in `.more-ci/` BREAKING CHANGE: this might break literally everything lol
This commit is contained in:
parent
5bb6803a30
commit
d6f146c481
@ -4,6 +4,7 @@ stages:
|
|||||||
- deploy
|
- deploy
|
||||||
|
|
||||||
# define the build stage
|
# define the build stage
|
||||||
|
|
||||||
build_stage:
|
build_stage:
|
||||||
stage: build
|
stage: build
|
||||||
# use node docker image as enviroment
|
# use node docker image as enviroment
|
||||||
@ -18,46 +19,53 @@ build_stage:
|
|||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- .output/
|
- .output/
|
||||||
|
- .nuxt/
|
||||||
|
|
||||||
# restrict to specific branch
|
# restrict to specific branch
|
||||||
only:
|
# only:
|
||||||
- master
|
# - master
|
||||||
|
|
||||||
# define the deploy stage
|
# define the deploy stage
|
||||||
deploy_stage:
|
deploy_staging:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
# use our deploy image
|
environment:
|
||||||
|
name: staging
|
||||||
|
url: https://next.rockfic.com
|
||||||
image: ubuntu:latest
|
image: ubuntu:latest
|
||||||
# install needed packages
|
# - apt-get update && apt-get install --yes --no-install-recommends rsync git openssh-client curl sshpass
|
||||||
# add the SSH key from the variable SSH_DEPLOY_KEY and disable StrictHostKeyChecking
|
# - eval $(ssh-agent -s)
|
||||||
before_script:
|
# - chmod 600 ${SSH_DEPLOY_KEY}
|
||||||
- apt-get update && apt-get install --yes --no-install-recommends rsync git openssh-client curl sshpass
|
# - ssh-add ${SSH_DEPLOY_KEY}
|
||||||
- eval $(ssh-agent -s)
|
# - mkdir -p ~/.ssh
|
||||||
- chmod 600 ${SSH_DEPLOY_KEY}
|
# - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
|
||||||
- ssh-add ${SSH_DEPLOY_KEY}
|
|
||||||
- mkdir -p ~/.ssh
|
|
||||||
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
# deploy application and server configuration
|
- bash ${CI_PROJECT_DIR}/.more-ci/deploy-pre.sh ${SSH_DEPLOY_KEY}
|
||||||
# - "cat ${ENV_FILE} | ssh rockfic@${DEPLOY_SERVER} 'cat > ~/rockfic-staging/.env'"
|
# - "cat ${ENV_FILE} | ssh rockfic@${DEPLOY_SERVER} 'cat > ~/rockfic-staging/.env'"
|
||||||
- rsync --archive --delete ${CI_PROJECT_DIR}/ rockfic@${DEPLOY_SERVER}:~/rockfic-staging/
|
- rsync --archive --del ${CI_PROJECT_DIR}/ rockfic@${DEPLOY_SERVER}:~/rockfic-staging/
|
||||||
- scp ${ENV_FILE} rockfic@${DEPLOY_SERVER}:rockfic-staging/.env
|
- scp ${ENV_FILE} rockfic@${DEPLOY_SERVER}:rockfic-staging/.env
|
||||||
#- rsync --archive --delete ${CI_PROJECT_DIR}/cnf/ ${DEPLOY_USER}@${DEPLOY_SERVER}:~/cnf/
|
#- rsync --archive --delete ${CI_PROJECT_DIR}/cnf/ ${DEPLOY_USER}@${DEPLOY_SERVER}:~/cnf/
|
||||||
|
|
||||||
# restart Node.js and reload nginx configuration
|
# restart Node.js and reload nginx configuration
|
||||||
- sshpass -p "${OLDROOTPWD}" ssh root@rockfic.com '~/cp.sh'
|
- sshpass -p "${OLDROOTPWD}" ssh root@rockfic.com '~/cp.sh'
|
||||||
- ssh rockfic@${DEPLOY_SERVER} "mongosh mongodb://localhost:27017 <(echo -e 'use rockfic_old\ndb.dropDatabase()\nuse ${DB_NAME}\ndb.dropDatabase()')"
|
- ssh rockfic@${DEPLOY_SERVER} "~/stage.sh"
|
||||||
- ssh rockfic@${DEPLOY_SERVER} mongosh mongodb://localhost:27017/${DB_NAME} --eval '"db.dropDatabase()"'
|
|
||||||
- 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'
|
|
||||||
- ssh rockfic@${DEPLOY_SERVER} 'sed -Ei "s,(hasMigrated = )false,\1true," rockfic-staging/lib/dbconfig.ts'
|
|
||||||
- ssh rockfic@${DEPLOY_SERVER} "kill `pidof node`"
|
|
||||||
- ssh rockfic@${DEPLOY_SERVER} node "~/rockfic-staging/.output/server/index.mjs" \&\>/dev/null \& disown \%1
|
- ssh rockfic@${DEPLOY_SERVER} node "~/rockfic-staging/.output/server/index.mjs" \&\>/dev/null \& disown \%1
|
||||||
- ssh rockfic@${DEPLOY_SERVER} sudo systemctl reload apache2
|
- ssh rockfic@${DEPLOY_SERVER} sudo systemctl reload apache2
|
||||||
|
except:
|
||||||
|
- tags
|
||||||
|
deploy_production:
|
||||||
|
stage: deploy
|
||||||
environment:
|
environment:
|
||||||
name: staging
|
name: production
|
||||||
url: https://next.rockfic.com
|
url: https://www.rockfic.com
|
||||||
# restrict to specific branch
|
image: ubuntu:latest
|
||||||
|
script:
|
||||||
|
- bash ${CI_PROJECT_DIR}/.more-ci/deploy-pre.sh ${SSH_DEPLOY_KEY}
|
||||||
|
- rsync --archive --del ${CI_PROJECT_DIR}/ root@${DEPLOY_SERVER}:/home/@rockfic/
|
||||||
|
- scp ${ENV_FILE} root@${DEPLOY_SERVER}:/home/@rockfic/.env
|
||||||
|
#- rsync --archive --delete ${CI_PROJECT_DIR}/cnf/ ${DEPLOY_USER}@${DEPLOY_SERVER}:~/cnf/
|
||||||
|
- ssh root@${DEPLOY_SERVER} node "/home/@rockfic/.output/server/index.mjs" \&\>/dev/null \& disown \%1
|
||||||
|
- ssh rockfic@${DEPLOY_SERVER} sudo systemctl reload apache2
|
||||||
only:
|
only:
|
||||||
- master
|
- tags
|
||||||
|
# restrict to specific branch
|
||||||
|
7
.more-ci/deploy-pre.sh
Normal file
7
.more-ci/deploy-pre.sh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
apt-get update && apt-get install --yes --no-install-recommends rsync git openssh-client curl sshpass
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
chmod 600 $1
|
||||||
|
ssh-add $1
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
|
Loading…
Reference in New Issue
Block a user