Skip to content

Instantly share code, notes, and snippets.

@taufiqpsumarna
Last active July 6, 2022 03:43
Show Gist options
  • Save taufiqpsumarna/2264be5a634908b59fdcd018939613c9 to your computer and use it in GitHub Desktop.
Save taufiqpsumarna/2264be5a634908b59fdcd018939613c9 to your computer and use it in GitHub Desktop.
Gitlab Simple CI/CD Deploy To SSH Serverr
image: ubuntu:latest
stages:
- deploy
deploy_prod:
stage: deploy
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- ssh-add <(echo "$SECRET_KEY_base64" | base64 -d)
- ssh -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOSTNAME "cd /var/www/api && git checkout . && git pull"
##Setup the variable on gitlab
## $SECRET_KEY_base64
## $SSH_USER
## $SSH_HOSTNAME
##Generate the secret key
## ssh-keygen -t rsa
##Add public key to authorized_keys
##cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
##Encode private key with base64 encoding
## cat ~/.ssh/id_rsa | base64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment