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

use a script instead of piping to stdin in run_docker_build #337

Merged
merged 8 commits into from
Mar 2, 2018

Conversation

minrk
Copy link
Member

@minrk minrk commented Oct 26, 2016

Puts the script in build_artefacts/conda-forge-build.sh for use in the image.

It would appear that some tests interact with the stdin pipe, causing run_docker_build to finish early with apparent success, skipping the upload step. They seem to be doing this by consuming or detaching stdin somehow.

By using a regular script, pipes aren't involved, fixing at least one known cause of tests preventing upload.

Further, future similar failures should be protected against by writing a canary file in the build_artefacts dir at the end of the script. This is checked after docker run, in case other bugs reintroduce early exit with apparent success.

This is confirmed to fix the failure I was seeing on the new petsc-feedstock. The problematic test involved mpiexec, if that's relevant.

Other possibly affected cases:

@minrk minrk changed the title use a script instead of stdin-pipe in run_docker_build use a script instead of piping to stdin in run_docker_build Oct 26, 2016
@jakirkham
Copy link
Member

Good stuff @minrk ! Thanks for putting this together. 😀

Have definitely been suspicious of the pipe redirection for a while. I believe part of @pelson 's motivation for that design was to be security conscious. So we will need to evaluate these changes from that standpoint. Though maybe there are other concerns that he can share.

We should probably do something similar at staged-recipes. Though before we go down that road let me take a closer look at this implementation. Expect I should have some time later next week.

@jakirkham
Copy link
Member

Also do you have any links to builds, commits and/or PRs that are relevant from the petsc feedstock?

@minrk
Copy link
Member Author

minrk commented Oct 27, 2016

This build was run with the re-render and re-enabling the problematic test: https://circleci.com/gh/minrk/petsc-feedstock/3

This build is otherwise identical, rendered with smithy-1.3.3: https://circleci.com/gh/minrk/petsc-feedstock/4

Both pass, but note how the latter doesn't show the "No BINSTAR_TOKEN present..." output of run_docker_build.sh, indicating that it stopped at conda-build.

@minrk
Copy link
Member Author

minrk commented Oct 27, 2016

I'm not sure that writing a script in the feedstock can introduce a new security issue, because run_test.sh, etc. are mounted from the same directory and can be modified (after launching the build, even) to change what code the container runs. Although I guess now there is a file containing the BINSTAR_TOKEN, which may be what was meant to be avoided. I'm not sure how to avoid that with the script.

Things I wasn't so sure about:

  • where to put the build script / canary. I used build_artefacts because it's already git-ignored, but maybe it should be a new ignored folder. I aimed for minimal new things to start in a relatively unfamiliar codebase.
  • whether the canary is really necessary - I would be surprised if the issue is ever reintroduced, so maybe the canary check is too much.

EOF

docker run -i \
Copy link
Member

Choose a reason for hiding this comment

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

Given we are giving up redirection, what do you think about enabling TTY? Have already had a few issues where not having a TTY has caused problems (e.g. ncurses).

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, makes sense

Copy link
Member Author

Choose a reason for hiding this comment

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

TTY enabled

@jakirkham
Copy link
Member

Although I guess now there is a file containing the BINSTAR_TOKEN, which may be what was meant to be avoided. I'm not sure how to avoid that with the script.

Yes, this is what I meant. Sorry if that was cryptic. Not sure ATM either, but will try to think on it.

@jakirkham
Copy link
Member

where to put the build script / canary. I used build_artefacts because it's already git-ignored, but maybe it should be a new ignored folder. I aimed for minimal new things to start in a relatively unfamiliar codebase.

My inclination would be to put it in ci_support directory. We can also just add the file to .gitignore.

@minrk
Copy link
Member Author

minrk commented Oct 28, 2016

We can pass environment variables to docker on the CLI with -e and through files with --env-file, but both seem similarly snoopable. I don't see a way to tell docker run to 'use my environment variable' without echoing it somewhere other than the pipe.

Two pipey solutions if the file is to be avoided:

  1. write the script via pipe to docker build - so we get a docker image with the token-having script
  2. keep the pipe as-is, but write the whole content to a script in the container before running it

Both of these would avoid the token at rest on the host filesystem, but snoops with access to the docker service would be able to reach in and retrieve it

@jakirkham
Copy link
Member

This needs a rebase. Probably broken by PR ( #285 ). Should be an easy fix.

@minrk
Copy link
Member Author

minrk commented Jan 2, 2017

Sorry for forgetting about this one. Rebased and TTY enabled, per comment above.

@jakirkham
Copy link
Member

Thanks @minrk . I do want to take a closer look at this again, but it may not be for a couple weeks due to the other big changes with CI providers and conda-build.

@jakirkham jakirkham added this to the 2.1.0 milestone Jan 11, 2017
@jakirkham
Copy link
Member

Tentatively scheduling this for 2.1.0. I know we still have some more discussion and review to do, but am hopeful we should get this resolved soon. Please let me know if you think this is reasonable.

@jakirkham
Copy link
Member

@gqmelo , I'd be curious to hear your thoughts on this change. Would you have a chance to take a look?

@gqmelo
Copy link
Contributor

gqmelo commented Jan 11, 2017

I like the idea, but I'm sorry for my ignorance: is there a good reason to keep only one template? I mean, couldn't we have a build.tmpl so that conda smithy would render a ci_support/build.sh and ci_support/run_docker_build.sh? What would be the implications of rendering a ci_support/build.sh and commit it?

It is just that this would be simpler and make it easy to use build.sh without docker. I've needed this sometimes to investigate some errors that happened inside docker but not on my native machine (but then I had to extract only the conda-build stuff from run_docker_build.sh to try to reproduce it).

Anyway this would be probably another issue. I think these changes are nice

@minrk
Copy link
Member Author

minrk commented Feb 8, 2017

What would be the implications of rendering a ci_support/build.sh and commit it?

Exactly as it is, build.sh includes the BINSTAR_TOKEN env from circle, which we don't have at render time. I think it could be generated as a template and use an env-file to pass the token, though.

@minrk
Copy link
Member Author

minrk commented Feb 8, 2017

Actually, I might have a better idea - if we can do the upload from the host environment instead of the build environment, this should be even simpler, and not have any issues with tokens.

@gqmelo
Copy link
Contributor

gqmelo commented Feb 8, 2017

Actually, I might have a better idea - if we can do the upload from the host environment instead of the build environment, this should be even simpler, and not have any issues with tokens.

That would be nice but you would have to setup the host environment with dependencies needed by the upload script, right?

@dalcinl
Copy link

dalcinl commented Feb 8, 2017

@minrk @jakirkham What about running docker two times? The first one you build using a script, the second one you upload passing the token through stdin. I think this is even better, as you never expose the token to the build scripts.

@jakirkham
Copy link
Member

Was thinking about the same thing, @dalcinl.

@minrk
Copy link
Member Author

minrk commented Feb 8, 2017

@dalcinl good idea. This now runs docker twice:

  1. run the build with a plain script and proper tty (should fix mpiexec issues)
  2. run the upload step in a second container, passing the token via stdin

@minrk minrk force-pushed the docker-build-script branch 2 times, most recently from 65b93a3 to 3976569 Compare January 16, 2018 18:46
@minrk
Copy link
Member Author

minrk commented Jan 16, 2018

Rebased on master

Puts the script in build_artefacts/conda-forge-build.sh

It would appear that some tests interact with the stdin pipe,
causing run_docker_build to finish early with apparent success,
skipping the upload step.
They seem to be doing this by consuming or detaching stdin somehow.

By using a regular script, no pipes are involved,
fixing at least one known cause of tests preventing upload.

Further, future similar failures should be protected against by writing
a canary file in the build_artefacts dir at the end of the script.
This is checked, in case other bugs reintroduce early exit with apparent success.
and ignore it in .gitignore
1. build script doesn't have access to the token
2. upload gets token via stdin, but doesn't run user code

commit build container to an image, so upload can run in the same env
- build.sh goes in .circleci
- preserve set -x
not needed now that circle uses a real build matrix
@minrk
Copy link
Member Author

minrk commented Mar 2, 2018

rebased. This has gotten simpler since the original PR now that the matrix env stuff is no longer needed.

@ocefpaf
Copy link
Member

ocefpaf commented Mar 2, 2018

Ouch. Sorry @minrk another PR that we dropped the ball.

@ocefpaf ocefpaf merged commit 6d479f9 into conda-forge:master Mar 2, 2018
@minrk minrk deleted the docker-build-script branch March 2, 2018 11:48
-v "${RECIPE_ROOT}":/home/conda/recipe_root \
-v "${FEEDSTOCK_ROOT}":/home/conda/feedstock_root \
--env-file ${FEEDSTOCK_ROOT}/env \
-e HOST_USER_ID="${HOST_USER_ID}" \
Copy link
Member

Choose a reason for hiding this comment

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

You've missed the CONFIG env variable here.

Copy link
Member Author

Choose a reason for hiding this comment

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

# see https://github.com/conda-forge/conda-smithy/pull/337
# for a possible fix
set +x
echo "BINSTAR_TOKEN=${BINSTAR_TOKEN}" > "${FEEDSTOCK_ROOT}/env"
Copy link
Member

Choose a reason for hiding this comment

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

Put this inside .circleci folder?

Copy link
Member

Choose a reason for hiding this comment

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

Actually would it make sense to save this in a directory that is not mounted in the container? To propose an arbitrary option, what about ~/.conda-smithy/upload.token?

minrk added a commit to minrk/conda-smithy that referenced this pull request Mar 2, 2018
CONTAINER=$(docker create -t \
-v "${RECIPE_ROOT}":/home/conda/recipe_root \
-v "${FEEDSTOCK_ROOT}":/home/conda/feedstock_root \
--env-file ${FEEDSTOCK_ROOT}/env \
Copy link
Member

Choose a reason for hiding this comment

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

Was not aware of this option. Nice fix!

@isuruf
Copy link
Member

isuruf commented Mar 3, 2018

This doesn't work in circleci and hangs with no output after the build.sh is run.

@jakirkham
Copy link
Member

We can change back to docker run and just point to an env file outside the feedstock.

@isuruf
Copy link
Member

isuruf commented Mar 3, 2018

I'm going to revert it as I can't find anyway to fix it

@jakirkham
Copy link
Member

That seems reasonable, @isuruf. FWIW I do want us to solve this issue. Just think trying to tackle it in conda-smithy 3 when we are very close to releasing (and thus getting conda-build 3 support), is a bit ambitious personally.

@minrk
Copy link
Member Author

minrk commented Mar 4, 2018

FWIW, after the single typo fixed in #692 I can confirm that this PR results in working builds on circleci with no issues. successful build here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants