danilo
July 24, 2021, 8:23pm
1
Hello,
Our server uses CentOS 7 to deliver web app to our customers. They are developed in PHP, Node, React, etc.
We want to do auto deploy from versioning in GitLab. Here what we need:
GitPush to GitLab;
GitLab do the build and tests;
GitLab deploy the files to our CentOS 7 through SSH;
GitLab exec some shell commands on our server, like node start.
Is there any way to do that way?
Thanks for any help
Iduoad
July 25, 2021, 2:28am
2
Yes there are many ways to do so:
First generate an ssh key pair for your deploy
job.
Copy the public key into the authorized_keys
on your Centos server.
Settings > CI/CD > Variables
and store your SSH private key as a file. For more information GitLab CI/CD variables | GitLab .
Create a deploy shell script with the commands you want to run against your machine.
On the deploy
job ssh into your machine and execute the deploy script.
deploy:
image: <any-image-with-ssh-client>
script:
- ssh -i 'bash -s' < deploy.sh
Also you can run your commands ad-hoc without using a script.
My preferred way is using Ansible. You’ll need to write an ansible playbook with all the command you want to execute and run in in the deploy job.
This is an overall description on how you can deploy using ssh. If you need more details, feel free to leave me a comment.
danilo
July 30, 2021, 12:37pm
3
Thanks for the answear.
I’m setting up the eDevOps config, but there is a security concern about the gitlab-ci.yml file:
We can’t allow anyone to config this file. It has some shell commands.
I’ve seen something about creating another private repository with this file. That way, we could link it in the original project without letting the devs to take a look into it.
Is that true? Can you help me with an example?