Compare commits
No commits in common. "28f14b82b0dc0fa67eee7039ec0ef7de81268160" and "c5c5c040c13ba553b57bd149c0c25989eb4c0423" have entirely different histories.
28f14b82b0
...
c5c5c040c1
23
README.md
23
README.md
@ -14,33 +14,12 @@ Otherworld creates a persistent Docker container running your choice of GNU/Linu
|
|||||||
### Remove the container
|
### Remove the container
|
||||||
`otherworld --rm`
|
`otherworld --rm`
|
||||||
|
|
||||||
## Arguments
|
|
||||||
These are arguments that go between `otherworld` and the command.
|
|
||||||
|
|
||||||
### --container=<container>
|
|
||||||
Name to assign to container (default: `otherworld_$USER`)
|
|
||||||
|
|
||||||
### --image=<image>
|
|
||||||
Image to create the container with (default: `debian:stable`)
|
|
||||||
|
|
||||||
### --sudo
|
|
||||||
Runs command as root, instead of current user.
|
|
||||||
|
|
||||||
### --rm
|
|
||||||
Removes the specified container.
|
|
||||||
|
|
||||||
### --build=<path>
|
|
||||||
Path to build context to build the image from. This overrides `--image`/`OW_IMAGE`.
|
|
||||||
|
|
||||||
### --volume=<volume>
|
|
||||||
Volume to map to the container. `~` is expanded automatically. If the directory exists in the user's home directory it will be created to ensure it has the correct ownership and permissions.
|
|
||||||
|
|
||||||
## Environment variables
|
## Environment variables
|
||||||
### OW_IMAGE
|
### OW_IMAGE
|
||||||
Image to create the container with (default: `debian:stable`)
|
Image to create the container with (default: `debian:stable`)
|
||||||
|
|
||||||
### OW_CONTAINER
|
### OW_CONTAINER
|
||||||
Name to assign to container (default: `otherworld_$USER`)
|
Name to assign to container (default: `overworld_$USER`)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
[GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.en.html) or later
|
[GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.en.html) or later
|
||||||
|
29
otherworld
29
otherworld
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from subprocess import call, check_call, check_output
|
from subprocess import call, check_output
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@ -58,19 +58,6 @@ def docker_exec (container, command, user):
|
|||||||
def docker_rm (container):
|
def docker_rm (container):
|
||||||
call(["docker", "rm", "-f", container])
|
call(["docker", "rm", "-f", container])
|
||||||
|
|
||||||
def docker_build (build_path, options, image_name):
|
|
||||||
check_call(["docker", "build"] + options + ["-t", image_name, build_path])
|
|
||||||
return image_name
|
|
||||||
|
|
||||||
def docker_pull (image_name):
|
|
||||||
check_call(["docker", "pull", image_name])
|
|
||||||
|
|
||||||
def resolve_build_path (build_path):
|
|
||||||
if build_path is not None and build_path.startswith("~/"):
|
|
||||||
build_path = f"{os.environ['HOME']}/{build_path[1:]}"
|
|
||||||
|
|
||||||
return build_path
|
|
||||||
|
|
||||||
def expand_user_volumes (volumes):
|
def expand_user_volumes (volumes):
|
||||||
outer_home = os.environ["HOME"]
|
outer_home = os.environ["HOME"]
|
||||||
inner_home = outer_home
|
inner_home = outer_home
|
||||||
@ -97,12 +84,10 @@ def expand_user_volumes (volumes):
|
|||||||
user = os.environ["USER"]
|
user = os.environ["USER"]
|
||||||
image_name = os.environ.get("OW_IMAGE", IMAGE_NAME)
|
image_name = os.environ.get("OW_IMAGE", IMAGE_NAME)
|
||||||
container_name = os.environ.get("OW_CONTAINER", f"{CONTAINER_NAME}_{user}")
|
container_name = os.environ.get("OW_CONTAINER", f"{CONTAINER_NAME}_{user}")
|
||||||
build_path = None
|
|
||||||
|
|
||||||
command = sys.argv[1:]
|
command = sys.argv[1:]
|
||||||
command_user = user
|
command_user = user
|
||||||
user_volumes = USER_VOLUMES
|
user_volumes = USER_VOLUMES
|
||||||
pull = False
|
|
||||||
|
|
||||||
quiet = False
|
quiet = False
|
||||||
while len(command) > 0:
|
while len(command) > 0:
|
||||||
@ -124,15 +109,9 @@ while len(command) > 0:
|
|||||||
elif arg.startswith("--image="):
|
elif arg.startswith("--image="):
|
||||||
image_name = arg[len("--image="):]
|
image_name = arg[len("--image="):]
|
||||||
command = command[1:]
|
command = command[1:]
|
||||||
elif arg.startswith("--build="):
|
|
||||||
build_path = arg[len("--build="):]
|
|
||||||
command = command[1:]
|
|
||||||
elif arg.startswith("--volume="):
|
elif arg.startswith("--volume="):
|
||||||
user_volumes.append(arg[len("--volume="):])
|
user_volumes.append(arg[len("--volume="):])
|
||||||
command = command[1:]
|
command = command[1:]
|
||||||
elif arg == "--pull":
|
|
||||||
command = command[1:]
|
|
||||||
pull = True
|
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -143,12 +122,6 @@ container = None
|
|||||||
try:
|
try:
|
||||||
container = docker_inspect(container_name)[0]
|
container = docker_inspect(container_name)[0]
|
||||||
except Exception:
|
except Exception:
|
||||||
build_path = resolve_build_path(build_path)
|
|
||||||
if build_path is not None:
|
|
||||||
image_name = docker_build(build_path, ["--pull"] if pull else [], f"image_{container_name}")
|
|
||||||
elif pull:
|
|
||||||
docker_pull(image_name)
|
|
||||||
|
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print(f">> Creating container: {container_name} (using image: {image_name})")
|
print(f">> Creating container: {container_name} (using image: {image_name})")
|
||||||
docker_create(
|
docker_create(
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
FROM debian:stable
|
|
||||||
RUN echo 'test' > /root/test
|
|
Loading…
x
Reference in New Issue
Block a user