{"id":24272436,"url":"https://github.com/kayvansol/gitlabcicd","last_synced_at":"2026-05-08T03:10:05.483Z","repository":{"id":272551405,"uuid":"916976802","full_name":"kayvansol/GitLabCICD","owner":"kayvansol","description":"GitLab CI/CD in Docker","archived":false,"fork":false,"pushed_at":"2025-01-15T07:09:52.000Z","size":1017,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-15T07:41:59.395Z","etag":null,"topics":["ci-cd","cicd","continuous-delivery","continuous-deployment","docker","docker-compose","gitlab","gitlab-ci","gitlab-runner","ssh"],"latest_commit_sha":null,"homepage":"https://medium.com/@kayvan.sol2/gitlab-ci-cd-aaaaccbada84","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kayvansol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-15T05:42:39.000Z","updated_at":"2025-01-15T07:11:17.000Z","dependencies_parsed_at":"2025-01-15T07:42:03.649Z","dependency_job_id":"8b2ba57a-d945-4230-a017-fbb14cbb2533","html_url":"https://github.com/kayvansol/GitLabCICD","commit_stats":null,"previous_names":["kayvansol/gitlabcicd"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kayvansol%2FGitLabCICD","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kayvansol%2FGitLabCICD/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kayvansol%2FGitLabCICD/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kayvansol%2FGitLabCICD/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kayvansol","download_url":"https://codeload.github.com/kayvansol/GitLabCICD/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241977493,"owners_count":20051832,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci-cd","cicd","continuous-delivery","continuous-deployment","docker","docker-compose","gitlab","gitlab-ci","gitlab-runner","ssh"],"created_at":"2025-01-15T18:26:25.856Z","updated_at":"2026-05-08T03:10:05.387Z","avatar_url":"https://github.com/kayvansol.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# GitLab CI/CD\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/1.webp?raw=true)\n\n**`GitLab`** is a web-based Git repository that provides free open and private repositories, issue-following capabilities, and wikis. It is a complete DevOps platform that enables professionals to perform all the tasks in a project — from project planning and source code management to monitoring and security.\n\nThis article will guide you on how to do **`CI/CD pipeline`** setup with GitLab.\n\nContinuous integration and continuous delivery (CI/CD) is a methodology of automatically building and deploying code to provide you with greater speed and reliability. It is done in two parts: continuous integration (CI) and continuous delivery (CD).\n\n`Continuous delivery` is then getting your code to a deliverable state, so it can be deployed at the click of a button. Or, in the case of `continuous deployment`, automatically deploy your code if all tests pass.\n\n\u003c/hr\u003e\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/2.webp?raw=true)\n\n# Installing docker on 2 servers with ansible 🎉\n\nRelated files are stored at my [github](https://github.com/kayvansol/AnsibleDockerInstallation) :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/3.webp?raw=true)\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/4.webp?raw=true)\n\nRun the ansible playbook 🚀\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/5.webp?raw=true)\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/6.webp?raw=true)\n\nThe result of installing docker ✔️:\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/7.webp?raw=true)\n\n\u003c/hr\u003e\n\n# Installing gitlab on docker (GitLabServer) 🎉\n\nPull the gitlab docker image from repository.\n```\ndocker pull gitlab/gitlab-ce:nightly\n```\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/8.webp?raw=true)\n\nGitlab compose file :\n```\nversion: '3.6'\n\nvolumes:\n  gitlab_backup:\n    name: gitlab_backup\n  gitlab_data:\n    name: gitlab_data\n  gitlab_logs:\n    name: gitlab_logs\n  gitlab_config:\n    name: gitlab_config\n\nservices:\n  gitlab:\n    image: gitlab/gitlab-ce:nightly\n    container_name: gitlab\n    restart: always\n    hostname: 'gitlab.example.com'\n    environment:\n      GITLAB_OMNIBUS_CONFIG: |\n        # Add any other gitlab.rb configuration here, each on its own line\n        external_url 'http://gitlab.example.com'\n \n        # Change the initial default admin password\n        gitlab_rails['initial_root_password'] = \"y@1234567\"\n        gitlab_rails['display_initial_root_password'] = \"false\"\n        gitlab_rails['store_initial_root_password'] = \"false\"\n\n        # Nginx Configuration\n        nginx['client_max_body_size'] = '10240m'\n        nginx['gzip_enabled'] = true\n        nginx['listen_port'] = 80\n        nginx['listen_https'] = false\n        nginx['proxy_cache'] = 'gitlab'\n        nginx['http2_enabled'] = true\n        nginx['listen_port'] = 80\n        nginx['listen_https'] = false\n        nginx['http2_enabled'] = false\n        nginx['proxy_set_headers'] = {\n          \"Host\" =\u003e \"$$http_host\",\n          \"X-Real-IP\" =\u003e \"$$remote_addr\",\n          \"X-Forwarded-For\" =\u003e \"$$proxy_add_x_forwarded_for\",\n          \"X-Forwarded-Proto\" =\u003e \"https\",\n          \"X-Forwarded-Ssl\" =\u003e \"on\"\n        }\n\n        # Configure a failed authentication ban\n        gitlab_rails['rack_attack_git_basic_auth'] = {\n          'enabled' =\u003e false,\n          'ip_whitelist' =\u003e [\"127.0.0.1\"],\n          'maxretry' =\u003e 10,\n          'findtime' =\u003e 60,\n          'bantime' =\u003e 3600\n        }\n\n        # Disable unuse services\n        prometheus['enable'] = false\n        # grafana['enable'] = false\n        alertmanager['enable'] = false\n        pgbouncer_exporter['enable'] = false\n        puma['exporter_enabled'] = false\n        gitlab_exporter['enable'] = false\n        node_exporter['enable'] = false\n        sidekiq['metrics_enabled'] = false\n        redis_exporter['enable'] = false\n        postgres_exporter['enable'] = false\n\n        # gitlab backup config\n        gitlab_rails['manage_backup_path'] = true\n        gitlab_rails['backup_path'] = \"/var/opt/gitlab/backups\"\n        gitlab_rails['backup_archive_permissions'] = 0644\n        gitlab_rails['backup_keep_time'] = 604800\n        gitlab_rails['env'] = {\"SKIP\" =\u003e \"registry\"}\n\n        # Gitlab registry config\n        registry_external_url 'https://reg.gitlab.example.com'\n        registry_nginx['listen_port'] = 5100\n        registry_nginx['listen_https'] = false\n        registry_nginx['proxy_set_headers'] = {\n          \"Host\" =\u003e \"$$http_host\",\n          \"X-Real-IP\" =\u003e \"$$remote_addr\",\n          \"X-Forwarded-For\" =\u003e \"$$proxy_add_x_forwarded_for\",\n          \"X-Forwarded-Proto\" =\u003e \"https\",\n          \"X-Forwarded-Ssl\" =\u003e \"on\"\n        }\n\n    ports:\n      - '80:80'\n      - '443:443'\n      - '2424:22'\n    volumes:\n      - gitlab_backup:/var/opt/gitlab/backups\n      - gitlab_data:/var/opt/gitlab\n      - gitlab_logs:/var/log/gitlab\n      - gitlab_config:/etc/gitlab\n```\n```\ndocker compose up -d\n```\n\nRun the compose file 🚀\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/9.webp?raw=true)\n\nHtop on the gitlab server :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/10.webp?raw=true)\n\nWelcome to the GitLab. 🎉\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/11.webp?raw=true)\n\nCreate project related Users :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/12.webp?raw=true)\n\nNow we need to create a Project and create a new branch or default (main) inside the Project Repository :\n\nHere is the project has been created successfully.✔️\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/13.webp?raw=true)\n\nSpecify users to the project :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/14.webp?raw=true)\n\nGlobal `dashboard` overview :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/15.webp?raw=true)\n\nadd user’s machine’s ssh public key for working with gitlab project :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/16.webp?raw=true)\n\n**Clone** the project to your local area :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/17.webp?raw=true)\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/18.webp?raw=true)\n\nCreate file \u0026 folders related to your project \u0026 commit and push them :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/19.webp?raw=true)\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/20.webp?raw=true)\n\n\u003c/hr\u003e\n\n# Set Up a GitLab Runner 🎉\n\n**`GitLab Runner`** is an application that works with GitLab CI/CD to run jobs in a pipeline.\n\nRunners are available based on who you want to have access to :\n\nShared runners are available to all groups and projects in a GitLab instance.\nGroup runners are available to all projects and subgroups in a group.\nSpecific runners are associated with specific projects. Typically, specific runners are used for one project at a time.\n\nConfiguring the Runner server on docker compose file :\n\n```\nversion: '3.8'\n\nvolumes:\n  runner_data:\n    name: runner_data\n    external: false\n\nservices:\n\n  gitlab-runner:\n    image: gitlab/gitlab-runner:alpine-v17.6.1\n    restart: unless-stopped\n    container_name: gitlab-runner\n    hostname: gitlab-runner\n    volumes:\n      - /var/run/docker.sock:/var/run/docker.sock\n      - runner_data:/etc/gitlab-runner\n```\n```\ndocker compose pull\n\ndocker compose up -d\n```\n\nRunning the compose 🚀\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/21.webp?raw=true)\n\nThen create a runner inside gitlab (Settings \u003e CI/CD \u003e Runners \u003e New project runner \u003e Create \u003e Register runner) :\n```\ngitlab-runner register  \n--url http://gitlab.example.com  \n--token glrt-t3_PtA9egtEgpG5AyZsoz6R\n```\n\nInside the runner server :\n```\ndocker exec -it gitlab-runner /bin/bash\n\ngitlab-runner register  \n--url http://gitlab.example.com  \n--token glrt-t3_PtA9egtEgpG5AyZsoz6R\n```\n\nAfter running this command, it will ask below-mentioned details, provide those details, and your Runner will be ready :\n\n1. Enter your GitLab instance URL (also known as the gitlab-ci coordinator URL).\n\n2. Enter the token you obtained to register the runner(These details you can get from your GitLab Project \u003e Settings \u003e CI/CD \u003e Runners )\n\n3. Enter a description for the runner. You can change this value later through the GitLab user interface.\n\n4. Enter the tags associated with the runner, separated by commas. You can change this value later through the GitLab user interface.\n\n5. Enter any optional maintenance note for the runner.\n\n6. Provide the runner executor. For most use cases, enter docker.\n\n7. If you entered docker as your executor, you are asked for the default image to be used for projects that do not define one in .gitlab-ci.yml.\n   \n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/22.webp?raw=true)\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/23.webp?raw=true)\n\nAfter providing those details we are able to see our Specific Runner has been Configured Successfully.✔️\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/24.webp?raw=true)\n\nCreate some changes at runner’s **`config.toml`** file (runner server) :\n```\ndocker inspect --format='{{.NetworkSettings.Networks}}' 4819f97432fc\n```\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/25.webp?raw=true)\n\n```\nvi /etc/gitlab-runner/config.toml\n```\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/26.webp?raw=true)\n\n\u003c/br\u003e\n\n# It’s time to establish a CI/CD pipeline 🎉\n\nFor Running the Pipeline, first we need to write the **`.gitlab-ci.yml`** YML file. Create a file named `.gitlab-ci.yml` at the root of the project and write your desire dscripts \u0026 stages :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/27.webp?raw=true)\n```\nstages:\n  - build\n\nbuild-job:\n  image: localhost:5000/docker:dind \n  stage: build  \n  before_script:\n    - 'command -v ssh-agent \u003e/dev/null || ( apk add --update openssh )'\n    - eval $(ssh-agent -s)\n    - chmod 400 ${SSH_PRIVATE_KEY}\n    #- echo ${SSH_PRIVATE_KEY}\n    - ssh-add ${SSH_PRIVATE_KEY}\n    - mkdir -p ~/.ssh\n    - chmod 700 ~/.ssh\n    - ssh-keyscan 192.168.56.157 \u003e\u003e ~/.ssh/known_hosts\n    - chmod 644 ~/.ssh/known_hosts\n  script:    \n    - |\n      scp -o StrictHostKeyChecking=no -r app  root@192.168.56.157:/opt/text/\n      scp -o StrictHostKeyChecking=no newfile.txt  root@192.168.56.157:/opt/text/\n      # Create directory if not exist\n      ##ssh -o StrictHostKeyChecking=no  -i  ${SSH_PRIVATE_KEY} root@192.168.56.157 \"            \n      # move compose and env file to server\n      ##scp -o StrictHostKeyChecking=no  newfile.txt  root@192.168.56.157:/opt/text/            \n      ##\"        \n  when: manual\n```\n\nNote : **manual** means continuous delivery (CD) \u0026 without this line we have continuous deployment (CD)\n\nNote : For **`docker:dind`** image, we pull it from docker repository and then tag \u0026 push it to our local registry (on port 5000) for performance :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/28.webp?raw=true)\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/29.webp?raw=true)\n\nFor copying objects to production server, we need a ssh key on gitlab runner \u0026 use it’s private key at .gitlab-ci.yml **`${SSH_PRIVATE_KEY}`** and also copy it’s public key to production server :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/30.webp?raw=true)\n\nGo to Settings \u003e CI/CD \u003e Variables :\n\nCreate a file typed variable named **SSH_PRIVATE_KEY** :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/31.webp?raw=true)\n\nCopy the **id_rsa** (private key) entire content to the Value box and insert a new line at the end of it and then save changes :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/32.webp?raw=true)\n\nand then copy the **id_rsa.pub** content to the production server :\n```\nssh-copy-id -i .ssh/id_rsa.pub root@192.168.56.157\n```\n\nAnd after commit the file, pipeline will begin to work and send jobs to the runner server for executing and sending project files \u0026 folders to the production server at your desired location. 🚀\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/33.webp?raw=true)\n\nAfter committing, our Pipeline has been executed and completed successfully, for more details click on Jobs and then click on specific job to see its logs and details.\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/34.webp?raw=true)\n\nRelated job execution details :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/35.webp?raw=true)\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/36.webp?raw=true)\n\nHere, GitLab Pipeline has been executed Successfully.✔️\n\nCheck the production server for transferred project contents :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/37.webp?raw=true)\n\n\u003c/br\u003e\n\n# Test again the pipeline with other user (root) ♻️ :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/38.webp?raw=true)\n\nNote : `Commit 80e16891` 🎉\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/39.webp?raw=true)\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/40.webp?raw=true)\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/41.webp?raw=true)\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/42.webp?raw=true)\n\nCheck the changes content (commit changes) :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/43.webp?raw=true)\n\nCheck the production server again for transferred project contents :\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/44.webp?raw=true)\n\n\u003c/br\u003e\n\n# Writing ssh multiline commands 🎉\n\nWrite and save some changes including bash scripts \u0026 docker commands at `.gitlab-ci.yml` file :\n\n```\nstages:\n  - build\n\nbuild-job:\n  image: localhost:5000/docker:dind \n  stage: build \n  variables: \n    SERVER_IP: 192.168.56.157   \n    SSH_USER: root\n  before_script:\n    - 'command -v ssh-agent \u003e/dev/null || ( apk add --update openssh )'\n    - eval $(ssh-agent -s)\n    - chmod 400 ${SSH_PRIVATE_KEY}\n    #- echo ${SSH_PRIVATE_KEY}\n    - ssh-add ${SSH_PRIVATE_KEY}\n    - mkdir -p ~/.ssh\n    - chmod 700 ~/.ssh\n    - ssh-keyscan ${SERVER_IP} \u003e\u003e ~/.ssh/known_hosts\n    - chmod 644 ~/.ssh/known_hosts\n  script:    \n    - |\n      scp -o StrictHostKeyChecking=no -r app  ${SSH_USER}@${SERVER_IP}:/opt/text/\n      scp -o StrictHostKeyChecking=no newfile.txt  ${SSH_USER}@${SERVER_IP}:/opt/text/\n      ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SERVER_IP} \"\n      echo '********* ls command *********'\n      ls /opt/text\n      echo '******** cat the file ********'\n      cat /opt/text/newfile.txt\n      echo '******************************'\n      docker run hello-world\n      \"            \n  when: manual\n```\n\nNote : `Commit 4fd2cae9` 🎉\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/45.webp?raw=true)\n\nPipeline is going to takeoff 🚀\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/46.webp?raw=true)\n\n![alt text](https://raw.githubusercontent.com/kayvansol/GitLabCICD/refs/heads/main/img/47.webp?raw=true)\n\n# Congratulation 🍹\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkayvansol%2Fgitlabcicd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkayvansol%2Fgitlabcicd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkayvansol%2Fgitlabcicd/lists"}