Created
February 14, 2018 14:04
-
-
Save mcarpenterjr/9d927cb66562466180f37e1b27feb4cf to your computer and use it in GitHub Desktop.
GITLAB YML Example
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
stages: | |
- test | |
- build | |
- user-test | |
- deploy | |
test: | |
stage: test | |
before_script: | |
# Find the SSH Agent | |
- 'which ssh-agent' | |
# Run The Agent | |
- eval $(ssh-agent -s) | |
# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store | |
- ssh-add <(echo "$SSH_PRIVATE_KEY") | |
script: | |
- echo "Make Sure Commit SHA Exists, Use for revision hashing" | |
- echo $CI_COMMIT_SHA | |
- echo "Test Deploy To Preview" | |
- rsync --update --dry-run --checksum -rlvzub --exclude ".*" --exclude "*.tgz" --exclude "Makefile.*" --backup-dir="backups/$CI_JOB_ID" -e "ssh -i ~/.ssh/id_rsa.pub" _src/ gitlab-runner@linux3:/var/www/mc-dev/$DEPLOYMENT_PREVIEW_DESTINATION/_preview | |
- echo "Dry Run Deployment On Linux3" | |
# - ssh gitlab-runner@linux3 -tt | |
- rsync --update --dry-run --checksum -rlvzub --exclude ".*" --exclude "*.tgz*" --exclude "Makefile.*" --backup-dir="backups/$CI_JOB_ID" -e "ssh -i ~/.ssh/id_rsa.pub" _src/ gitlab-runner@linux3:/var/www/$DEPLOYMENT_DESTINATION | |
build: | |
stage: build | |
script: | |
- echo "Building The App" | |
- echo $CI_COMMIT_SHA | |
user-test: | |
stage: user-test | |
before_script: | |
# Find SSH Agent | |
- 'which ssh-agent' | |
# Run the Agent | |
- eval $(ssh-agent -s) | |
#Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store | |
- ssh-add <(echo "$SSH_PRIVATE_KEY") | |
script: | |
# - echo "Update Local Preview" | |
# - rsync --update --checksum -rlvzu --exclude ".*" --exclude "*.tgz" --exclude "Makefile.*" -e "ssh -i ~/.ssh/id_rsa.pub" _src/ _preview | |
- echo "Create Revision Hashes" | |
- sed -i "s/@@hash/$CI_COMMIT_SHA/g" _src/index.php | |
- echo "Deploying to the preview folder" | |
- rsync --update --checksum -rlvzub --exclude ".*" --exclude "*.tgz" --exclude "Makefile.*" --backup-dir="backups/$CI_JOB_ID" -e "ssh -i ~/.ssh/id_rsa.pub" _src/ gitlab-runner@linux3:/var/www/mc-dev/$DEPLOYMENT_PREVIEW_DESTINATION/_preview | |
when: manual | |
allow_failure: true | |
deploy_prod: | |
stage: deploy | |
before_script: | |
# Find the SSH Agent | |
- 'which ssh-agent' | |
# Run The Agent | |
- eval $(ssh-agent -s) | |
# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store | |
- ssh-add <(echo "$SSH_PRIVATE_KEY") | |
script: | |
- echo "Deploy App to Linux 3" | |
# - ssh gitlab-runner@linux3 -tt | |
- echo "Create Revision Hashes" | |
- sed -i "s/@@hash/$CI_COMMIT_SHA/g" _src/index.php | |
- echo "Copying Files" | |
- rsync --update --checksum -rlvzub --exclude ".*" --exclude "*.tgz*" --exclude "Makefile.*" --backup-dir="backups/$CI_JOB_ID" -e "ssh -i ~/.ssh/id_rsa.pub" _src/ gitlab-runner@linux3:/var/www/$DEPLOYMENT_DESTINATION | |
environment: | |
name: production | |
url: http://linux3/$DEPLOYMENT_DESTINATION | |
only: | |
- master | |
- merge-requests | |
# when: manual | |
allow_failure: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment