Deploy something with Gitlab
10 May 2021
Basicly, when you want to “deploy” something via Gitlab CI/CD, that just mean building something inside a docker container and Rsync the result to the production server.
“Continuous Integration” and “Continuous Deployment” are just fancy word that mean you put your shit online. It’s not magic, it’s automated FTP with Git as the source.
First create SSH_PRIVATE_KEY
with a ssh private key that can access the server.
ssh-keygen -t rsa -b 4096 -C "me@my-domain.com"
Don’t use the passphrase, otherwise, the automatique login wont work.
You need to add the public key to a file named ~/.ssh/authorized_keys
and chmod 0644 ~/.ssh/authorized_keys
that file.
Now we just need to add this ssh key to the gitlab-ci that will Rsync what ever file you want to put on the server
deploy_henix:
stage: deploy
image: my_image
before_script:
- apt-get update
- apt-get install -qq rsync
script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- 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'
- rsync -av public/js/ myuser@mydomain:public_html/public/js
only:
- master