Giter Site home page Giter Site logo

gitlab-runner's Introduction

gitlab-runner

This project will help you set up your Gitlab runners with docker-compose easily, Gitlab runner is an application for DevOps to run jobs of Gitlab CI/CD.

Steps to use

  1. Login to a server to deploy Gitlab runner.
  2. Git clone this project to your working directory.
  3. Export two variables in the server:
# You need admin role to get the gitlab runner registration token, Admin Area -> CI/CD -> Runners -> Register an instance runner -> Registration token
export GITLAB_RUNNER_TOKEN=<your-gitlab-runner-registration-token>
export GITLAB_URL=<your-gitlab-url>
  1. Run docker-compose up -d.
  2. Check CI/CD Runners in Admin Area of your Gitlab website, there should be a runner online.

Additional usage

Automatic tag the commit

Take maven project as an example.

NOTE: Make sure a shared gitlab runner or specific runner is available under your project, you can confirm it in -> Settings -> CI/CD -> Runners(Expand), you can see a blue cycle if it's available.

  1. Firstly, we need configure .gitlab-ci.yml to trigger Gitlab CI/CD, here is my .gitlab-ci.yml for automatic tagging the commit.
stages:
  - deploy

image: maven-git:latest

tag:
  before_script:
    - VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
    - git fetch
    - project_url=$(echo $CI_PROJECT_URL | sed 's/http:\/\///')
    - git remote set-url origin http://oauth2:$TAG_CREATION_TOKEN@$project_url
  script:
    - echo "Automatic build and tag the commit"
    - tag=v${VERSION}
    - git tag $tag
    - git push origin $tag
  stage: deploy
  only:
    refs:
      - release
  except:
    - merge_requests
  1. Then a CI/CD variable $TAG_CREATION_TOKEN is required, it could be initiated in User Setting -> Access Tokens -> Personal Access Tokens, recommend using a specific account such as ci-bot to restrict the access.
  2. Configure TAG_CREATION_TOKEN as a global CI/CD variable or project CI/CD variable.
  • Global CI/CD variable: Admin Area -> Settings -> CD/CD -> Variables(Expand)
  • Project CI/CD variable: -> Settings -> CD/CD -> Variables(Expand)
  1. Next, a docker image should be prepared to run the script, we need maven, git and java in the docker container, so I customized my own docker image in ./images/maven.
  • build.sh is used to create the docker image.
  • load.sh is used to save .tar file, copy to gitlab-runner and load it, I have to do so because there's no docker register in my test environment.
  1. At last, you can change your version in pom.xml, commit to the target branch and see the result.

gitlab-runner's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.