Last active
January 9, 2019 07:20
-
-
Save duynguyenhoang/9915d802993d13faef8c4f47e9670dba to your computer and use it in GitHub Desktop.
Very basic gitflow cicd config to build and deploy Vuejs application to server via SSH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # NOTE, CHANGE BELOW VALUE | |
| # SSH user is 'deployer' | |
| # Server address is 'remote_server_address' | |
| # Server location is '/your/server/location/' | |
| before_script: | |
| ## | |
| ## Install ssh-agent if not already installed, it is required by Docker. | |
| ## (change apt-get to yum if you use an RPM-based image) | |
| ## | |
| - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client rsync -y )' | |
| ## | |
| ## Run ssh-agent (inside the build environment) | |
| ## | |
| - eval $(ssh-agent -s) | |
| ## | |
| ## Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store | |
| ## We're using tr to fix line endings which makes ed25519 keys work | |
| ## without extra base64 encoding. | |
| ## https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556 | |
| ## | |
| - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null | |
| ## | |
| ## Create the SSH directory and give it the right permissions | |
| ## | |
| - mkdir -p ~/.ssh | |
| - chmod 700 ~/.ssh | |
| - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config | |
| stages: | |
| - build | |
| - deploy | |
| #unit_test: | |
| # image: node:6 | |
| # stage: test | |
| # script: | |
| # - npm install --progress=false | |
| # - npm run unit | |
| build_site: | |
| image: node:6 | |
| stage: build | |
| script: | |
| - npm install --progress=false | |
| - npm run build:prod | |
| artifacts: | |
| expire_in: 1 week | |
| paths: | |
| - dist | |
| only: | |
| - develop | |
| deploy_dev: | |
| image: debian:stretch | |
| stage: deploy | |
| script: | |
| - rsync -rav --delete -e "ssh -p 999" dist/ deployer@remote_server_address:/your/server/location/ | |
| only: | |
| - develop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment