Skip to content

Commit 745fa4a

Browse files
Merge pull request #9163 from mheon/backports_rc2
Backports for v3.0 RC2
2 parents b633607 + c1f05be commit 745fa4a

33 files changed

+628
-286
lines changed

.cirrus.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,17 +274,19 @@ swagger_task:
274274

275275

276276
# Check that all included go modules from other sources match
277-
# what is expected in `vendor/modules.txt` vs `go.mod`.
278-
vendor_task:
279-
name: "Test Vendoring"
280-
alias: vendor
277+
# what is expected in `vendor/modules.txt` vs `go.mod`. Also
278+
# make sure that the generated bindings in pkg/bindings/...
279+
# are in sync with the code.
280+
consistency_task:
281+
name: "Test Code Consistency"
282+
alias: consistency
281283
skip: *tags
282284
depends_on:
283285
- build
284286
container: *smallcontainer
285287
env:
286288
<<: *stdenvars
287-
TEST_FLAVOR: vendor
289+
TEST_FLAVOR: consistency
288290
TEST_ENVIRON: container
289291
CTR_FQIN: ${FEDORA_CONTAINER_FQIN}
290292
clone_script: *full_clone # build-cache not available to container tasks
@@ -642,7 +644,7 @@ success_task:
642644
- validate
643645
- bindings
644646
- swagger
645-
- vendor
647+
- consistency
646648
- alt_build
647649
- static_alt_build
648650
- osx_alt_build

Makefile

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ PODMAN_SERVER_LOG ?=
8686

8787
# If GOPATH not specified, use one in the local directory
8888
ifeq ($(GOPATH),)
89-
export GOPATH := $(CURDIR)/_output
89+
export GOPATH := $(HOME)/go
9090
unexport GOBIN
9191
endif
9292
FIRST_GOPATH := $(firstword $(subst :, ,$(GOPATH)))
@@ -98,6 +98,8 @@ ifeq ($(GOBIN),)
9898
GOBIN := $(FIRST_GOPATH)/bin
9999
endif
100100

101+
export PATH := $(PATH):$(GOBIN)
102+
101103
GOMD2MAN ?= $(shell command -v go-md2man || echo '$(GOBIN)/go-md2man')
102104

103105
CROSS_BUILD_TARGETS := \
@@ -206,7 +208,7 @@ endif
206208
podman: bin/podman
207209

208210
.PHONY: bin/podman-remote
209-
bin/podman-remote: .gopathok .generate-bindings $(SOURCES) go.mod go.sum ## Build with podman on remote environment
211+
bin/podman-remote: .gopathok $(SOURCES) go.mod go.sum ## Build with podman on remote environment
210212
$(GO) build $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN)' -tags "${REMOTETAGS}" -o $@ ./cmd/podman
211213

212214
.PHONY: bin/podman-remote-static
@@ -277,7 +279,6 @@ clean: ## Clean artifacts
277279
libpod/container_easyjson.go \
278280
libpod/pod_easyjson.go \
279281
.install.goimports \
280-
.generate-bindings \
281282
docs/build
282283
make -C docs clean
283284

@@ -459,20 +460,11 @@ podman-remote-%-release:
459460
rm -f release.txt
460461
$(MAKE) podman-remote-release-$*.zip
461462

462-
BINDINGS_SOURCE = $(wildcard pkg/bindings/**/types.go)
463-
.generate-bindings: $(BINDINGS_SOURCE)
463+
.PHONY: generate-bindings
464+
generate-bindings:
464465
ifneq ($(shell uname -s), Darwin)
465-
for i in $(BINDINGS_SOURCE); do \
466-
dirname=$$(dirname $${i}); \
467-
shortname=$$(basename $${dirname}); \
468-
pushd $${dirname}>/dev/null; \
469-
echo $${dirname}; \
470-
echo $(GO) generate; \
471-
$(GO) generate; \
472-
popd > /dev/null; \
473-
done;
466+
GO111MODULE=off $(GO) generate ./pkg/bindings/... ;
474467
endif
475-
touch .generate-bindings
476468

477469
.PHONY: docker-docs
478470
docker-docs: docs

cmd/podman/common/create_opts.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package common
33
import (
44
"fmt"
55
"net"
6+
"path/filepath"
67
"strconv"
78
"strings"
89

@@ -383,8 +384,29 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup
383384
}
384385

385386
// volumes
386-
if volumes := cc.HostConfig.Binds; len(volumes) > 0 {
387-
cliOpts.Volume = volumes
387+
volDestinations := make(map[string]bool)
388+
for _, vol := range cc.HostConfig.Binds {
389+
cliOpts.Volume = append(cliOpts.Volume, vol)
390+
// Extract the destination so we don't add duplicate mounts in
391+
// the volumes phase.
392+
splitVol := strings.SplitN(vol, ":", 3)
393+
switch len(splitVol) {
394+
case 1:
395+
volDestinations[vol] = true
396+
default:
397+
volDestinations[splitVol[1]] = true
398+
}
399+
}
400+
// Anonymous volumes are added differently from other volumes, in their
401+
// own special field, for reasons known only to Docker. Still use the
402+
// format of `-v` so we can just append them in there.
403+
// Unfortunately, these may be duplicates of existing mounts in Binds.
404+
// So... We need to catch that.
405+
for vol := range cc.Volumes {
406+
if _, ok := volDestinations[filepath.Clean(vol)]; ok {
407+
continue
408+
}
409+
cliOpts.Volume = append(cliOpts.Volume, vol)
388410
}
389411
if len(cc.HostConfig.BlkioWeightDevice) > 0 {
390412
devices := make([]string, 0, len(cc.HostConfig.BlkioWeightDevice))

cmd/podman/images/history.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (h historyReporter) Size() string {
162162
}
163163

164164
func (h historyReporter) CreatedBy() string {
165-
if len(h.ImageHistoryLayer.CreatedBy) > 45 {
165+
if !opts.noTrunc && len(h.ImageHistoryLayer.CreatedBy) > 45 {
166166
return h.ImageHistoryLayer.CreatedBy[:45-3] + "..."
167167
}
168168
return h.ImageHistoryLayer.CreatedBy

contrib/cirrus/runner.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ function _run_swagger() {
142142
cp -v $GOSRC/pkg/api/swagger.yaml $GOSRC/
143143
}
144144

145-
function _run_vendor() {
145+
function _run_consistency() {
146146
make vendor
147-
./hack/tree_status.sh
147+
SUGGESTION="run 'make vendor' and commit all changes" ./hack/tree_status.sh
148+
make generate-bindings
149+
SUGGESTION="run 'make generate-bindings' and commit all changes" ./hack/tree_status.sh
148150
}
149151

150152
function _run_build() {

contrib/cirrus/setup_environment.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ case "$TEST_FLAVOR" in
214214

215215
install_test_configs
216216
;;
217-
vendor) make clean ;;
217+
consistency) make clean ;;
218218
release) ;;
219219
*) die_unknown TEST_FLAVOR
220220
esac

libpod/container_api.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,3 +776,32 @@ func (c *Container) ShouldRestart(ctx context.Context) bool {
776776
}
777777
return c.shouldRestart()
778778
}
779+
780+
// ResolvePath resolves the specified path on the root for the container. The
781+
// root must either be the mounted image of the container or the already
782+
// mounted container storage.
783+
//
784+
// It returns the resolved root and the resolved path. Note that the path may
785+
// resolve to the container's mount point or to a volume or bind mount.
786+
func (c *Container) ResolvePath(ctx context.Context, root string, path string) (string, string, error) {
787+
logrus.Debugf("Resolving path %q (root %q) on container %s", path, root, c.ID())
788+
789+
// Minimal sanity checks.
790+
if len(root)*len(path) == 0 {
791+
return "", "", errors.Wrapf(define.ErrInternal, "ResolvePath: root (%q) and path (%q) must be non empty", root, path)
792+
}
793+
if _, err := os.Stat(root); err != nil {
794+
return "", "", errors.Wrapf(err, "cannot locate root to resolve path on container %s", c.ID())
795+
}
796+
797+
if !c.batched {
798+
c.lock.Lock()
799+
defer c.lock.Unlock()
800+
801+
if err := c.syncContainer(); err != nil {
802+
return "", "", err
803+
}
804+
}
805+
806+
return c.resolvePath(root, path)
807+
}

libpod/container_internal_linux.go

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,25 +174,60 @@ func (c *Container) prepare() error {
174174
return err
175175
}
176176

177-
// Ensure container entrypoint is created (if required)
178-
if c.config.CreateWorkingDir {
179-
workdir, err := securejoin.SecureJoin(c.state.Mountpoint, c.WorkingDir())
180-
if err != nil {
181-
return errors.Wrapf(err, "error creating path to container %s working dir", c.ID())
182-
}
183-
rootUID := c.RootUID()
184-
rootGID := c.RootGID()
177+
// Make sure the workdir exists
178+
if err := c.resolveWorkDir(); err != nil {
179+
return err
180+
}
185181

186-
if err := os.MkdirAll(workdir, 0755); err != nil {
187-
if os.IsExist(err) {
188-
return nil
182+
return nil
183+
}
184+
185+
// resolveWorkDir resolves the container's workdir and, depending on the
186+
// configuration, will create it, or error out if it does not exist.
187+
// Note that the container must be mounted before.
188+
func (c *Container) resolveWorkDir() error {
189+
workdir := c.WorkingDir()
190+
191+
// If the specified workdir is a subdir of a volume or mount,
192+
// we don't need to do anything. The runtime is taking care of
193+
// that.
194+
if isPathOnVolume(c, workdir) || isPathOnBindMount(c, workdir) {
195+
logrus.Debugf("Workdir %q resolved to a volume or mount", workdir)
196+
return nil
197+
}
198+
199+
_, resolvedWorkdir, err := c.resolvePath(c.state.Mountpoint, workdir)
200+
if err != nil {
201+
return err
202+
}
203+
logrus.Debugf("Workdir %q resolved to host path %q", workdir, resolvedWorkdir)
204+
205+
// No need to create it (e.g., `--workdir=/foo`), so let's make sure
206+
// the path exists on the container.
207+
if !c.config.CreateWorkingDir {
208+
if _, err := os.Stat(resolvedWorkdir); err != nil {
209+
if os.IsNotExist(err) {
210+
return errors.Errorf("workdir %q does not exist on container %s", workdir, c.ID())
189211
}
190-
return errors.Wrapf(err, "error creating container %s working dir", c.ID())
212+
// This might be a serious error (e.g., permission), so
213+
// we need to return the full error.
214+
return errors.Wrapf(err, "error detecting workdir %q on container %s", workdir, c.ID())
191215
}
216+
}
217+
218+
// Ensure container entrypoint is created (if required).
219+
rootUID := c.RootUID()
220+
rootGID := c.RootGID()
192221

193-
if err := os.Chown(workdir, rootUID, rootGID); err != nil {
194-
return errors.Wrapf(err, "error chowning container %s working directory to container root", c.ID())
222+
if err := os.MkdirAll(resolvedWorkdir, 0755); err != nil {
223+
if os.IsExist(err) {
224+
return nil
195225
}
226+
return errors.Wrapf(err, "error creating container %s workdir", c.ID())
227+
}
228+
229+
if err := os.Chown(resolvedWorkdir, rootUID, rootGID); err != nil {
230+
return errors.Wrapf(err, "error chowning container %s workdir to container root", c.ID())
196231
}
197232

198233
return nil

0 commit comments

Comments
 (0)