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

feat: add docker login function #1450

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
30 changes: 30 additions & 0 deletions modules/docker/login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package docker

import (
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/shell"
"github.com/gruntwork-io/terratest/modules/testing"
"github.com/stretchr/testify/require"
)

type LoginOptions struct {
Registry string
Login string
Password string
}

// Login runs the 'docker login' command to login the given registry. This will fail the test if there are any errors.
// Do not use production password, only for testing purpose.
func Login(t testing.TestingT, opt LoginOptions) {
require.NoError(t, login(t, opt))
}

// login runs the 'docker login' command to login the given registry.
func login(t testing.TestingT, opt LoginOptions) error {
Copy link
Member

Choose a reason for hiding this comment

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

No public function which return error, similar to Push() / PushE()

Copy link
Author

Choose a reason for hiding this comment

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

fix

logger.Logf(t, "Running 'docker login' for user %s", opt.Login)
cmd := shell.Command{
Command: "docker",
Args: []string{"login", opt.Registry, "-u", opt.Login, "-p", opt.Password},
}
return shell.RunCommandE(t, cmd)
}