1
"""Build and optinally push the launch agent image."""
5
from wandb.docker import build, push
7
DOCKERFILE_TEMPLATE = """
8
FROM python:3.9-bullseye
9
LABEL maintainer='Weights & Biases <support@wandb.com>'
12
RUN apt-get update && apt-get upgrade -y \
13
&& apt-get install -y git \
14
&& apt-get -qy autoremove \
15
&& apt-get clean && rm -r /var/lib/apt/lists/*
17
# copy reqs and install for docker cache
18
COPY ../requirements.txt /src/requirements.txt
19
RUN pip install --no-cache-dir -r /src/requirements.txt
20
RUN pip install awscli nbconvert nbformat chardet iso8601 typing_extensions boto3 botocore google-auth google-cloud-compute google-cloud-storage google-cloud-artifact-registry kubernetes
23
# Copy source code and install
25
RUN pip install --no-cache-dir "/src[launch]"
28
RUN useradd -m -s /bin/bash --create-home --no-log-init -u 1000 -g 0 launch_agent
30
WORKDIR /home/launch_agent
31
RUN chown -R launch_agent /home/launch_agent
35
ENTRYPOINT ["wandb", "launch-agent"]
39
# set agent version env var
40
ENV WANDB_AGENT_VERSION={agent_version}
49
"""Parse command line arguments."""
50
parser = argparse.ArgumentParser()
54
help="Push image after creation. This requires that you enter a tag that includes a registry via --tag",
56
parser.add_argument("--tag", default="wandb-launch-agent", help="Tag for the image")
58
"--platform", default="linux/amd64", help="Platform to use, e.g. 'linux/amd64'"
60
return parser.parse_args()
64
"""Build the launch agent image."""
66
build_context = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
67
dockerfile_path = os.path.join(build_context, "Dockerfile")
68
dockerignore_path = os.path.join(build_context, ".dockerignore")
69
# Set the version env var if a custom tag is set
71
if args.tag != "wandb-launch-agent":
72
version_section = VERSION_SECTION.format(agent_version=args.tag)
73
dockerfile_contents = DOCKERFILE_TEMPLATE.format(version_section=version_section)
74
with open(dockerfile_path, "w") as f:
75
f.write(dockerfile_contents)
76
with open(dockerignore_path, "w") as f:
81
context_path=build_context,
82
platform=args.platform,
85
image, tag = args.tag.split(":")
88
# Remove the dockerfui
89
os.remove(dockerfile_path)
90
os.remove(dockerignore_path)
93
if __name__ == "__main__":