diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 65dbcd1a2c4f4c07ad5f20edd1464ed757301daf..f36b62ac6b4a0ab5d21d7008f2c328e09c94314a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,38 +1,40 @@ -# This file is a template, and might need editing before it works on your project. -# To contribute improvements to CI/CD templates, please follow the Development guide at: -# https://docs.gitlab.com/ee/development/cicd/templates.html -# This specific template is located at: -# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Docker.gitlab-ci.yml - -# Build a Docker image with CI/CD and push to the GitLab registry. -# Docker-in-Docker documentation: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html -# -# This template uses one generic job with conditional builds -# for the default branch and all other (MR) branches. - +# Build and push the Docker image off of merges to master; based off +# of Gitlab CI support in https://pythonspeed.com/products/pythoncontainer/ docker-build: - # Use the official docker image. - image: docker:latest stage: build + + image: + # An alpine-based image with the `docker` CLI installed. + name: docker:stable + + # This will run a Docker daemon in a container (Docker-In-Docker), which will + # be available at thedockerhost:2375. If you make e.g. port 5000 public in Docker + # (`docker run -p 5000:5000 yourimage`) it will be exposed at thedockerhost:5000. services: - - docker:dind - before_script: - - echo $CI_BUILD_TOKEN | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY - # Default branch leaves tag empty (= latest tag) - # All other branches are tagged with the escaped branch name (commit ref slug) + - name: docker:dind + alias: thedockerhost + + variables: + # Tell docker CLI how to talk to Docker daemon; see + # https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker-executor + DOCKER_HOST: tcp://thedockerhost:2375/ + # Use the overlayfs driver for improved performance: + DOCKER_DRIVER: overlay2 + DOCKER_TLS_CERTDIR: "" + script: - - | - if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then - tag="" - echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'" - else - tag=":$CI_COMMIT_REF_SLUG" - echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag" - fi - - docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" . - - docker push "$CI_REGISTRY_IMAGE${tag}" - # Run this job in a branch where a Dockerfile exists - rules: - - if: $CI_COMMIT_BRANCH - exists: - - Dockerfile + # Download bash: + - apk add --no-cache bash python3 + # GitLab has a built-in Docker image registry, whose parameters are set automatically. + # See https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#using-the-gitlab-contai + # + # CHANGEME: You can use some other Docker registry though by changing the + # login and image name. + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY" + - docker build -t "$CI_REGISTRY_IMAGE" . + - docker push "$CI_REGISTRY_IMAGE" + + # Only build off of master branch: + only: + - main + diff --git a/run-runner.sh b/run-runner.sh index 17a37bd7086d90b8a886dc5d838021fb32dd148d..bea6b34ec7dc593224696c6ae5c94b2ace24a4e4 100644 --- a/run-runner.sh +++ b/run-runner.sh @@ -2,11 +2,17 @@ # --restart always -# docker run -d --name gitlab-runner --restart unless-stopped -v /srv/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest +docker run -d --name gitlab-runner --restart unless-stopped -v /srv/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest # #System volume # docker run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register # #Docker volume # #docker run --rm -it -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner:latest register -echo S1zuhiescap | sudo gitlab-runner register url "https://gitlab.example.com/" registration-token "PROJECT_REGISTRATION_TOKEN" description "docker-ruby:2.6" executor "docker" template-config /tmp/test-config.template.toml docker-image ruby:2.6 +sudo gitlab-runner register \ + --url "https://git-ce.rwth-aachen.de/" \ + --registration-token "GR1348941g1nyq5UHChraBCy7SsxU" \ + --description "docker-ruby:2.6" \ + --executor "docker" \ + --template-config /tmp/test-config.template.toml \ + --docker-image ruby:2.6 \ No newline at end of file