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
|
2023-12-28 17:49:41 -05:00
|
|
|
|
2023-12-20 16:06:50 -05:00
|
|
|
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-28 17:49:41 -05:00
|
|
|
- .nuxt/
|
2023-12-18 23:09:44 -05:00
|
|
|
|
2023-12-20 16:06:50 -05:00
|
|
|
# restrict to specific branch
|
2023-12-28 17:49:41 -05:00
|
|
|
# only:
|
|
|
|
# - master
|
2023-12-18 23:09:44 -05:00
|
|
|
|
2023-12-20 16:06:50 -05:00
|
|
|
# define the deploy stage
|
2023-12-28 17:49:41 -05:00
|
|
|
deploy_staging:
|
2023-12-20 16:06:50 -05:00
|
|
|
stage: deploy
|
2023-12-28 18:53:29 -05:00
|
|
|
resource_group: staging
|
2023-12-28 20:03:41 -05:00
|
|
|
needs:
|
|
|
|
- build_stage
|
2023-12-28 17:49:41 -05:00
|
|
|
environment:
|
|
|
|
name: staging
|
|
|
|
url: https://next.rockfic.com
|
2023-12-20 16:06:50 -05:00
|
|
|
image: ubuntu:latest
|
2023-12-28 17:49:41 -05:00
|
|
|
# - 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-28 17:57:08 -05:00
|
|
|
before_script:
|
2023-12-28 18:19:32 -05:00
|
|
|
- ". ${CI_PROJECT_DIR}/.more-ci/deploy-pre.sh ${SSH_DEPLOY_KEY}"
|
2023-12-28 17:57:08 -05:00
|
|
|
script:
|
2023-12-26 17:09:35 -05:00
|
|
|
# - "cat ${ENV_FILE} | ssh rockfic@${DEPLOY_SERVER} 'cat > ~/rockfic-staging/.env'"
|
2023-12-28 17:49:41 -05:00
|
|
|
- rsync --archive --del ${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
|
2023-12-25 21:18:09 -05:00
|
|
|
#- 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-28 18:29:41 -05:00
|
|
|
- ssh rockfic@${DEPLOY_SERVER} "~/stage.sh" ${DB_NAME}
|
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
|
2023-12-28 17:49:41 -05:00
|
|
|
except:
|
|
|
|
- tags
|
|
|
|
deploy_production:
|
|
|
|
stage: deploy
|
2023-12-28 20:03:41 -05:00
|
|
|
needs:
|
|
|
|
- build_stage
|
2023-12-28 18:53:29 -05:00
|
|
|
resource_group: production
|
2023-12-25 21:18:09 -05:00
|
|
|
environment:
|
2023-12-28 17:49:41 -05:00
|
|
|
name: production
|
|
|
|
url: https://www.rockfic.com
|
|
|
|
image: ubuntu:latest
|
2023-12-28 17:57:08 -05:00
|
|
|
before_script:
|
2023-12-28 18:19:32 -05:00
|
|
|
- ". ${CI_PROJECT_DIR}/.more-ci/deploy-pre.sh ${SSH_DEPLOY_KEY}"
|
2023-12-28 17:57:08 -05:00
|
|
|
script:
|
2023-12-28 17:49:41 -05:00
|
|
|
- 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/
|
2023-12-28 18:38:47 -05:00
|
|
|
- sed -Ei "s,(hasMigrated = )false,\1true," /home/@rockfic/lib/dbconfig.ts
|
2023-12-28 17:49:41 -05:00
|
|
|
- ssh root@${DEPLOY_SERVER} node "/home/@rockfic/.output/server/index.mjs" \&\>/dev/null \& disown \%1
|
2023-12-28 17:57:08 -05:00
|
|
|
- ssh root@${DEPLOY_SERVER} sudo systemctl reload apache2
|
2023-12-20 16:06:50 -05:00
|
|
|
only:
|
2023-12-28 17:49:41 -05:00
|
|
|
- tags
|
|
|
|
# restrict to specific branch
|