Proof of concept deployment with Gitlab

I’m running 15.5.1 gitlab-runner from a on-premises RHEL image in VMware with Docker configured.

I’m using the Docker executor: Executors | GitLab.

So it’s registered and running and if I do a docker ps I see my “gitlab-runner” running.

The idea is to deploy a “hello-world” using this executor. I.e. gitlab deploys another container on the same Docker host as the Gitlab runner. Is that possible?

So the end result, I’d expect docker ps on the host and two named containers:

  • gitlab-runner
  • hello-world

Do please let me know if you have a better suggestion here!

1 Like

I have something working like so:

stages:
  - build
  - deploy

build:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:v1.9.0-debug
    entrypoint: [""]
  tags:
    - non_privileged
  script:
    - /kaniko/executor
      --context "${CI_PROJECT_DIR}"
      --build-arg VERSION=$CI_COMMIT_SHORT_SHA
      --build-arg BRANCH=$CI_COMMIT_REF_NAME
      --dockerfile "${CI_PROJECT_DIR}/Dockerfile"
      --destination "${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}"

deploy:
  stage: deploy
  tags:
    - onprem
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD registry.example.com
    - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
    - docker stop $CI_PROJECT_NAME || true # might not be running
    - docker run -d --rm -p 8080:8080 --name $CI_PROJECT_NAME $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA

The key was for the gitlab runner running onprem to bind the /var/run/docker.sock in the [runners.docker] stanza.