Skip to content

Instantly share code, notes, and snippets.

@webdevsuperfast
Forked from qutek/.gitlab-ci.yml
Created April 1, 2022 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdevsuperfast/70a0d8fbd513a69fa20d83e0322758bc to your computer and use it in GitHub Desktop.
Save webdevsuperfast/70a0d8fbd513a69fa20d83e0322758bc to your computer and use it in GitHub Desktop.
[Gitlab CI With Rsync] Auto deploy gitlab CI with rsync
# https://gitlab.com/help/ci/quick_start/README
# https://docs.gitlab.com/ee/ci/introduction/
# https://docs.gitlab.com/ee/ci/yaml/
image: dpolyakov/docker-node-latest-with-rsync:latest
# before_script:
# - apt-get update -qq
# - apt-get install -qq git
##
# STAGES
##
stages:
# - build
# - test
- deploy
##
# TASKS
##
# Build Dependencies:
# stage: build
# script:
# - echo "Building the app"
# - node -v
# # - (cd mu-plugins/mba-project && npm install) # temporary cd and install
# # - gulp --production
# # - composer install -d mu-plugins/mba-project
# only:
# # - staging
# - master
# Test Codes:
# stage: test
# script:
# - echo "Running tests"
# only:
# # - staging
# - master
Deploy to Staging:
stage: deploy
# when: manual
environment:
name: staging
only:
- master
script:
- echo "Deploy to staging server"
before_script:
# Setup SSH deploy keys
- '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'
Deploy to Production:
stage: deploy
when: manual
environment:
name: production
only:
- master
script:
- echo "Deploying ${CI_COMMIT_SHA} from ${CI_COMMIT_REF_NAME} to production server"
# - ssh -o PasswordAuthentication=no root@lafif.me 'exit' || echo "SSH login failed."
# - rsync --version
# - ls -a
# Write log file
- |
cat <<EOT >> deploy.txt
Commit SHA : ${CI_COMMIT_SHA}
From ref : ${CI_COMMIT_REF_NAME}
Date : ${CI_JOB_DATE}
EOT
- rsync -a --progress --human-readable --delete
--exclude-from '.gitignore'
--exclude .gitignore
--exclude .git
.
root@lafif.me:/home/admin/web/demo.lafif.me/public_html/deploy
before_script:
- export CI_JOB_DATE=$(TZ=Asia/Jakarta date)
# Setup SSH deploy keys
- '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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment