Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker login opt #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type (
Environ []string
Volumes []string
Labels map[string]string `envconfig:"DRONE_AGENT_LABELS"`
Dockerusername string `envconfig:"DRONE_AGENT_DOCKER_USERNAME"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation. You should run gofmt -w **/*.go

Dockerpassword string `envconfig:"DRONE_AGENT_DOCKER_PASSWORD"`
}

Runner Runner
Expand Down
2 changes: 2 additions & 0 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func New(
watchtowerImage: config.Watchtower.Image,
watchtowerTimeout: config.Watchtower.Timeout,
watchtowerInterval: config.Watchtower.Interval,
dockerUsername: config.Agent.Dockerusername,
dockerPassword: config.Agent.Dockerpassword,
},
pinger: &pinger{
servers: servers,
Expand Down
22 changes: 20 additions & 2 deletions engine/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package engine

import (
"encoding/base64"
"encoding/json"
"context"
"fmt"
"io"
Expand Down Expand Up @@ -58,6 +60,8 @@ type installer struct {

servers autoscaler.ServerStore
client clientFunc
dockerUsername string
dockerPassword string
}

func (i *installer) Install(ctx context.Context) error {
Expand Down Expand Up @@ -143,9 +147,23 @@ poller:

logger.Debug().
Str("image", i.image).
Msg("pull docker image")
Msg("pull docker image")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace error here


rc, err := client.ImagePull(ctx, i.image, types.ImagePullOptions{})
options := types.ImagePullOptions{}
if i.dockerUsername != "" && i.dockerPassword != "" {
authConfig := types.AuthConfig{
Username: i.dockerUsername,
Password: i.dockerPassword,
}
encodedJSON, err := json.Marshal(authConfig)
if err != nil {
panic(err)
}
authStr := base64.URLEncoding.EncodeToString(encodedJSON)
options = types.ImagePullOptions{RegistryAuth: authStr}
}

rc, err := client.ImagePull(ctx, i.image, options)
if err != nil {
logger.Error().Err(err).
Str("image", i.image).
Expand Down