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

*: add bottlecap, an optional entry point #182

Merged
merged 1 commit into from
Nov 12, 2018

Conversation

ajeddeloh
Copy link
Contributor

Add bottlecap as the default entry point. It will handle launching the
coreos-assembler container and optionally binding in and rebuilding
certain aspects to aid development. This is in additon to the existing
flows.

Putting this up as WIP to get some feedback, will add docs before final version

@cgwalters
Copy link
Member

Can you elaborate slightly on the usage of this? One would run it as root like ./bottlecap from a git clone of this repo?

bottlecap Outdated Show resolved Hide resolved
bottlecap Outdated

if [ "$dev" == 1 ]; then
volumes+="-v $script_dir:/host/src "
volumes+="-v $(go env GOCACHE):/root/.cache/go-build "
Copy link
Member

Choose a reason for hiding this comment

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

On a SELinux enabled system this assumes these are labeled too. Which may be OK, but will almost certainly bite people. (I try not to run containers accessing my /home for example)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm. the gocache is easy enough (just put it literally anywhere that will persist across container runs).

If we want to support local dev though we need to be able to bind in wherever the build scripts are coming from (which is right now, this repo)

Copy link
Member

Choose a reason for hiding this comment

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

The TL;DR is that SELinux + docker/podman (as root anyways) want files to be labeled specially for containers. Trying to do -v /home/myuser:/home for example will fail, and you don't want to relabel your /home.

Copy link
Member

Choose a reason for hiding this comment

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

(To pivot this topic though, while I haven't played with it the "rootless" podman should sidestep this issue; if we merge the bits to have this container not require privileges, just /dev/kvm, that will work well for rootless too)

Copy link
Member

Choose a reason for hiding this comment

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

another note here: we need to check if go env GOCACHE reports a value before we try to mount it in:

$ ./bottlecap --build-dir /srv/ --dev --container ca build
./bottlecap: line 81: go: command not found
+ sudo podman run --rm --net=host -ti --privileged --userns=host -v /var/srv:/srv -v /var/sharedfolder/code/github.com/coreos/coreos-assembler:/host/src -v :/root/.cache/go-build --workdir /srv --entrypoint /host/src/bottlecap-shim ca d
invalid host path, must be an absolute path ""

@ajeddeloh
Copy link
Contributor Author

ajeddeloh commented Oct 22, 2018

Yeah, that's the idea. Basically allow an easy way to both work on the container itself and give an opinionated way to use it. Manually setting bash aliases is not ideal. The goal is also to keep bottlecap as stripped down as possible.

Edit: shouldn't need root I don't think?

@ajeddeloh ajeddeloh force-pushed the bottlecap branch 2 times, most recently from 956db3b to 00af17e Compare October 22, 2018 21:57
bottlecap Outdated Show resolved Hide resolved
bottlecap Show resolved Hide resolved
@@ -0,0 +1,76 @@
#!/bin/sh

# bottlecap, 'cause it's kinda like cork... get it?
Copy link
Member

Choose a reason for hiding this comment

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

cork is nice since it's 4 letters :) - I like cass because it's also 4 letters, but I also like highlighting that this is the script vs an alias that someone has defined on the command line (since I like to define my alias as alias cass=. So cass.sh would be my suggestion here, but also takes us back to 7 characters so I'm a hypocrite :)

This was mostly just a thought excercise for me. We don't need to change anything unless you want to.

@ajeddeloh
Copy link
Contributor Author

Not sure what to do about the selinux issue @cgwalters brought up (ideas?) but I switched to getopt parsing.

@dustymabe
Copy link
Member

one thing you could do for the selinux issue is detect and error (or warn). If system has selinux enabled and the label on the files aren't going to work then error/warn. For example tell them they could chcon -Rt svirt_sandbox_file_t /path/to/files/

bottlecap Outdated
echo " --container: which coreos-assembler container to use"
echo " --help: print this help message"
echo "Command to be executed:"
runtime="echo $runtime"
Copy link
Member

Choose a reason for hiding this comment

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

I feel like the above two lines should be deleted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could go either way. It's certainly been useful for debugging bottlecap and I think it does a good job of illustrating that bottlecap is just a thin wrapper. What about a ---dry-run option instead?

Copy link
Member

@dustymabe dustymabe Nov 8, 2018

Choose a reason for hiding this comment

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

right now it doesn't actually output the command to be executed I don't think. It outputs Command to be executed: and then sets the runtime variable equal to "echo $runtime", which doesn't print anything to the screen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it sets runtime to echo $runtime because some of the args are not set when usage is called. Note it does not exit immediately after usage.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Thanks for explaining. I did not understand what you were doing. We discussed that you could also achieve this with --dry-run

bottlecap Show resolved Hide resolved
bottlecap Outdated

usage() {
echo "usage:"
echo "bottlecap [--dev] [--runtime $runtime] [--build-dir $build_dir] [--container $container] assemblerargs..."
Copy link
Member

Choose a reason for hiding this comment

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

did you mean to evaluate the above variables when we print stuff to the screen? If not then we should use single quotes and not double quotes here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do. You can do bottlecap --build-dir foobar --help and see your arg reflected in the help text, which I am a fan of personally.

Copy link
Member

Choose a reason for hiding this comment

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

I see, I haven't seen that very much in practice, but seems OK

bottlecap Outdated
build_dir="$(pwd)"
container="quay.io/cgwalters/coreos-assembler"

TEMP=$(getopt -o 'dr:b:c:h' --long 'dev,runtime:,build-dir:,container:,help' -- $@)
Copy link
Member

Choose a reason for hiding this comment

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

you need to check the exit code of getopt and call usage() and exit if it failed.

bottlecap Outdated
entrypoint="--entrypoint /host/src/bottlecap-shim"
fi

$runtime run --rm --net=host -ti --privileged --userns=host $volumes --workdir /srv $entrypoint $container $@
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should set -x right above this command

also, do we expect users to run sudo ./bottlecap ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also, do we expect users to run sudo ./bottlecap

If needed. I'd rather leave that to the user to decide than than bake it into the script.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe we should set -x right above this command

SGTM

@dustymabe
Copy link
Member

a few style comments:

  • there is a PR to run most of our bash through shellcheck, might be worth doing that here too.
  • you like tabs don't you? I think we had that conversation before

bottlecap Show resolved Hide resolved
@ajeddeloh
Copy link
Contributor Author

Will do on running it through shellcheck.

And yeah, I do like tabs, let everyone decide their own indentation level (I typically like 8, which is far more than most people I think).

@ajeddeloh ajeddeloh force-pushed the bottlecap branch 2 times, most recently from 0212211 to 4c30422 Compare November 9, 2018 00:18
@ajeddeloh
Copy link
Contributor Author

Fixed a lot of things, switch the gocache to just always use $script_dir/.gocache and added that to the .gitignore.

Passes shellcheck, with one exception where we actually do want glob expansion

@ajeddeloh ajeddeloh changed the title WIP: *: add bottlecap, an optional entry point *: add bottlecap, an optional entry point Nov 9, 2018
bottlecap Outdated
rc=0
TEMP=$(getopt -o 'dr:b:c:h' --long 'dev,dry-run,runtime:,build-dir:,container:,help' -- "$@") || rc=$?
if [ "$rc" -ne 0 ]; then
echo "Bad arguments. getopt failed."
Copy link
Member

Choose a reason for hiding this comment

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

should the above go to stderr ?

bottlecap Show resolved Hide resolved
bottlecap Outdated
break
;;
*)
echo "Error parsing args"
Copy link
Member

Choose a reason for hiding this comment

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

not sure if this section is needed any longer since we are using getopt, but if we keep this let's spit that message to stderr

@dustymabe
Copy link
Member

a few final comments in the code on stderr.. otherwise LGTM.

will probably want to update this in a future PR to handle the 'unpriv' case, but we don't need to do that now

Add bottlecap as the default entry point. It will handle launching the
coreos-assembler container and optionally binding in and rebuilding
certain aspects to aid development. This is in additon to the existing
flows.
@ajeddeloh
Copy link
Contributor Author

Made errors go to stdout, fixed shellcheck complaints in bottlecap-shim

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.

3 participants