Skip to content

Commit efad1e1

Browse files
authored
RTECO-977 - Fix docker build skip-login (#3404)
* RTECO-977 - Fix docker build skip-login * pinned pipenv version
1 parent 93bb13f commit efad1e1

4 files changed

Lines changed: 51 additions & 7 deletions

File tree

.github/workflows/pythonTests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959

6060
- name: Setup Pipenv
6161
if: ${{ matrix.suite == 'pipenv' && matrix.os.name != 'macos' }}
62-
run: python -m pip install pipenv
62+
run: python -m pip install pipenv==2026.2.2
6363

6464
- name: Setup Twine
6565
if: ${{ matrix.suite == 'pip' && matrix.os.name != 'macos' }}

buildtools/cli.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ func buildCmd(c *cli.Context) error {
10701070
}
10711071

10721072
// Extract build configuration and arguments
1073-
_, rtDetails, _, _, _, cleanArgs, buildConfiguration, err := extractDockerOptionsFromArgs(c.Args())
1073+
_, rtDetails, _, skipLogin, _, cleanArgs, buildConfiguration, err := extractDockerOptionsFromArgs(c.Args())
10741074
if err != nil {
10751075
return err
10761076
}
@@ -1079,10 +1079,11 @@ func buildCmd(c *cli.Context) error {
10791079
return err
10801080
}
10811081

1082-
// Login to the docker registry
1083-
err = loginCmd(c)
1084-
if err != nil {
1085-
return err
1082+
if !skipLogin {
1083+
err = loginCmd(c)
1084+
if err != nil {
1085+
return err
1086+
}
10861087
}
10871088

10881089
dockerOptions := strategies.DockerBuildOptions{

docker_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"testing"
1515
"time"
1616

17+
urfavecli "github.com/urfave/cli"
1718
"github.com/jfrog/jfrog-client-go/utils/log"
1819

1920
tests2 "github.com/jfrog/jfrog-cli-artifactory/utils/tests"
@@ -1278,6 +1279,48 @@ CMD ["echo", "Hello from buildx"]`, baseImage)
12781279
inttestutils.ContainerTestCleanup(t, serverDetails, artHttpDetails, imageNameOnly, buildName, tests.OciLocalRepo)
12791280
}
12801281

1282+
// TestDockerBuildxSkipLoginFails verifies that --skip-login actually skips login.
1283+
// After logging out, buildx --push with --skip-login should fail because no auth is available.
1284+
func TestDockerBuildxSkipLoginFails(t *testing.T) {
1285+
cleanup := initDockerBuildTest(t)
1286+
defer cleanup()
1287+
1288+
// Prevent urfave/cli from calling os.Exit on command errors
1289+
origOsExiter := urfavecli.OsExiter
1290+
urfavecli.OsExiter = func(code int) {}
1291+
defer func() { urfavecli.OsExiter = origOsExiter }()
1292+
1293+
registryHost := *tests.ContainerRegistry
1294+
if parsedURL, err := url.Parse(registryHost); err == nil && parsedURL.Host != "" {
1295+
registryHost = parsedURL.Host
1296+
}
1297+
imageName := path.Join(registryHost, tests.OciLocalRepo, "test-skip-login")
1298+
imageTag := imageName + ":v1"
1299+
1300+
workspace, err := filepath.Abs(tests.Out)
1301+
assert.NoError(t, err)
1302+
assert.NoError(t, fileutils.CreateDirIfNotExist(workspace))
1303+
1304+
baseImage := path.Join(registryHost, tests.OciRemoteRepo, "busybox:latest")
1305+
dockerfileContent := fmt.Sprintf(`FROM %s
1306+
CMD ["echo", "skip-login test"]`, baseImage)
1307+
dockerfilePath := filepath.Join(workspace, "Dockerfile")
1308+
assert.NoError(t, os.WriteFile(dockerfilePath, []byte(dockerfileContent), 0644)) //#nosec G703 -- test code
1309+
1310+
// Logout from registry so push requires fresh login
1311+
logoutCmd := exec.Command("docker", "logout", registryHost)
1312+
assert.NoError(t, logoutCmd.Run())
1313+
1314+
// With --skip-login, jf should NOT re-login, so push should fail
1315+
err = runJfrogCliWithoutAssertion("docker", "buildx", "build",
1316+
"--platform", "linux/amd64",
1317+
"-t", imageTag, "-f", dockerfilePath, "--push", "--skip-login", workspace)
1318+
assert.Error(t, err, "Expected failure: --skip-login should prevent auto-login, causing push to fail without auth")
1319+
1320+
// Re-login for subsequent tests
1321+
runJfrogCli(t, "docker", "login", registryHost)
1322+
}
1323+
12811324
// TestDockerBuildWithVirtualRepo tests docker build with virtual repository
12821325
func TestDockerBuildWithVirtualRepo(t *testing.T) {
12831326
cleanup := initDockerBuildTest(t)

utils/cliutils/commandsflags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ var commandFlags = map[string][]string{
19141914
serverId, skipLogin,
19151915
},
19161916
DockerBuild: {
1917-
BuildName, BuildNumber, serverId,
1917+
BuildName, BuildNumber, serverId, skipLogin,
19181918
},
19191919
DockerPromote: {
19201920
targetDockerImage, sourceTag, targetTag, dockerPromoteCopy, url, user, password, accessToken, sshPassphrase, sshKeyPath,

0 commit comments

Comments
 (0)