diff --git a/Dockerfile.arm b/Dockerfile.arm index 65476b23..e039faa7 100644 --- a/Dockerfile.arm +++ b/Dockerfile.arm @@ -1,20 +1,29 @@ -FROM --platform=linux/arm64 python:3.10-slim +# This applies to mchip on arm64 +FROM python:3.10-slim RUN apt-get update && apt-get install -y \ build-essential \ git \ curl \ ca-certificates \ + libxrender1 \ + libxext6 \ + libsm6 \ && rm -rf /var/lib/apt/lists/* RUN pip install --no-cache-dir uv WORKDIR /app -COPY pyproject.toml . -COPY VERSION . +COPY pyproject.toml VERSION README.md LICENSE build.sh install.sh ./ +COPY uv.lock.mchip ./uv.lock COPY atomsci ./atomsci -RUN uv sync --extra mchip --group docker --no-dev +RUN uv sync --frozen --extra mchip --group docker --group dev +ENV PATH="/app/.venv/bin:$PATH" -CMD ["uv", "run", "python", "-c", "import atomsci; print('arm64/mchip-style ok')"] +# Install atomsci-ampl +RUN ./build.sh +RUN ./install.sh + +CMD ["uv", "run", "python", "-c", "import atomsci.ddm; print('arm64/mchip-style ok')"] diff --git a/Dockerfile.cpu b/Dockerfile.cpu index 100ee8e3..7d265677 100644 --- a/Dockerfile.cpu +++ b/Dockerfile.cpu @@ -1,12 +1,28 @@ FROM python:3.10-slim -RUN pip install uv +RUN apt-get update && apt-get install -y \ + build-essential \ + git \ + curl \ + ca-certificates \ + libxrender1 \ + libxext6 \ + libsm6 \ + && rm -rf /var/lib/apt/lists/* + +RUN pip install --no-cache-dir uv + WORKDIR /app -COPY pyproject.toml . +COPY pyproject.toml VERSION README.md LICENSE build.sh install.sh ./ +COPY uv.lock.cpu ./uv.lock COPY atomsci ./atomsci -COPY VERSION . -RUN uv sync --extra cpu +RUN uv sync --frozen --extra cpu --group docker --group dev +ENV PATH="/app/.venv/bin:$PATH" + +# Install atomsci-ampl +RUN ./build.sh +RUN ./install.sh -CMD ["uv", "run", "python", "-c", "import atomsci; print('cpu ok')"] +CMD ["uv", "run", "python", "-c", "import atomsci.ddm; print('cpu ok')"] diff --git a/Dockerfile.gpu b/Dockerfile.gpu index 88ed0553..3cae9d1b 100644 --- a/Dockerfile.gpu +++ b/Dockerfile.gpu @@ -1,13 +1,31 @@ FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04 -RUN apt-get update && apt-get install -y python3.10 python3-pip -RUN python3.10 -m pip install uv +RUN apt-get update && apt-get install -y \ + python3.10 \ + python3-pip \ + python3.10-venv \ + build-essential \ + git \ + curl \ + ca-certificates \ + libxrender1 \ + libxext6 \ + libsm6 \ + && rm -rf /var/lib/apt/lists/* + +RUN python3.10 -m pip install --no-cache-dir uv WORKDIR /app -COPY pyproject.toml . + +COPY pyproject.toml VERSION README.md LICENSE build.sh install.sh ./ +COPY uv.lock.cuda ./uv.lock COPY atomsci ./atomsci -COPY VERSION . -RUN uv sync --extra cuda +RUN uv sync --frozen --extra cuda --group docker --group dev +ENV PATH="/app/.venv/bin:$PATH" + +# Install atomsci-ampl +RUN ./build.sh +RUN ./install.sh -CMD ["uv", "run", "python3.10", "-c", "import atomsci; print('cuda ok')"] +CMD ["uv", "run", "python", "-c", "import atomsci.ddm; print('cuda ok')"] diff --git a/Dockerfile.rocm b/Dockerfile.rocm index c75e3f71..54e9b259 100644 --- a/Dockerfile.rocm +++ b/Dockerfile.rocm @@ -7,16 +7,25 @@ RUN apt-get update && apt-get install -y \ build-essential \ git \ curl \ - ca-certificates + ca-certificates \ + libxrender1 \ + libxext6 \ + libsm6 \ + && rm -rf /var/lib/apt/lists/* RUN python3.10 -m pip install --no-cache-dir uv WORKDIR /app -COPY pyproject.toml . -COPY VERSION . +COPY pyproject.toml VERSION README.md LICENSE build.sh install.sh ./ +COPY uv.lock.rocm ./uv.lock COPY atomsci ./atomsci -RUN uv sync --extra rocm --group docker --no-dev +RUN uv sync --frozen --extra rocm --group docker --group dev +ENV PATH="/app/.venv/bin:$PATH" -CMD ["uv", "run", "python3.10", "-c", "import atomsci; print('rocm ok')"] +# Install atomsci-ampl +RUN ./build.sh +RUN ./install.sh + +CMD ["uv", "run", "python", "-c", "import atomsci.ddm; print('rocm ok')"] \ No newline at end of file diff --git a/Makefile b/Makefile index 71be804a..e2bc1c95 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ VERSION=$(shell cat VERSION) ifeq ($(ENV), prod) TAG = v$(VERSION)-$(SUBTAG) else - TAG = $(ENV)-$(PLATFORM) + TAG = $(ENV)-$(SUBTAG) endif # IMAGE REPOSITORY @@ -58,9 +58,24 @@ load-docker: pull-docker: docker pull $(IMAGE_REPO):$(TAG) -# Push Docker image +# Push Docker image. +# if cpu, also set those as default tags. like atomsci/atomsci-ampl:vx.x.x, atomsci/atomsci-ampl:latest push-docker: - docker buildx build --no-cache -t $(IMAGE_REPO):$(TAG) -t $(IMAGE_REPO):latest-$(SUBTAG) --build-arg ENV=$(ENV) $(PLATFORM_ARG) --push -f Dockerfile.$(PLATFORM) . +ifeq ($(PLATFORM),cpu) + docker buildx build --no-cache \ + -t $(IMAGE_REPO):$(TAG) \ + -t $(IMAGE_REPO):v$(VERSION) \ + -t $(IMAGE_REPO):latest \ + -t $(IMAGE_REPO):latest-$(SUBTAG) \ + --build-arg ENV=$(ENV) $(PLATFORM_ARG) --push \ + -f Dockerfile.$(PLATFORM) . +else + docker buildx build --no-cache \ + -t $(IMAGE_REPO):$(TAG) \ + -t $(IMAGE_REPO):latest-$(SUBTAG) \ + --build-arg ENV=$(ENV) $(PLATFORM_ARG) --push \ + -f Dockerfile.$(PLATFORM) . +endif # Save Docker image save-docker: @@ -182,4 +197,4 @@ sync-rocm: ./sync_uv_env.sh rocm sync-mchip: - ./sync_uv_env.sh mchip \ No newline at end of file + ./sync_uv_env.sh mchip diff --git a/Makefile.md b/Makefile.md index 6050d4cf..0f138355 100644 --- a/Makefile.md +++ b/Makefile.md @@ -39,6 +39,24 @@ This Makefile is designed to manage Jupyter environments, Docker images, and the - `make save-docker`: Save the Docker image to a tarball (`ampl-$(PLATFORM)-$(ENV).tar.gz`). - `make build-docker`: Build the Docker image for the specified platform and environment. +***Note:*** + +Usage for docker build: + +``` +make build-docker PLATFORM= ARCH= ENV= +``` + +Examples: + +``` +make build-docker PLATFORM=cpu ARCH=linux/amd64 ENV=prod +make build-docker PLATFORM=gpu ARCH=linux/amd64 ENV=prod +make build-docker PLATFORM=rocm ARCH=linux/amd64 ENV=prod +make build-docker PLATFORM=rocm ARCH=linux/amd64 ENV=prod +make build-docker PLATFORM=cpu ARCH=linux/arm64 ENV=prod +``` + - **Jupyter Notebook and Lab:** - `make jupyter-notebook`: Start a Jupyter Notebook server. diff --git a/README.md b/README.md index 859e9770..2f435e94 100644 --- a/README.md +++ b/README.md @@ -293,6 +293,10 @@ python -m ipykernel install --user --name atomsci-env - Create a workspace folder to mount with Docker environment and transfer files. - Get the Docker image and run it. Since 1.6.3, there are some changes with the AMPL Docker. +The AMPL Docker image is available on Docker Hub: + +[https://hub.docker.com/r/atomsci/atomsci-ampl](https://hub.docker.com/r/atomsci/atomsci-ampl) + To retrieve, run version 1.6.2 or earlier, please specify the desired version tag: ``` docker pull atomsci/atomsci-ampl:v1.6.2 diff --git a/atomsci/ddm/docs/source/get_started/install_with_docker.rst b/atomsci/ddm/docs/source/get_started/install_with_docker.rst index 7d7bdcef..7d5e167f 100644 --- a/atomsci/ddm/docs/source/get_started/install_with_docker.rst +++ b/atomsci/ddm/docs/source/get_started/install_with_docker.rst @@ -6,7 +6,7 @@ This page provides an option to use Docker to install `AMPL `_ software using Docker, the major steps are: -* :ref:`Create Docker` +* :ref:`Create or download a Docker` * :ref:`Start container` * :ref:`Start Jupyter notebook` @@ -29,7 +29,7 @@ You can either pull a prebuilt `AMPL `_ Option 1: Pull a Prebuilt AMPL Image from Docker Repo ===================================================== -The simplest method is to download a prebuilt Docker image from DockerHub. For every official `AMPL `_ release, a docker image will be pushed to its `Docker Hub `_. +The simplest method is to download a prebuilt Docker image from DockerHub. For every official `AMPL `_ release, a docker image will be pushed to its `Docker Hub `_. To pull a prebuilt `AMPL `_ image, the method varies based on its version. @@ -39,11 +39,11 @@ For a pre-1.6.3 release: docker pull atomsci/atomsci-ampl:v1.6.2 # Specify a version to pull, ie, v1.6.2. -For 1.6.3 and later, you can download the latest images for various platforms (CPU, GPU, or Linux/ARM64), an example: +For 1.6.3 and later, you can download the latest images for various platforms (CPU, GPU, or Linux/ARM64), an example: .. code-block:: - docker pull atomsci/atomsci-ampl:latest-cpu # Specify the latest image built for a platform (use those for tags 'cpu', 'gpu', or 'arm') + docker pull atomsci/atomsci-ampl:latest-cpu # Specify the latest image built for a platform (use those for tags 'cpu', 'gpu', or 'arm') After that, please follow the instruction from the ":ref:`Start container`" step. @@ -60,7 +60,7 @@ First clone `AMPL `_ github repo, then .. code-block:: - git clone https://github.com/ATOMScience-org/AMPL.git + git clone https://github.com/ATOMScience-org/AMPL.git ### The following line is _optional_. If you want to check out a development branch instead of the default branch (master). git checkout 1.6.3 # (optional) checkout a dev branch, 1.6.3 for example cd AMPL @@ -82,7 +82,7 @@ This normally takes about 15-20 minutes to build. Once it's built on your machin Run a Docker Container ********************** -To see what images are running on your machine, type "docker images". +To see what images are running on your machine, type "docker images". .. image:: ../_static/img/install_with_docker_files/docker_run.png @@ -93,13 +93,13 @@ Use "docker run ... ``" command to start the container. The command synta docker run -it -p : -v : bash -Use the following example to start the container. For images created or downloaded from version 1.6.3 or later, append 'bash' to the end of the docker run command to open a bash session. By default, the container starts with a Python interpreter session. +Use the following example to start the container. For images created or downloaded from version 1.6.3 or later, append 'bash' to the end of the docker run command to open a bash session. By default, the container starts with a Python interpreter session. .. code-block:: docker run -it -p 8888:8888 -v ${PWD}:/home atomsci/atomsci-ampl:latest-cpu bash # replace with your : -To get more info for the "docker run" command options, type "docker run --help": +To get more info for the "docker run" command options, type "docker run --help": .. code-block:: @@ -135,10 +135,10 @@ Copy and paste the URL from the output message (highlighted in yellow from above .. note:: *If this doesn't work, exit the container and choose a different port - such as "7777" or "8899" (in all 3 places it's - written), then rerun both commands in "Start a Docker container" and - "Start the Jupyter notebook from a container". - Be sure to save any work in your container. See instructions on how to "Save work from Docker Jupyter".* + such as "7777" or "8899" (in all 3 places it's + written), then rerun both commands in "Start a Docker container" and + "Start the Jupyter notebook from a container". + Be sure to save any work in your container. See instructions on how to "Save work from Docker Jupyter".* Once connected, you will see a screen like this: diff --git a/pyproject.toml b/pyproject.toml index fdf570bf..eb5d42db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -117,6 +117,7 @@ pattern = "(?P\\d+\\.\\d+\\.\\d+.*)" [tool.hatch.build.targets.wheel] packages = ["atomsci"] exclude = [ + "uv.lock*", "atomsci/ddm/examples/archive/**", # old tutorials "atomsci/ddm/test/test_datasets/**", # test datasets "**/*.tar.gz", @@ -126,6 +127,7 @@ exclude = [ [tool.hatch.build.targets.sdist] exclude = [ + "uv.lock*", "atomsci/ddm/examples/archive/**", # old tutorials "atomsci/ddm/test/test_datasets/**", # test datasets "**/*.tar.gz",