Skip to content

Instantly share code, notes, and snippets.

@theoomoregbee
Last active September 29, 2020 16:20
Show Gist options
  • Save theoomoregbee/cf0e5a03fe9da5e75c9dd8b0fb27aaf3 to your computer and use it in GitHub Desktop.
Save theoomoregbee/cf0e5a03fe9da5e75c9dd8b0fb27aaf3 to your computer and use it in GitHub Desktop.
Gitlab Final Script for Deploying Your App over SSH
image: trion/ng-cli-karma
cache:
paths:
- node_modules/
before_script:
- apt-get update -qq && apt-get install -y -qq sshpass
deploy_stage:
stage: deploy
environment: Staging
only:
- master
script:
- rm ./package-lock.json
- npm install
- ./node_modules/@angular/cli/bin/ng test --progress false --single-run=true --watch=false
- ./node_modules/@angular/cli/bin/ng e2e --progress false --watch=false
- ./node_modules/@angular/cli/bin/ng build --progress false --prod
- cd dist/
- ls
- sshpass -V
- export SSHPASS=$USER_PASS
- sshpass -e scp -o stricthostkeychecking=no -r . username@host.com:/var/www/html
deploy_production:
stage: deploy
environment: Production
only:
- tags
script:
- rm ./package-lock.json
- npm install
- ./node_modules/@angular/cli/bin/ng test --progress false --single-run=true --watch=false
- ./node_modules/@angular/cli/bin/ng e2e --progress false --watch=false
- ./node_modules/@angular/cli/bin/ng build --progress false --prod
- cd dist/
- ls
- sshpass -V
- export SSHPASS=$USER_PASS
- sshpass -e scp -o stricthostkeychecking=no -r . username@host.com:/var/www/html
@craigiswayne
Copy link

Thanks for this... recently read up that you can actually keep common code blocks as an "anchor"

see: https://docs.gitlab.com/ee/ci/yaml/#anchors

image: trion/ng-cli-karma

.common_code: &common_code
  script:
    - rm ./package-lock.json
    - npm install
    - ./node_modules/@angular/cli/bin/ng test --progress false --single-run=true --watch=false
    - ./node_modules/@angular/cli/bin/ng e2e --progress false --watch=false
    - ./node_modules/@angular/cli/bin/ng build --progress false --prod 
    - cd dist/
    - ls
    - sshpass -V
    - export SSHPASS=$USER_PASS 
    - sshpass -e scp -o stricthostkeychecking=no -r . username@host.com:/var/www/html

cache:
  paths:
    - node_modules/

before_script:
 - apt-get update -qq && apt-get install -y -qq sshpass

deploy_stage:
  stage: deploy
  environment: Staging
  only:
    - master
  <<: *common_code

deploy_production:
  stage: deploy
  environment: Production
  only:
    - tags
    <<: *common_code

@theoomoregbee
Copy link
Author

ah, nice thanks @craigiswayne

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment