Skip to content

Instantly share code, notes, and snippets.

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

  • Save Lory1990/452ee2ad9bd063b22e42bb04ca09b2ea to your computer and use it in GitHub Desktop.

Select an option

Save Lory1990/452ee2ad9bd063b22e42bb04ca09b2ea to your computer and use it in GitHub Desktop.
Gitlab Pipeline code for a linear deployment via SFTP
stages:
- Load Libraries
- Build
- Deploy Test
- Deploy Prod
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:
when: on_success
image: node:lts-slim
stage: Build
allow_failure: false
dependencies:
- Load Libraries
script:
- npx pnpm add -g pnpm
- pnpm run build
artifacts:
paths:
- server
- build
- Dockerfile
Deploy Test:
stage: Deploy Test
image: jimmyadaro/gitlab-ci-cd:latest
when: on_success
environment:
name: test
allow_failure: false
needs:
- Build
dependencies:
- Build
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 Prod:
stage: Deploy Prod
image: jimmyadaro/gitlab-ci-cd:latest
when: on_success
environment:
name: prod
allow_failure: false
needs:
- Deploy Test
- Build
dependencies:
- Build
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