Skip to content

Commit 44f11ec

Browse files
committed
podman-remote: enable support for additional build-context on macOS, remote
Feature of additional build context added here containers/buildah#3978 already exists on `podman` following PR just enables this feature of `podman-remote` and `podman on macOS` setups. Signed-off-by: Aditya R <[email protected]>
1 parent 516c955 commit 44f11ec

File tree

4 files changed

+86
-80
lines changed

4 files changed

+86
-80
lines changed

docs/source/markdown/podman-build.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ different stages in COPY instruction.
9999

100100
Valid values could be:
101101

102-
* Local directory – e.g. --build-context project2=../path/to/project2/src
102+
* Local directory – e.g. --build-context project2=../path/to/project2/src (This option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines)
103103
* HTTP URL to a tarball – e.g. --build-context src=https://example.org/releases/src.tar
104104
* Container image – specified with a container-image:// prefix, e.g. --build-context alpine=container-image://alpine:3.15, (also accepts docker://, docker-image://)
105105

pkg/api/handlers/compat/images_build.go

Lines changed: 78 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -70,68 +70,69 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
7070
}()
7171

7272
query := struct {
73-
AddHosts string `schema:"extrahosts"`
74-
AdditionalCapabilities string `schema:"addcaps"`
75-
AllPlatforms bool `schema:"allplatforms"`
76-
Annotations string `schema:"annotations"`
77-
AppArmor string `schema:"apparmor"`
78-
BuildArgs string `schema:"buildargs"`
79-
CacheFrom string `schema:"cachefrom"`
80-
CgroupParent string `schema:"cgroupparent"` // nolint
81-
Compression uint64 `schema:"compression"`
82-
ConfigureNetwork string `schema:"networkmode"`
83-
CPPFlags string `schema:"cppflags"`
84-
CpuPeriod uint64 `schema:"cpuperiod"` // nolint
85-
CpuQuota int64 `schema:"cpuquota"` // nolint
86-
CpuSetCpus string `schema:"cpusetcpus"` // nolint
87-
CpuSetMems string `schema:"cpusetmems"` // nolint
88-
CpuShares uint64 `schema:"cpushares"` // nolint
89-
DNSOptions string `schema:"dnsoptions"`
90-
DNSSearch string `schema:"dnssearch"`
91-
DNSServers string `schema:"dnsservers"`
92-
Devices string `schema:"devices"`
93-
Dockerfile string `schema:"dockerfile"`
94-
DropCapabilities string `schema:"dropcaps"`
95-
Envs []string `schema:"setenv"`
96-
Excludes string `schema:"excludes"`
97-
ForceRm bool `schema:"forcerm"`
98-
From string `schema:"from"`
99-
HTTPProxy bool `schema:"httpproxy"`
100-
IdentityLabel bool `schema:"identitylabel"`
101-
Ignore bool `schema:"ignore"`
102-
Isolation string `schema:"isolation"`
103-
Jobs int `schema:"jobs"` // nolint
104-
LabelOpts string `schema:"labelopts"`
105-
Labels string `schema:"labels"`
106-
Layers bool `schema:"layers"`
107-
LogRusage bool `schema:"rusage"`
108-
Manifest string `schema:"manifest"`
109-
MemSwap int64 `schema:"memswap"`
110-
Memory int64 `schema:"memory"`
111-
NamespaceOptions string `schema:"nsoptions"`
112-
NoCache bool `schema:"nocache"`
113-
OSFeatures []string `schema:"osfeature"`
114-
OSVersion string `schema:"osversion"`
115-
OutputFormat string `schema:"outputformat"`
116-
Platform []string `schema:"platform"`
117-
Pull bool `schema:"pull"`
118-
PullPolicy string `schema:"pullpolicy"`
119-
Quiet bool `schema:"q"`
120-
Registry string `schema:"registry"`
121-
Rm bool `schema:"rm"`
122-
RusageLogFile string `schema:"rusagelogfile"`
123-
Remote string `schema:"remote"`
124-
Seccomp string `schema:"seccomp"`
125-
Secrets string `schema:"secrets"`
126-
SecurityOpt string `schema:"securityopt"`
127-
ShmSize int `schema:"shmsize"`
128-
Squash bool `schema:"squash"`
129-
TLSVerify bool `schema:"tlsVerify"`
130-
Tags []string `schema:"t"`
131-
Target string `schema:"target"`
132-
Timestamp int64 `schema:"timestamp"`
133-
Ulimits string `schema:"ulimits"`
134-
UnsetEnvs []string `schema:"unsetenv"`
73+
AddHosts string `schema:"extrahosts"`
74+
AdditionalCapabilities string `schema:"addcaps"`
75+
AdditionalBuildContexts string `schema:"additionalbuildcontexts"`
76+
AllPlatforms bool `schema:"allplatforms"`
77+
Annotations string `schema:"annotations"`
78+
AppArmor string `schema:"apparmor"`
79+
BuildArgs string `schema:"buildargs"`
80+
CacheFrom string `schema:"cachefrom"`
81+
CgroupParent string `schema:"cgroupparent"` // nolint
82+
Compression uint64 `schema:"compression"`
83+
ConfigureNetwork string `schema:"networkmode"`
84+
CPPFlags string `schema:"cppflags"`
85+
CpuPeriod uint64 `schema:"cpuperiod"` // nolint
86+
CpuQuota int64 `schema:"cpuquota"` // nolint
87+
CpuSetCpus string `schema:"cpusetcpus"` // nolint
88+
CpuSetMems string `schema:"cpusetmems"` // nolint
89+
CpuShares uint64 `schema:"cpushares"` // nolint
90+
DNSOptions string `schema:"dnsoptions"`
91+
DNSSearch string `schema:"dnssearch"`
92+
DNSServers string `schema:"dnsservers"`
93+
Devices string `schema:"devices"`
94+
Dockerfile string `schema:"dockerfile"`
95+
DropCapabilities string `schema:"dropcaps"`
96+
Envs []string `schema:"setenv"`
97+
Excludes string `schema:"excludes"`
98+
ForceRm bool `schema:"forcerm"`
99+
From string `schema:"from"`
100+
HTTPProxy bool `schema:"httpproxy"`
101+
IdentityLabel bool `schema:"identitylabel"`
102+
Ignore bool `schema:"ignore"`
103+
Isolation string `schema:"isolation"`
104+
Jobs int `schema:"jobs"` // nolint
105+
LabelOpts string `schema:"labelopts"`
106+
Labels string `schema:"labels"`
107+
Layers bool `schema:"layers"`
108+
LogRusage bool `schema:"rusage"`
109+
Manifest string `schema:"manifest"`
110+
MemSwap int64 `schema:"memswap"`
111+
Memory int64 `schema:"memory"`
112+
NamespaceOptions string `schema:"nsoptions"`
113+
NoCache bool `schema:"nocache"`
114+
OSFeatures []string `schema:"osfeature"`
115+
OSVersion string `schema:"osversion"`
116+
OutputFormat string `schema:"outputformat"`
117+
Platform []string `schema:"platform"`
118+
Pull bool `schema:"pull"`
119+
PullPolicy string `schema:"pullpolicy"`
120+
Quiet bool `schema:"q"`
121+
Registry string `schema:"registry"`
122+
Rm bool `schema:"rm"`
123+
RusageLogFile string `schema:"rusagelogfile"`
124+
Remote string `schema:"remote"`
125+
Seccomp string `schema:"seccomp"`
126+
Secrets string `schema:"secrets"`
127+
SecurityOpt string `schema:"securityopt"`
128+
ShmSize int `schema:"shmsize"`
129+
Squash bool `schema:"squash"`
130+
TLSVerify bool `schema:"tlsVerify"`
131+
Tags []string `schema:"t"`
132+
Target string `schema:"target"`
133+
Timestamp int64 `schema:"timestamp"`
134+
Ulimits string `schema:"ulimits"`
135+
UnsetEnvs []string `schema:"unsetenv"`
135136
}{
136137
Dockerfile: "Dockerfile",
137138
IdentityLabel: true,
@@ -375,6 +376,14 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
375376
additionalTags = append(additionalTags, possiblyNormalizedTag)
376377
}
377378

379+
var additionalBuildContexts = map[string]*buildahDefine.AdditionalBuildContext{}
380+
if _, found := r.URL.Query()["additionalbuildcontexts"]; found {
381+
if err := json.Unmarshal([]byte(query.AdditionalBuildContexts), &additionalBuildContexts); err != nil {
382+
utils.BadRequest(w, "additionalbuildcontexts", query.AdditionalBuildContexts, err)
383+
return
384+
}
385+
}
386+
378387
var buildArgs = map[string]string{}
379388
if _, found := r.URL.Query()["buildargs"]; found {
380389
if err := json.Unmarshal([]byte(query.BuildArgs), &buildArgs); err != nil {
@@ -562,12 +571,13 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
562571

563572
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
564573
buildOptions := buildahDefine.BuildOptions{
565-
AddCapabilities: addCaps,
566-
AdditionalTags: additionalTags,
567-
Annotations: annotations,
568-
CPPFlags: cppflags,
569-
Args: buildArgs,
570-
AllPlatforms: query.AllPlatforms,
574+
AddCapabilities: addCaps,
575+
AdditionalBuildContexts: additionalBuildContexts,
576+
AdditionalTags: additionalTags,
577+
Annotations: annotations,
578+
CPPFlags: cppflags,
579+
Args: buildArgs,
580+
AllPlatforms: query.AllPlatforms,
571581
CommonBuildOpts: &buildah.CommonBuildOptions{
572582
AddHost: addhosts,
573583
ApparmorProfile: apparmor,

pkg/bindings/images/build.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
8181
for _, tag := range options.AdditionalTags {
8282
params.Add("t", tag)
8383
}
84+
if additionalBuildContexts := options.AdditionalBuildContexts; len(additionalBuildContexts) > 0 {
85+
additionalBuildContextMap, err := jsoniter.Marshal(additionalBuildContexts)
86+
if err != nil {
87+
return nil, err
88+
}
89+
params.Set("additionalbuildcontexts", string(additionalBuildContextMap))
90+
}
8491
if buildArgs := options.Args; len(buildArgs) > 0 {
8592
bArgs, err := jsoniter.MarshalToString(buildArgs)
8693
if err != nil {

test/buildah-bud/apply-podman-deltas

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,10 @@ skip_if_remote "volumes don't work with podman-remote" \
193193
"buildah bud --volume" \
194194
"buildah-bud-policy"
195195

196-
# Most of this should work in podman remote after API implementation other than where context is host.
197196
skip_if_remote "--build-context option not implemented in podman-remote" \
198-
"build-with-additional-build-context and COPY, test pinning image" \
199-
"build-with-additional-build-context and COPY, stagename and additional-context conflict" \
200-
"build-with-additional-build-context and COPY, additionalContext and numeric value of stage" \
201-
"build-with-additional-build-context and COPY, additionalContext and numeric value of stage" \
202197
"build-with-additional-build-context and COPY, additional context from host" \
203-
"build-with-additional-build-context and COPY, additional context from external URL" \
204-
"build-with-additional-build-context and RUN --mount=from=, additional-context is URL and mounted from subdir" \
205198
"build-with-additional-build-context and RUN --mount=from=, additional-context not image and also test conflict with stagename" \
206-
"build-with-additional-build-context and RUN --mount=from=, additional-context and also test conflict with stagename" \
207-
"bud-multiple-platform for --all-platform with additional-build-context" \
208-
"build-with-additional-build-context and FROM, stagename and additional-context conflict" \
209199
"bud with Containerfile.in, via envariable" \
210-
"build-with-additional-build-context and FROM, pin busybox to alpine"
211200

212201
# Requires a local file outside context dir
213202
skip_if_remote "local keyfile not sent to podman-remote" \

0 commit comments

Comments
 (0)