setting / gitlab

GitLab CI setting

November 15, 20222 min read
Image for GitLab CI setting

gitlab CI 설정 중 대단히 하고 있던 착각들

  • 모든 동작은 호스트에서 이루어진다 -> X

  • 모든 동작은 Runner container 내부에서 이루어진다.

    그래서 모든 동작은 일회성으로 끝남.

    gradlew build 후 굳이 artifact로 넘겨주거나, "배포"한다고 해놓고 dockerhub에 push해놓고 끝나는 이유가 여기에 있었음.

    모든 동작은 runner container 내부에서 동작 후 해당 runner container는 죽기 때문에, 저장하는 등의 작업을 해봤자 다 사라진다.

  • .gitlab-ci.yml file

    stages:          # List of stages for jobs, and their order of execution
      - build
      - deploy
    
    variables:
      IMAGE_NAME: test_image_name
      # DOCKER_HOST: tcp://dindhost:2375
      # DOCKER_DRIVER: overlay2
      DOCKER_TLS_CERTDIR: ""
    
    build-job:       # This job runs in the build stage, which runs first.
      stage: build
      image: openjdk:8
      script:
        - ./gradlew clean build
      artifacts:
        paths:
          - build/libs/test_image-0.0.1-SNAPSHOT.jar
        expire_in: 10min
    
    deploy-job:
      stage: deploy
      image: docker:latest
      services:
        - name: docker:dind
      script:
        - docker build -t $IMAGE_NAME .
        - docker stop $IMAGE_NAME
        - docker rm $IMAGE_NAME
        - docker run -d -p 8080:8080 --name $IMAGE_NAME --restart always $IMAGE_NAME:latest
    
  • /srv/gitlab-runner/config/config.toml

    concurrent = 1
    check_interval = 0
    
    [session_server]
      session_timeout = 1800
    
    [[runners]]
      name = "runnername"
      url = "http://url:port/"
      token = "token"
      executor = "docker"
      [runners.custom_build_dir]
      [runners.cache]
        [runners.cache.s3]
        [runners.cache.gcs]
        [runners.cache.azure]
      [runners.docker]
        tls_verify = false
        image = "docker:stable"
        privileged = true
        disable_entrypoint_overwrite = false
        oom_kill_disable = false
        disable_cache = false
        volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
        shm_size = 0
gitlabdocker