Last active
July 6, 2022 03:43
-
-
Save taufiqpsumarna/2264be5a634908b59fdcd018939613c9 to your computer and use it in GitHub Desktop.
Gitlab Simple CI/CD Deploy To SSH Serverr
This file contains 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
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