ちゃんるいすのブログ

オタクエンジニアの雑記

Nomad に Drone を展開する


drone のどっかのバージョンから server と runner が別イメージになった。

job "drone" {
  datacenters = ["luis"]
  type = "service"

  update {
    max_parallel      = 1
    min_healthy_time  = "10s"
    healthy_deadline  = "3m"
    progress_deadline = "10m"
    auto_revert       = true
    canary            = 0
  }

  group "drone-server" {
    count = 1

    task "drone-server" {
      driver = "docker"

      config {
        image = "drone/drone:1"
        port_map {
          port = 80
        }
        volumes = [
          "/var/lib/drone:/data"
        ]
      }

      env {
        "DRONE_GITHUB_SERVER"         = "https://github.com"
        "DRONE_RPC_SECRET"            = ""
        "DRONE_GITHUB_CLIENT_ID"      = ""
        "DRONE_GITHUB_CLIENT_SECRET"  = ""
        "DRONE_SERVER_HOST"           = ""
        "DRONE_SERVER_PROTO"          = "https"
        "DRONE_USER_CREATE"           = "username:luis,machine:false,admin:true,token:"
        "DRONE_DATABASE_DRIVER"       = "postgres"
        "DRONE_DATABASE_DATASOURCE"   = "postgres://@arjuna.db.elephantsql.com:5432/cduzmalf?sslmode=disable"
      }

      resources {
        cpu     = 100
        memory  = 128
        network {
          mbits = 100
          port "port"{}
        }
      }

      service {
        name = "drone-server"
        port = "port"

        tags = [
          "traefik.tags=service",
          "traefik.frontend.rule=PathPrefixStrip:/drone",
        ]

        check {
          type     = "tcp"
          port     = "port"
          interval = "2s"
          timeout  = "2s"
        }
      }
    }
  }

  group "drone-runner" {
    count = 3

    task "drone-runner" {
      driver = "docker"

      config {
        image = "drone/drone-runner-docker:1"
        port_map {
          port = 3000
        }
        volumes = [
          "/var/run/docker.sock:/var/run/docker.sock"
        ]
      }

      env {
        "DRONE_RPC_PROTO"       = "https"
        "DRONE_RPC_HOST"        = ""
        "DRONE_RPC_SECRET"      = ""
        "DRONE_RUNNER_CAPACITY" = "4"
        "DRONE_RUNNER_NAME"     = "drone-runner"
      }

      resources {
        cpu     = 100
        memory  = 2048
        network {
          mbits = 100
            port "port"{}
        }
      }

      service {
        name = "drone-runner"
        port = "port"

        check {
          type     = "tcp"
          port     = "port"
          interval = "2s"
          timeout  = "2s"
        }
      }
    }
  }
}

DB を PostgreSQL にして、各リポジトリの設定を保存しておいて
ステートレスになるようになってる。

PostgreSQL はここが無料で使えてオススメ
www.elephantsql.com