Start by creating .gitlab-ci.yml
file and pasting the contents provided in it, you can customize the deployment commands as needed.
On the server, generate a new SSH key pair using the ssh-keygen command:
ssh-keygen -t id_ed25519
After generating the SSH key pair, copy the contents of the public key (usually found in ~/.ssh/id_ed25519.pub). You can use the cat command to display the contents:
cat ~/.ssh/id_ed25519.pub
Now, you need to add the public key to the authorized_keys file in the .ssh directory of your user's home directory. If the file doesn't exist, create it.
nano ~/.ssh/authorized_keys
Paste the contents of the public key into this file and save it.
Ensure that the permissions for the .ssh directory and the authorized_keys file are set correctly:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
First obtain the private key contents using:
cat ~/.ssh/id_ed25519
then go to your GitLab project's settings and navigate to CI/CD > Variables
.
Then click on "Add variable" button and set the key to SSH_PRIVATE_KEY
and paste the contents of your SSH private key into the value field.
The variable value must end in a newline (LF character). To add a newline, press Enter or Return at the end of the last line of the SSH key before saving it in the CI/CD settings.
Now also add other required environment variables as needed e.g SSH_HOST
, SSH_USER
& PROJECT_PATH
.
You must have at least the Maintainer role for the project.
This is very important if you selected "Protected" when creating the variables above else they won't be available for use.
- In your project, Select Settings > Repository.
- Expand Protected tags
- Click on Add tag
- Select Tag and type
v*
then selectCreate wildcard v*
in the options - Select Allowed to create and choose the role level you want to permit deployments for.
- Then click Protect
You must have at least the Maintainer role for the project.
- In your project, Select Settings > Repository.
- Expand Deploy keys.
- Click on Add new key.
- Use the server IP as the Title
- Use the public key contents you copied above as the Key.
- Then click on Add Key button to save.
To deploy a new version of your project to production or whatever environment you decided to setup, use the following tagging command:
git tag -a 'v1.0.3' -m 'Add KYC Verification Support'