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

fix: build endpoint for compat API #9790

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
48 changes: 44 additions & 4 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
BuildArgs string `schema:"buildargs"`
CacheFrom string `schema:"cachefrom"`
Compression uint64 `schema:"compression"`
ConfigureNetwork int64 `schema:"networkmode"`
ConfigureNetwork string `schema:"networkmode"`
CpuPeriod uint64 `schema:"cpuperiod"` // nolint
CpuQuota int64 `schema:"cpuquota"` // nolint
CpuSetCpus string `schema:"cpusetcpus"` // nolint
Expand All @@ -84,7 +84,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
ForceRm bool `schema:"forcerm"`
From string `schema:"from"`
HTTPProxy bool `schema:"httpproxy"`
Isolation int64 `schema:"isolation"`
Isolation string `schema:"isolation"`
Ignore bool `schema:"ignore"`
Jobs int `schema:"jobs"` // nolint
Labels string `schema:"labels"`
Expand Down Expand Up @@ -205,9 +205,15 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
isolation := buildah.IsolationDefault
*/
if utils.IsLibpodRequest(r) {
// isolation = buildah.Isolation(query.Isolation)
// isolation = parseLibPodIsolation(query.Isolation)
Copy link
Member

Choose a reason for hiding this comment

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

is this comment of any value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I understand it correctly the comment should be removed at some point see TODO above.

Copy link
Member

Choose a reason for hiding this comment

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

Yes I have a PR that is attempting to remove it.
I think we just merge this and I will continue to rework my PRs

registry = ""
format = query.OutputFormat
} else {
if _, found := r.URL.Query()["isolation"]; found {
if query.Isolation != "" && query.Isolation != "default" {
logrus.Debugf("invalid `isolation` parameter: %q", query.Isolation)
}
}
}
var additionalTags []string
if len(query.Tag) > 1 {
Expand Down Expand Up @@ -329,7 +335,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
CNIConfigDir: rtc.Network.CNIPluginDirs[0],
CNIPluginPath: util.DefaultCNIPluginPath,
Compression: compression,
ConfigureNetwork: buildah.NetworkConfigurationPolicy(query.ConfigureNetwork),
ConfigureNetwork: parseNetworkConfigurationPolicy(query.ConfigureNetwork),
ContextDirectory: contextDirectory,
Devices: devices,
DropCapabilities: dropCaps,
Expand Down Expand Up @@ -459,6 +465,40 @@ loop:
}
}

func parseNetworkConfigurationPolicy(network string) buildah.NetworkConfigurationPolicy {
if val, err := strconv.Atoi(network); err == nil {
return buildah.NetworkConfigurationPolicy(val)
}
switch network {
case "NetworkDefault":
return buildah.NetworkDefault
case "NetworkDisabled":
return buildah.NetworkDisabled
case "NetworkEnabled":
return buildah.NetworkEnabled
default:
return buildah.NetworkDefault
}
}

func parseLibPodIsolation(isolation string) buildah.Isolation { // nolint
if val, err := strconv.Atoi(isolation); err == nil {
return buildah.Isolation(val)
}
switch isolation {
case "IsolationDefault", "default":
return buildah.IsolationDefault
case "IsolationOCI":
return buildah.IsolationOCI
case "IsolationChroot":
return buildah.IsolationChroot
case "IsolationOCIRootless":
return buildah.IsolationOCIRootless
default:
return buildah.IsolationDefault
}
}

func extractTarFile(r *http.Request) (string, error) {
// build a home for the request body
anchorDir, err := ioutil.TempDir("", "libpod_builder")
Expand Down
2 changes: 1 addition & 1 deletion test/python/docker/compat/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_load_corrupt_image(self):
def test_build_image(self):
labels = {"apple": "red", "grape": "green"}
_ = self.client.images.build(
path="test/python/docker/build_labels", labels=labels, tag="labels"
path="test/python/docker/build_labels", labels=labels, tag="labels", isolation="default"
)
image = self.client.images.get("labels")
self.assertEqual(image.labels["apple"], labels["apple"])
Expand Down