Skip to content

Instantly share code, notes, and snippets.

ec2Service.TerminateInstancesRequest(&ec2.TerminateInstancesInput{
DryRun: aws.Bool(dryRun),
InstanceIds: []*string{runInstanceResponse.Instances[0].InstanceId},
})
inspect, errInspect := newClient.ContainerInspect(ctx, resp.ID)
Inspect := inspect.State.ExitCode
newClient.ContainerStop(context.Background(), resp.ID, &timeout)
//if no error, grab the logs
logs, errLogs := newClient.ContainerLogs(ctx, resp.ID, ops)
if errLogs == nil {
scanner := bufio.NewScanner(logs)
for scanner.Scan() {
log.Printf("docker | %s", scanner.Text())
}
_ = reader.Close()
}
//attempt to start the container, notice the response id from container create API
newClient.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
resp, err := newClient.ContainerCreate(ctx, config, &container.HostConfig{
NetworkMode: "host", //might require a different setting, here we need the container exposed to the subnet
}, nil, "name")
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
log.Printf("docker | %s", scanner.Text())
}
_ = reader.Close()
reader, err := newClient.ImagePull(ctx, image, types.ImagePullOptions{
RegistryAuth: authStr,
})
decoded, e := base64.StdEncoding.DecodeString(token)
parts := strings.Split(decoded, ":")
authConfig := types.AuthConfig{
Username: parts[0],
Password: parts[1],
}
encodedJSON, err := json.Marshal(authConfig)
authStr := base64.URLEncoding.EncodeToString(encodedJSON)
tokenRequest, errToken := ecrService.GetAuthorizationToken(&ecr.GetAuthorizationTokenInput{})
if errToken != nil {
log.Fatalf("couldn't retrieve ecr login details! %v", errToken)
}
token := *tokenRequest.AuthorizationData[0].AuthorizationToken