Skip to content

Commit

Permalink
Remove bypass support
Browse files Browse the repository at this point in the history
Removes support for bypassing pyrex with an environment variable. This
support has some issues now that capture of the environment is done
inside of a container and it's easy enough for a user to simply init
the environment with a different script.
  • Loading branch information
JoshuaWatt committed Jan 28, 2020
1 parent 916ef8d commit 5bf35d1
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 101 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,6 @@ Pyrex environment setup you created. This will setup up the current shell to
run the commands listed in `${config:command}` inside of Pyrex. Once this is
done, you can simply run those commands and they will be executed in Pyrex.

### Bypassing Pyrex
In some cases, it may be desirable to bypass Pyrex and run the commands it
wraps locally instead of in the container. This can be done in one of two ways:

1. Set `${run:enable}` to `0` in `pyrex.ini` which will disable using the
container engine for all commands
2. Set the environment variable `PYREX_USE_CONTAINER` to `0`. Any Pyrex
commands run with this variable will not be run in the container.

## What doesn't work?
The following items are either known to not work, or haven't been fully tested:
* **Bitbake Server** Since the container starts and stops each time a command
Expand Down
7 changes: 1 addition & 6 deletions ci/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def test_pyrex_shell(self):
def test_pyrex_run(self):
self.assertPyrexContainerCommand("/bin/false", returncode=1)

def test_disable_pyrex(self):
def test_in_container(self):
def capture_pyrex_state(*args, **kwargs):
capture_file = os.path.join(self.thread_dir, "pyrex_capture")

Expand Down Expand Up @@ -337,11 +337,6 @@ def capture_local_state():
pyrex_state = capture_pyrex_state()
self.assertNotEqual(local_state, pyrex_state)

env = os.environ.copy()
env["PYREX_USE_CONTAINER"] = "0"
pyrex_state = capture_pyrex_state(env=env)
self.assertEqual(local_state, pyrex_state)

def test_quiet_build(self):
env = os.environ.copy()
env["PYREX_BUILD_QUIET"] = "1"
Expand Down
4 changes: 1 addition & 3 deletions image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,12 @@ ENV LC_ALL en_US.UTF-8
# Add startup scripts
COPY ./run.sh /usr/libexec/pyrex/run
COPY ./capture.sh /usr/libexec/pyrex/capture
COPY ./bypass.sh /usr/libexec/pyrex/bypass
COPY ./entry.py /usr/libexec/pyrex/entry.py
COPY ./cleanup.py /usr/libexec/pyrex/cleanup.py
RUN chmod +x /usr/libexec/pyrex/cleanup.py \
/usr/libexec/pyrex/entry.py \
/usr/libexec/pyrex/run \
/usr/libexec/pyrex/capture \
/usr/libexec/pyrex/bypass
/usr/libexec/pyrex/capture

# Add startup script directory & test script.
COPY ./test_startup.sh /usr/libexec/pyrex/startup.d/
Expand Down
27 changes: 0 additions & 27 deletions image/bypass.sh

This file was deleted.

6 changes: 0 additions & 6 deletions image/capture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ cat > $PYREX_CAPTURE_DEST <<HEREDOC
"PATH": "$PATH",
"BUILDDIR": "$BUILDDIR"
}
},
"bypass": {
"env": {
"PYREX_OEINIT": "$PYREX_OEINIT ${PYREX_ARGS[@]}",
"PYREX_OEINIT_DIR": "$INIT_PWD"
}
}
}
HEREDOC
Expand Down
4 changes: 0 additions & 4 deletions pyrex.ini
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ confversion = @CONFVERSION@
# Runtime options. Changes in this section take effect the next time a Pyrex
# command is run
[run]
# Should the container engine be enabled? Can be used to disable using the
# container engine for all commands
%enable = 1

# A list of directories that should be bound when running in the container
%bind =
% ${env:PYREX_BIND}
Expand Down
58 changes: 12 additions & 46 deletions pyrex.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ def get_image_id(config, image):
)


def use_container(config):
return os.environ.get("PYREX_USE_CONTAINER", config["run"]["enable"]) == "1"


def build_image(config, build_config):
build_config.setdefault("build", {})

Expand Down Expand Up @@ -633,21 +629,6 @@ def create_shims(config, build_config, buildconf):
)
os.chmod(rebuildfile, stat.S_IRWXU)

# Create bypass command
bypassfile = os.path.join(shimdir, "pyrex-bypass")
engine_args = [
config["config"]["engine"],
"run",
"--rm",
"--entrypoint",
"cat",
build_config["build"]["runid"],
"/usr/libexec/pyrex/bypass",
]
with open(bypassfile, "w") as f:
subprocess.run(engine_args, check=True, stdout=f)
os.chmod(bypassfile, stat.S_IRWXU)

# Create shims
user_commands = config["config"].get("commands")
if user_commands:
Expand Down Expand Up @@ -718,7 +699,6 @@ def capture(args):
build_config["run"] = capture["run"]
build_config["container"] = capture["container"]
build_config["tempdir"] = capture["tempdir"]
build_config["bypass"] = capture["bypass"]

try:
os.makedirs(build_config["tempdir"])
Expand Down Expand Up @@ -766,35 +746,21 @@ def run(args):
with open(args.buildconf, "r") as f:
build_config = json.load(f)

if use_container(config):
engine_args = prep_container(
config,
build_config,
["/usr/libexec/pyrex/run"] + args.command,
extra_env=build_config.get("run", {}).get("env", {}),
allow_test_config=True,
)

if not engine_args:
sys.exit(1)
engine_args = prep_container(
config,
build_config,
["/usr/libexec/pyrex/run"] + args.command,
extra_env=build_config.get("run", {}).get("env", {}),
allow_test_config=True,
)

stop_coverage()
os.execvp(engine_args[0], engine_args)
print("Cannot exec container!")
if not engine_args:
sys.exit(1)
else:
command = [
os.path.join(build_config["shimdir"], "pyrex-bypass")
] + args.command

env = os.environ.copy()
for k, v in build_config.get("bypass", {}).get("env", {}).items():
env[k] = v

stop_coverage()
os.execve(command[0], command, env)
print("Cannot exec command!")
sys.exit(1)
stop_coverage()
os.execvp(engine_args[0], engine_args)
print("Cannot exec container!")
sys.exit(1)

def config_get(args):
config = load_config()
Expand Down

0 comments on commit 5bf35d1

Please sign in to comment.