Skip to main content

Detailed instructions to set up Continuous Integration/Continuous Deployment (CI/CD) on a VPS running GitLab

Here are the detailed instructions to set up Continuous Integration/Continuous Deployment (CI/CD) on a VPS running GitLab:

  1. Install and configure GitLab Runner on your VPS by following the instructions provided by GitLab. This will allow your VPS to communicate with the GitLab instance and run the CI/CD pipeline.

  2. Create a new project in GitLab and push your code to the project's repository.

  3. Create a new file named .gitlab-ci.yml in the root of your repository. This file will define the CI/CD pipeline and the tasks that need to be executed at each stage.

  4. Define the stages of your pipeline in the .gitlab-ci.yml file. For example, you may have stages for build, test, and deploy.

  5. Define the tasks that need to be executed in each stage. For example, in the build stage, you may have tasks for compiling the code, in the test stage, you may have tasks for running unit tests, and in the deploy stage, you may have tasks for deploying the code to a staging or production environment.

  6. Commit the .gitlab-ci.yml file and push it to the repository.

  7. Register your GitLab runner to the project, this can be done by visiting the project's settings > CI/CD > Runner settings

  8. Once the runner is registered, every time you push changes to the repository, the CI/CD pipeline will be executed automatically.

  9. You can view the pipeline status and logs by visiting the project's CI/CD > Pipelines in GitLab

  10. To automate the deploy stage, you can set up a deploy key on your server and configure it on the gitlab. This way you can use the gitlab-runner to push the code directly to the server.

  11. You can also use a deploy script, such as Ansible, Capistrano, or any other script that you prefer to deploy your code to the production server.