Skip to content

Add docker run script#172

Merged
istio-testing merged 4 commits intoistio:masterfrom
howardjohn:run-script
Mar 7, 2020
Merged

Add docker run script#172
istio-testing merged 4 commits intoistio:masterfrom
howardjohn:run-script

Conversation

@howardjohn
Copy link
Copy Markdown
Member

Take over https://github.com/istio/common-files/pull/94/files

This makes it possible to run interactive commands inside the build container

resolves istio/istio#17476 - all commands arguments to run-docker.sh are passed
into the container

resolves istio/istio#17474 - the script will pass along a filtered picture of the host's environment to the container

@howardjohn howardjohn requested a review from a team as a code owner December 23, 2019 17:27
@googlebot googlebot added the cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. label Dec 23, 2019
@istio-testing istio-testing added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 23, 2019
@howardjohn
Copy link
Copy Markdown
Member Author

/hold need some more work

@howardjohn
Copy link
Copy Markdown
Member Author

Ok I split out the enviroment variables, should be ok now

Copy link
Copy Markdown
Contributor

@ericvn ericvn left a comment

Choose a reason for hiding this comment

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

Will need a rebase.

Copy link
Copy Markdown
Member

@sdake sdake left a comment

Choose a reason for hiding this comment

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

looks like a good restructure of the existing Makefile (that has grown too unwieldy). Still, I can't help but think this will introduce unwanted side-effects and compound the difficulty of moving istio/istio to the container plan. Can you hold off on merging this work until istio/istio is on the container plan?

Cheers
-steve

/hold

files/Makefile Outdated
# Set up environment variables
$(shell mkdir -p out)
$(shell $(PWD)/common/scripts/setup_env.sh envfile > out/.env)
include out/.env
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand this include. Why not simply pass the variables in this file? I am not keen on using filesystem contents in the top level Makefile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We need a way to have the environment setting consistent across the makefile and the shell script. This was the only way I could come up with this, but if there are better approaches I am all ears, I didn't feel great about this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't have any immediate ideas, but I am beat after 5 hours of popcorn ceiling removal. Wow what a PITA. We can always adjust this in the future.

files/Makefile Outdated
ENV_VARS+=-e TAG="$(TAG)"
endif
RUN = ./common/scripts/run.sh
IMG ?= gcr.io/istio-testing/build-tools:master-2019-12-15T16-17-48
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMG version needs updating.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The whole PR is out of date a bit, I'll rebase once we are ready to merge

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am not sure why I have this IMG, it should just be defined in the script. Ill see if I can remove this one

files/Makefile Outdated
TIMEZONE=`readlink $(READLINK_FLAGS) /etc/localtime | sed -e 's/^.*zoneinfo\///'`
# Override variables with container specific
export TARGET_OUT=$(CONTAINER_TARGET_OUT)
export TARGET_OUT_LINUX=$(CONTAINER_TARGET_OUT_LINUX)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The introduction of CONTAINER_* variables seems confusing to me?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The intent here was that we are defining thins like TARGET_OUT conditionally in the Makefile so we need to have both defined in the script -- no one other than Makefile uses the container_out though.

However, we can probably do the BUILD_WITH_CONTAINER check inside the script an remove the need for this

-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
$CONTAINER_OPTIONS \
--env-file <(env | grep -v ${ENV_BLACKLIST}) \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice simple approach here).

--mount "type=bind,source=${PWD},destination=/work" \
--mount "type=volume,source=go,destination=/go" \
--mount "type=volume,source=gocache,destination=/gocache" \
${CONDITIONAL_HOST_MOUNTS} \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

default CONDITIOANL_HOST_MOUNTS missing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Its in the environment setup script

exit 1
fi

export UID
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

where is UID set? Not in the environment:

sdake@beast-01:~/go/src/istio.io/istio$ env | grep UID

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh maybe this isn't right then. UID is a builtin I guess

$ env | grep UID
$ echo $UID
576696

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd verify the export works as expected. I would think it should as a built-in but best to be sure.

export CONTAINER_TARGET_OUT="${CONTAINER_TARGET_OUT:-/work/out/${TARGET_OS}_${TARGET_ARCH}}"
export CONTAINER_TARGET_OUT_LINUX="${CONTAINER_TARGET_OUT_LINUX:-/work/out/linux_amd64}"

export IMG="${IMG:-gcr.io/istio-testing/build-tools:master-2019-12-15T16-17-48}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would be nice if we had one IMG variable to modify rather than two.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ack, I think the other one can be removed


export CONTAINER_CLI="${CONTAINER_CLI:-docker}"

export ENV_BLACKLIST="${ENV_BLACKLIST:-^_\|PATH\|SHELL\|EDITOR\|TMUX\|USER\|HOME\|PWD\|TERM\|GO\|rvm\|SSH}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

call this ENV_REJECTLIST please.

@sdake sdake added the do-not-merge Block automatic merging of a PR. label Jan 26, 2020
Copy link
Copy Markdown
Member Author

@howardjohn howardjohn left a comment

Choose a reason for hiding this comment

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

ill make the changes mentioned once we are on container plan for istio. This PR is a pain to rebase so I don't intend to keep it up to date until we are ready to merge

files/Makefile Outdated
# Set up environment variables
$(shell mkdir -p out)
$(shell $(PWD)/common/scripts/setup_env.sh envfile > out/.env)
include out/.env
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We need a way to have the environment setting consistent across the makefile and the shell script. This was the only way I could come up with this, but if there are better approaches I am all ears, I didn't feel great about this

files/Makefile Outdated
ENV_VARS+=-e TAG="$(TAG)"
endif
RUN = ./common/scripts/run.sh
IMG ?= gcr.io/istio-testing/build-tools:master-2019-12-15T16-17-48
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The whole PR is out of date a bit, I'll rebase once we are ready to merge

--mount "type=bind,source=${PWD},destination=/work" \
--mount "type=volume,source=go,destination=/go" \
--mount "type=volume,source=gocache,destination=/gocache" \
${CONDITIONAL_HOST_MOUNTS} \
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Its in the environment setup script

exit 1
fi

export UID
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh maybe this isn't right then. UID is a builtin I guess

$ env | grep UID
$ echo $UID
576696

files/Makefile Outdated
ENV_VARS+=-e TAG="$(TAG)"
endif
RUN = ./common/scripts/run.sh
IMG ?= gcr.io/istio-testing/build-tools:master-2019-12-15T16-17-48
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am not sure why I have this IMG, it should just be defined in the script. Ill see if I can remove this one

export CONTAINER_TARGET_OUT="${CONTAINER_TARGET_OUT:-/work/out/${TARGET_OS}_${TARGET_ARCH}}"
export CONTAINER_TARGET_OUT_LINUX="${CONTAINER_TARGET_OUT_LINUX:-/work/out/linux_amd64}"

export IMG="${IMG:-gcr.io/istio-testing/build-tools:master-2019-12-15T16-17-48}"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ack, I think the other one can be removed

files/Makefile Outdated
TIMEZONE=`readlink $(READLINK_FLAGS) /etc/localtime | sed -e 's/^.*zoneinfo\///'`
# Override variables with container specific
export TARGET_OUT=$(CONTAINER_TARGET_OUT)
export TARGET_OUT_LINUX=$(CONTAINER_TARGET_OUT_LINUX)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The intent here was that we are defining thins like TARGET_OUT conditionally in the Makefile so we need to have both defined in the script -- no one other than Makefile uses the container_out though.

However, we can probably do the BUILD_WITH_CONTAINER check inside the script an remove the need for this

@sdake
Copy link
Copy Markdown
Member

sdake commented Feb 3, 2020

Understood re difficulty of rebasing - especially against a moving target. I think BUILD_WITH_CONTAINER=1 PR is ready to merge. Once that is done, I'd suggest moving on this fast before more changes come to the TLD makefile in the common-files repo 😁

@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label Feb 12, 2020
@sdake
Copy link
Copy Markdown
Member

sdake commented Mar 3, 2020

@howardjohn what do you want to do with this PR post 1.5 release? I think the make system is in sold enough shape that a script based approach can be used. Best to do that at the beginning of the dev cycle (after 1.5 work is done of course).

Your thoughts welcome as I am listed as a reviewer.

@howardjohn
Copy link
Copy Markdown
Member Author

howardjohn commented Mar 3, 2020 via email

@howardjohn
Copy link
Copy Markdown
Member Author

howardjohn commented Mar 3, 2020 via email

This allows running the same set of logic for the script runs and
makefile runs. It also allows non makefile users to source this and
continue to run `go test ./...` or whatever they want, without
duplicated logic.
@istio-testing istio-testing removed the needs-rebase Indicates a PR needs to be rebased before being merged label Mar 6, 2020
@howardjohn howardjohn removed the do-not-merge Block automatic merging of a PR. label Mar 7, 2020
@istio-testing istio-testing merged commit dfe763e into istio:master Mar 7, 2020
@howardjohn
Copy link
Copy Markdown
Member Author

I did not mean to merge this, I didn't realize it was approved. However, I do think it should be merge. If anyone disagrees we can revert or roll forward?

howardjohn added a commit to howardjohn/common-files that referenced this pull request Mar 7, 2020
I broke this in istio#172 because I forgot about the BUILD_WITH_CONTAINER=0
case... This should get things moving again. I have tested this in
istio/istio#21951
@clarketm
Copy link
Copy Markdown
Member

clarketm commented Mar 7, 2020

I did not mean to merge this, I didn't realize it was approved. However, I do think it should be merge. If anyone disagrees we can revert or roll forward?

@howardjohn

Did the API change? Or there is probably an assumption that this is to run on Linux host? but FWIW make commands no longer work for me locally on MacOS after this merged (even when running in container).

$ BUILD_WITH_CONTAINER=1 make lint

/bin/sh: 1: set: Illegal option -o pipefail
common/Makefile.common.mk:33: recipe for target 'lint-yaml' failed
make[1]: *** [lint-yaml] Error 2
make: *** [Makefile:44: lint] Error 2
$ BUILD_WITH_CONTAINER=1 make update-common

mkdir: cannot create directory '/var/folders': Permission denied
common/Makefile.common.mk:98: recipe for target 'update-common' failed
make[1]: *** [update-common] Error 1
make: *** [Makefile:44: update-common] Error 2
$ BUILD_WITH_CONTAINER=1 make test

go: creating work dir: stat /var/folders/9j/nh3fxdf153v11vsjwtd1lf_800n1b6/T/: no such file or directory
Makefile.core.mk:23: recipe for target 'test' failed
make[1]: *** [test] Error 1
make: *** [Makefile:44: test] Error 2

clarketm added a commit that referenced this pull request Mar 7, 2020
istio-testing pushed a commit that referenced this pull request Mar 7, 2020
howardjohn added a commit to howardjohn/common-files that referenced this pull request Mar 9, 2020
* Add docker run script

* Break out environment setup into a common script

This allows running the same set of logic for the script runs and
makefile runs. It also allows non makefile users to source this and
continue to run `go test ./...` or whatever they want, without
duplicated logic.

* Fix lint

* clean up

(cherry picked from commit dfe763e)
istio-testing pushed a commit that referenced this pull request Mar 9, 2020
* Add docker run script (#172)

* Add docker run script

* Break out environment setup into a common script

This allows running the same set of logic for the script runs and
makefile runs. It also allows non makefile users to source this and
continue to run `go test ./...` or whatever they want, without
duplicated logic.

* Fix lint

* clean up

(cherry picked from commit dfe763e)

* done

(cherry picked from commit 0b5b799084d5654b1260fbb49a1f4c4c45389434)

* Add TMPDIR to blocklist

For OS X
fjglira pushed a commit to fjglira/istio-common-files that referenced this pull request Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUILD_WITH_CONTAINER=1 needs way to run arbitrary commands BUILD_WITH_CONTAINER=1 cannot pass environment variables

7 participants