Skip to content

Commit d8c5893

Browse files
Merge pull request #21414 from umohnani8/farm-reg
Farm build should read server registries.conf
2 parents c3a32b1 + a06685a commit d8c5893

File tree

5 files changed

+51
-12
lines changed

5 files changed

+51
-12
lines changed

cmd/podman/farm/build.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,17 @@ func build(cmd *cobra.Command, args []string) error {
109109
return err
110110
}
111111
opts.IIDFile = iidFile
112-
tlsVerify, err := cmd.Flags().GetBool("tls-verify")
113-
if err != nil {
114-
return err
112+
// only set tls-verify if it has been changed by the user
113+
// if it hasn't we will read the registries.conf on the farm
114+
// nodes for further configuration
115+
if changed := cmd.Flags().Changed("tls-verify"); changed {
116+
tlsVerify, err := cmd.Flags().GetBool("tls-verify")
117+
if err != nil {
118+
return err
119+
}
120+
skipTLSVerify := !tlsVerify
121+
opts.SkipTLSVerify = &skipTLSVerify
115122
}
116-
opts.SkipTLSVerify = !tlsVerify
117123

118124
localEngine := registry.ImageEngine()
119125
ctx := registry.Context()

pkg/domain/entities/types/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type FarmBuildOptions struct {
5656
// Authfile is the path to the file holding registry credentials
5757
Authfile string
5858
// SkipTLSVerify skips tls verification when set to true
59-
SkipTLSVerify bool
59+
SkipTLSVerify *bool
6060
}
6161

6262
// BuildOptions describe the options for building container images.

pkg/farm/list_builder.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type listBuilderOptions struct {
1717
cleanup bool
1818
iidFile string
1919
authfile string
20-
skipTLSVerify bool
20+
skipTLSVerify *bool
2121
}
2222

2323
type listLocal struct {
@@ -39,13 +39,19 @@ func newManifestListBuilder(listName string, localEngine entities.ImageEngine, o
3939
// Build retrieves images from the build reports and assembles them into a
4040
// manifest list in local container storage.
4141
func (l *listLocal) build(ctx context.Context, images map[entities.BuildReport]entities.ImageEngine) (string, error) {
42+
// Set skipTLSVerify based on whether it was changed by the caller
43+
skipTLSVerify := types.OptionalBoolUndefined
44+
if l.options.skipTLSVerify != nil {
45+
skipTLSVerify = types.NewOptionalBool(*l.options.skipTLSVerify)
46+
}
47+
4248
exists, err := l.localEngine.ManifestExists(ctx, l.listName)
4349
if err != nil {
4450
return "", err
4551
}
4652
// Create list if it doesn't exist
4753
if !exists.Value {
48-
_, err = l.localEngine.ManifestCreate(ctx, l.listName, []string{}, entities.ManifestCreateOptions{SkipTLSVerify: types.NewOptionalBool(l.options.skipTLSVerify)})
54+
_, err = l.localEngine.ManifestCreate(ctx, l.listName, []string{}, entities.ManifestCreateOptions{SkipTLSVerify: skipTLSVerify})
4955
if err != nil {
5056
return "", fmt.Errorf("creating manifest list %q: %w", l.listName, err)
5157
}
@@ -63,7 +69,7 @@ func (l *listLocal) build(ctx context.Context, images map[entities.BuildReport]e
6369
logrus.Infof("pushing image %s", image.ID)
6470
defer logrus.Infof("pushed image %s", image.ID)
6571
// Push the image to the registry
66-
report, err := engine.Push(ctx, image.ID, l.listName+docker.UnknownDigestSuffix, entities.ImagePushOptions{Authfile: l.options.authfile, Quiet: false, SkipTLSVerify: types.NewOptionalBool(l.options.skipTLSVerify)})
72+
report, err := engine.Push(ctx, image.ID, l.listName+docker.UnknownDigestSuffix, entities.ImagePushOptions{Authfile: l.options.authfile, Quiet: false, SkipTLSVerify: skipTLSVerify})
6773
if err != nil {
6874
return fmt.Errorf("pushing image %q to registry: %w", image, err)
6975
}
@@ -111,11 +117,11 @@ func (l *listLocal) build(ctx context.Context, images map[entities.BuildReport]e
111117
}
112118

113119
// Add the images to the list
114-
listID, err := l.localEngine.ManifestAdd(ctx, l.listName, refs, entities.ManifestAddOptions{Authfile: l.options.authfile, SkipTLSVerify: types.NewOptionalBool(l.options.skipTLSVerify)})
120+
listID, err := l.localEngine.ManifestAdd(ctx, l.listName, refs, entities.ManifestAddOptions{Authfile: l.options.authfile, SkipTLSVerify: skipTLSVerify})
115121
if err != nil {
116122
return "", fmt.Errorf("adding images %q to list: %w", refs, err)
117123
}
118-
_, err = l.localEngine.ManifestPush(ctx, l.listName, l.listName, entities.ImagePushOptions{Authfile: l.options.authfile, SkipTLSVerify: types.NewOptionalBool(l.options.skipTLSVerify)})
124+
_, err = l.localEngine.ManifestPush(ctx, l.listName, l.listName, entities.ImagePushOptions{Authfile: l.options.authfile, SkipTLSVerify: skipTLSVerify})
119125
if err != nil {
120126
return "", err
121127
}

test/farm/001-farm.bats

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,37 @@ load helpers.bash
8585
run_podman image prune -f
8686
}
8787

88+
@test "farm - build on farm node only with registries.conf" {
89+
cat >$PODMAN_TMPDIR/registries.conf <<EOF
90+
[[registry]]
91+
location="$REGISTRY"
92+
insecure=true
93+
EOF
94+
95+
iname="test-image-4"
96+
CONTAINERS_REGISTRIES_CONF="$PODMAN_TMPDIR/registries.conf" run_podman farm build --authfile $AUTHFILE -t $REGISTRY/$iname $FARM_TMPDIR
97+
assert "$output" =~ "Farm \"$FARMNAME\" ready"
98+
99+
# get the system architecture
100+
CONTAINERS_REGISTRIES_CONF="$PODMAN_TMPDIR/registries.conf" run_podman info --format '{{.Host.Arch}}'
101+
ARCH=$output
102+
# inspect manifest list built and saved
103+
CONTAINERS_REGISTRIES_CONF="$PODMAN_TMPDIR/registries.conf" run_podman manifest inspect $iname
104+
assert "$output" =~ $ARCH
105+
106+
echo "# skopeo inspect ..."
107+
run skopeo inspect "$@" --tls-verify=false --authfile $AUTHFILE docker://$REGISTRY/$iname
108+
echo "$output"
109+
is "$status" "0" "skopeo inspect - exit status"
110+
111+
run_podman manifest rm $iname
112+
run_podman image prune -f
113+
}
114+
88115
# Test out podman-remote
89116

90117
@test "farm - build on farm node only (podman-remote)" {
91-
iname="test-image-4"
118+
iname="test-image-5"
92119
run_podman --remote farm build --authfile $AUTHFILE --tls-verify=false -t $REGISTRY/$iname $FARM_TMPDIR
93120
assert "$output" =~ "Farm \"$FARMNAME\" ready"
94121

test/farm/setup_suite.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function setup_suite(){
3636
run_podman system connection add --identity $sshkey test-node $ROOTLESS_USER@localhost
3737
run_podman farm create $FARMNAME test-node
3838

39-
export PODMAN_LOGIN_WORKDIR=$(mktemp -d --tmpdir=${BATS_TMPDIR:-${TMPDIR:-/tmp}} podman-bats-registry.XXXXXX)
39+
export PODMAN_LOGIN_WORKDIR=$(mktemp -d --tmpdir=${BATS_TMPDIR:-${TMPDIR:-/tmp}} podman-bats-registry.XXXXXX)
4040

4141
export PODMAN_LOGIN_USER="user$(random_string 4)"
4242
export PODMAN_LOGIN_PASS="pw$(random_string 15)"

0 commit comments

Comments
 (0)