Smithx10 / nomad-driver-triton

HashiCorp Nomad Triton driver plugin
15 stars 6 forks source link

Implement Docker authentication for private registries #22

Closed teutat3s closed 4 years ago

teutat3s commented 4 years ago

Depends on #21

This initial implementation of docker authentication for private registries is inspired by HashiCorps docker driver.

Relevant bits are from: https://github.com/hashicorp/nomad/blob/ef99996f1419334e1d9d23eba9d24e7d9404218f/drivers/docker/config.go#L281-L286 https://github.com/hashicorp/nomad/blob/ef99996f1419334e1d9d23eba9d24e7d9404218f/drivers/docker/driver.go#L540-L565 https://github.com/hashicorp/nomad/blob/ef99996f1419334e1d9d23eba9d24e7d9404218f/drivers/docker/driver.go#L583-L591 https://github.com/hashicorp/nomad/blob/ef99996f1419334e1d9d23eba9d24e7d9404218f/drivers/docker/utils.go#L75-L84 https://github.com/hashicorp/nomad/blob/ef99996f1419334e1d9d23eba9d24e7d9404218f/drivers/docker/utils.go#L86-L100 https://github.com/hashicorp/nomad/blob/ef99996f1419334e1d9d23eba9d24e7d9404218f/drivers/docker/utils.go#L187-L196 https://github.com/hashicorp/nomad/blob/ef99996f1419334e1d9d23eba9d24e7d9404218f/drivers/docker/driver_test.go#L2152-L2204

Only AuthFromTaskConfig gets implemented by this PR, so you can issue a nomad job like this:

...   
   config {
        api_type = "docker_api"

        docker_api {
          private_network = "My-Fabric-Network"

          labels {
            group         = "redis-demo"
            bob.bill.john = "label"
            test          = "test"
          }

          image {
            name      = "hub.example.com/custom-redis"
            tag       = "v0.0.1"
            auto_pull = true
          }

          auth {
            username = "admin"
            password = "s3cr3t-pass"
          }
        }

        package {
          name = "sample-512M"
        }
...

Tested in our triton setup and works as expected.

I'm looking forward for feedback because this is my first contribution to a go project and would like to learn as much as possible. Hopefully this can be improved and merged one day.

Smithx10 commented 4 years ago

Thanks for this!