Skip to content

Commit

Permalink
simplify dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
StardustDL committed Mar 13, 2024
1 parent 3c65e15 commit 8b274ac
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 19 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ jobs:
- name: Test Image Runner
run: |
aexpy runimage ./cache -t stardustdl/aexpy:latest -- --version
aexpy runimage ./cache -t -- view report.json.gz
- name: Test Service Provider
env:
AEXPY_SERVICE: "./scripts/services.py"
run: |
echo "def getService(): return ServiceProvider()" | aexpy -vvv -s - --version
aexpy -vvv --version
echo "def getService(): return ServiceProvider()" | aexpy -vvv -s - view --help
aexpy -vvv view --help
aexpy -vvv extract ./cache/distribution1.json.gz ./cache/api8.json.gz
aexpy -vvv extract ./cache/distribution2.json.gz ./cache/api9.json.gz
aexpy -vvv diff ./cache/api8.json.gz ./cache/api9.json.gz ./cache/diff3.json.gz
Expand Down Expand Up @@ -128,7 +129,7 @@ jobs:
mkdir -p ./cache
- name: Test Service Provider
run: |
echo "def getService(): return ServiceProvider()" | docker run -i aexpy/aexpy -vvv -s - --version
echo "def getService(): return ServiceProvider()" | docker run -i aexpy/aexpy -vvv -s - view --help
- name: Test Preprocess
run: |
docker run -v ${{ github.workspace }}/cache:/data -u root aexpy/aexpy -vvv preprocess -r -p generator-oj-problem@0.0.1 /data /data/distribution1.json
Expand Down
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ RUN python -m build /src --outdir /dist
FROM mambaorg/micromamba:latest

ARG MAMBA_DOCKERFILE_ACTIVATE=1
ENV PYTHONUTF8=1
ENV RUN_IN_CONTAINER=1
ENV AEXPY_ENV_PROVIDER=micromamba
ENV PYTHONUTF8=1 RUN_IN_CONTAINER=1 AEXPY_ENV_PROVIDER=micromamba

WORKDIR /app
WORKDIR /data
VOLUME [ "/data" ]

COPY --chown=$MAMBA_USER:$MAMBA_USER env.yaml /tmp/env.yaml
Expand Down
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,26 @@ echo "," | cat ./api1.json - ./api2.json | docker run -i aexpy/aexpy diff - - -
When you installed AexPy package, you could use `tool runimage` command for a quick runner of containers (if you have Docker installed).
> [!TIP]
> The volume directory will mount to `/data` in the container
>
> All file path arguments passed to container should use absolute paths with `/data` prefix or use a path relative to `/data`.
```sh
# Use the same version of the image as current AexPy version
aexpy tool runimage ./mount -- --version
aexpy runimage ./mount -- --version
# Use current as mount directory
aexpy tool runimage -- --version
aexpy runimage -- --version
# Extract from ./dist.json
aexpy runimage -- extract ./dist.json ./api.json
# Use a specified image tag and mount directory
aexpy tool runimage -v ./mount -t stardustdl/aexpy:latest -- --version
# Use a specified image tag
aexpy tool runimage ./mount -t stardustdl/aexpy:latest -- --version
# Extract from ./mount/dist.json
aexpy runimage -v ./mount -- extract ./dist.json ./api.json
aexpy runimage -v ./mount -- extract /data/dist.json /data/api.json
```
## Advanced Tools
Expand Down
2 changes: 1 addition & 1 deletion env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ dependencies:
- python=3.12
- click=8.1.7
- pydantic=2.6.3
- mypy=1.8.0
- mypy=1.9.0
2 changes: 1 addition & 1 deletion src/aexpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime
from functools import cache

__version__ = "0.4.2"
__version__ = "0.4.3"


LOGGING_FORMAT = "%(levelname)s %(asctime)s %(name)s [%(pathname)s:%(lineno)d:%(funcName)s]\n%(message)s\n"
Expand Down
18 changes: 13 additions & 5 deletions src/aexpy/tools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ def stat(ctx: click.Context, files: tuple[Path], output: IO[bytes]):

@tool.command()
@click.pass_context
@click.argument(
"volume",
@click.option(
"-v",
"--volume",
type=click.Path(
exists=True, dir_okay=True, file_okay=False, resolve_path=True, path_type=Path
),
default=Path("."),
)
@click.option(
"-t",
Expand All @@ -79,14 +81,20 @@ def stat(ctx: click.Context, files: tuple[Path], output: IO[bytes]):
"args",
nargs=-1,
)
def runimage(ctx: click.Context, volume: Path, args: tuple[str], tag: str = ""):
def runimage(ctx: click.Context, args: tuple[str], volume: Path=Path("."), tag: str = ""):
"""Quick runner to execute commands using AexPy images.
VOLUME describes the mount directory for containers.
VOLUME describes the mount directory for containers (to /data), default using current working directory.
All file path arguments passed to container should use absolute paths with `/data` prefix or use a path relative to `/data`.
Examples:
aexpy tool runimage ./mount -- --version
aexpy tool runimage -v ./mount -- --version
aexpy runimage -v ./mount -- extract ./dist.json ./api.json
aexpy runimage -v ./mount -- extract /data/dist.json /data/api.json
"""
clictx = ctx.ensure_object(CliContext)

Expand Down
12 changes: 11 additions & 1 deletion src/aexpy/tools/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,24 @@ def getImageTag(self, /, version: str):

@override
def getCommandPrefix(self, /):
user = "root"

# try:
# import pwd
# uid = os.getuid()
# gid = pwd.getpwuid(uid).pw_gid
# user = f"{uid}:{gid}"
# except Exception:
# pass

return [
"docker",
"run",
"-i",
"-v",
f"{str(self.cwd.resolve())}:/data",
"-u",
"root",
user,
"--rm",
self.tag,
] + (["--gzip"] if self.compress else [])
Expand Down

0 comments on commit 8b274ac

Please sign in to comment.