| 166 | } |
| 167 | |
| 168 | func (d Docker) Push(ctx context.Context, image string, user string, password string) (string, error) { |
| 169 | authConfig := types.AuthConfig{ |
| 170 | Username: user, |
| 171 | Password: password, |
| 172 | } |
| 173 | encodedJSON, err := json.Marshal(authConfig) |
| 174 | if err != nil { |
| 175 | return "", err |
| 176 | } |
| 177 | |
| 178 | authStr := base64.URLEncoding.EncodeToString(encodedJSON) |
| 179 | reader, err := d.client.ImagePush(ctx, image, types.ImagePushOptions{RegistryAuth: authStr}) |
| 180 | if err != nil { |
| 181 | return "", err |
| 182 | } |
| 183 | buf := new(bytes.Buffer) |
| 184 | buf.ReadFrom(reader) |
| 185 | return buf.String(), err |
| 186 | } |
| 187 | |
| 188 | func (d Docker) Exec(ctx context.Context, container string, chdir string, cmd []string, env []string) (string, error) { |
| 189 | id, err := d.client.ContainerExecCreate(ctx, container, types.ExecConfig{Tty: true, WorkingDir: chdir, Cmd: cmd, Env: env, AttachStderr: true, AttachStdout: true}) |