Skip to content

Instantly share code, notes, and snippets.

@Lory1990
Created May 26, 2020 06:49
Show Gist options
  • Select an option

  • Save Lory1990/29afbd72d63b8f719e8377e646fe7ea2 to your computer and use it in GitHub Desktop.

Select an option

Save Lory1990/29afbd72d63b8f719e8377e646fe7ea2 to your computer and use it in GitHub Desktop.
GitLab CD/CI pipeline for a parallel deploy
stages:
- load Libraries
- build
- create_docker_image
- deploy
Load Libraries:
image: node:lts-slim
when: manual
stage: load Libraries
allow_failure: false
cache:
paths:
- node_modules/
script:
- npx pnpm add -g pnpm
- pnpm install
artifacts:
paths:
- node_modules
Build Test:
when: on_success
image: node:lts-slim
stage: build
allow_failure: false
dependencies:
- Load Libraries
script:
- npx pnpm add -g pnpm
- pnpm run build-test
artifacts:
paths:
- server
Build Prod:
when: manual
image: node:lts-slim
stage: build
allow_failure: false
dependencies:
- Load Libraries
script:
- npx pnpm add -g pnpm
- pnpm run build
artifacts:
paths:
- server
Deploy Sftp Test:
stage: deploy
image: jimmyadaro/gitlab-ci-cd:latest
when: on_success
environment:
name: test
allow_failure: false
needs:
- Build Test
dependencies:
- Build Test
before_script:
- 'which ssh-agent || ( apt-get install -qq openssh-client )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- lftp -d -u $APP_SERVER_USER, -e 'set sftp:auto-confirm true; set sftp:connect-program "ssh -a -x -i ~/.ssh/id_rsa"; mirror -Rnev ./build /var/www/test/frontend/admin-the-pt; exit' sftp://$APP_SERVER_IP:$APP_SERVER_PORT
Deploy Sftp Prod:
stage: deploy
image: jimmyadaro/gitlab-ci-cd:latest
when: on_success
environment:
name: prod
allow_failure: false
needs:
- Build Prod
dependencies:
- Build Prod
before_script:
- 'which ssh-agent || ( apt-get install -qq openssh-client )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- lftp -d -u $APP_SERVER_USER, -e 'set sftp:auto-confirm true; set sftp:connect-program "ssh -a -x -i ~/.ssh/id_rsa"; mirror -Rnev ./build /var/www/prod/frontend/admin-the-pt; exit' sftp://$APP_SERVER_IP:$APP_SERVER_PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment