From 6da1d0d4013f08f7e1760b676c33283e5674c9bb Mon Sep 17 00:00:00 2001 From: Nick Cote Date: Wed, 26 Jun 2024 15:39:36 -0600 Subject: [PATCH 01/13] Add container information --- Containerfile | 27 --- _toc.yml | 6 +- notebooks/07_container_create.ipynb | 343 ++++++++++++++++++++++++++++ notebooks/Containerfile | 33 +++ 4 files changed, 381 insertions(+), 28 deletions(-) delete mode 100644 Containerfile create mode 100644 notebooks/07_container_create.ipynb create mode 100644 notebooks/Containerfile diff --git a/Containerfile b/Containerfile deleted file mode 100644 index 15375534..00000000 --- a/Containerfile +++ /dev/null @@ -1,27 +0,0 @@ -# Use an official Python runtime as a base image -FROM docker.io/mambaorg/micromamba:latest - -USER root - -RUN apt-get update && apt-get install -y git-all - -# Set the working directory in the container to /app -WORKDIR /home/mambauser/app - -# Copy the current directory contents into the container at /usr/src/app -RUN git clone https://github.com/NicholasCote/ERA5_interactive-cookbook-ncote.git - -# Install any needed packages specified in requirements.yml -RUN micromamba env create -f ERA5_interactive-cookbook-ncote/environment.yml - -RUN mv ERA5_interactive-cookbook-ncote/notebooks/04_dashboard.ipynb . - -RUN rm -r ERA5_interactive-cookbook-ncote/ - -# Activate the environment by providing ENV_NAME as an environment variable at runtime -# Make port bokeh application port to the world outside this container -EXPOSE 5006 - -USER mambauser - -CMD ["panel", "serve", "04_dashboard.ipynb", "--allow-websocket-origin=*", "--autoreload"] \ No newline at end of file diff --git a/_toc.yml b/_toc.yml index 226bb24c..a26a1fe4 100644 --- a/_toc.yml +++ b/_toc.yml @@ -14,4 +14,8 @@ parts: - caption: Preprocessing Notebooks for NCAR RDA chapters: - file: notebooks/05_data_preprocessing - - file: notebooks/06_era5_anomaly \ No newline at end of file + - file: notebooks/06_era5_anomaly + + - caption: Creating the Dashboard in a Container + chapters: + - file: notebooks/07_container_create \ No newline at end of file diff --git a/notebooks/07_container_create.ipynb b/notebooks/07_container_create.ipynb new file mode 100644 index 00000000..a7b68406 --- /dev/null +++ b/notebooks/07_container_create.ipynb @@ -0,0 +1,343 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Create a container image of the dashboard" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Containers package software and dependencies into a single image that can be run on any platform with a container engine installed. The image is portable and immutable, the software inside won't change. It will reliably run in the same state years from now making it powerful for easy reproducibility." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The most popular container engine is [Docker](https://www.docker.com/) and it will be used for this example. The principles learned can be applied to other container engines. Before proceeding make sure Docker is installed on the machine you are using. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A container engine is the core software that manages containers. It provides a user interface that can be used to create, run, and interact with containers while isolating the resources required " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Container image file" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A container image is a lightweight, standalone, and executable software package that includes everything needed to run a piece of software, such as the code, runtime, libraries, environment variables, and configuration files. A container image file, popularly referred to as a Dockerfile, is a set of instructions on how to build and run a container image. The filename can be anything and a flag can be specified at build time with the filename that should be used to create an image. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Container images are built in layers. Each layer corresponds to instructions provided in the container image file. They are built in sequence before being stacked together for the final image. Once a layer is created it cannot be changed. If a layer in the container image file is changed, on build, any layers that come before it are reused while new layers are built for the changed, and subsequent, layer. This is used to speed up builds and save storage space by sharing common layers between images. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Example Containerfile" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "There is a file in the notebooks directory named Containerfile that contains instructions to create a container image that hosts the interactive notebook as a web server. That file can be used directly to build a container image without having to change anything. The contents of that file can be viewed below with comments describing each command found inline. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "```docker\n", + "# Use the latest official micromamba image as the base image\n", + "FROM docker.io/mambaorg/micromamba:latest\n", + "\n", + "# Change to the root user in order to install OS packages\n", + "USER root\n", + "\n", + "# Update apt and install git\n", + "RUN apt-get update && apt-get install -y git-all\n", + "\n", + "# Set the working directory in the container to /home/mambauser/app\n", + "WORKDIR /home/mambauser/app\n", + "\n", + "# Run git clone to get the repo contents in to /home/mambauser/app\n", + "RUN git clone https://github.com/ProjectPythia/ERA5_interactive-cookbook.git\n", + "\n", + "# Create a conda environment from the environment.yml file included in the repo\n", + "RUN micromamba env create -f ERA5_interactive-cookbook/environment.yml\n", + "# Activate the environment by providing ENV_NAME as an environment variable at runtime \n", + "\n", + "# Copy the notebook with the panel application to the working directory\n", + "RUN mv ERA5_interactive-cookbook/notebooks/04_dashboard.ipynb .\n", + "\n", + "# Remove the rest of the repository as no other files are required \n", + "RUN rm -r ERA5_interactive-cookbook/\n", + "\n", + "# Make panel application port to the world outside this container\n", + "EXPOSE 5006\n", + "\n", + "# Set the user to be mambauser instead of root when the container runs\n", + "USER mambauser\n", + "\n", + "# Specify the command to run that starts the application\n", + "CMD [\"panel\", \"serve\", \"04_dashboard.ipynb\", \"--allow-websocket-origin=*\", \"--autoreload\"]\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Each line in the example starts with a command that creates an individual layer in the image. The layers can contain multiple lines and are typically linked with `&& \\` before starting the next line. Each layer is cached to increase subsequent builds. For instance if we wanted to change the last line to have a specific websocket origin instead of the wildcard the next build would only update that layer since it changed and is last. If we decided to add a package to the environment.yml file it would start building layers at the COPY command, and continue to rebuild all subsequent layers since they may be dependant on the change that was made to the middle layer. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Build the container image" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "With the container image build instructions in place a command can now be run to build it. The command below is an example of building an image in the ncote namespace (my Docker Hub namespace), with the name pythia-era5-viz. It is tagged with the default of `:latest` which does not provide great version control and will be updated later. When running this command the image tag, `-t`, should be updated to something that makes sense for you." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`docker buildx build -f Containerfile -t ncote/pythia-era5-viz .`" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Docker only recognizes container image files named `Dockerfile` by default so it's required to pass the container image file name `Containerfile` with the `-f` flag. It will take a few minutes for the image to build. When it is complete the output will look something like the following:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "```shell\n", + " => exporting to image\n", + " => => exporting layers\n", + " => => writing image sha256:76b3466afbc89f6f4043d9135d2e1c3a2ea6da0d79329b2b80635e7966ba9025\n", + " => => naming to docker.io/ncote/pythia-era5-viz \n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Run the container image" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now that the image has been built it can also be ran locally to test functionality. Because the environment name is not set inside the container it's required to pass the name of the conda environment to activate by using the following flag `-e ENV_NAME=ERA5_interactive`. The command below will run the container and make it accessible via a web browser:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`docker run -e ENV_NAME=ERA5_interactive -p 5006:5006 ncote/pythia-era5-viz`" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The site is now accessible at [http://localhost:5006/04_dashboard](http://localhost:5006/04_dashboard). " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Container registries" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A container registry is a centralized place where container images can be stored and distributed to others. There are a lot of different options when it comes to container registries. Docker Hub will be used in the following example but the concepts would apply directly to other container registries. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Docker Hub" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "[Docker Hub](https://hub.docker.com/) is a container registry provided by Docker that is the default registry for most container engines, including Podman. The link at the beginning of this section will navigate to the Docker Hub page where a new account can be created by using the Sign up button in the top right, or the Sign in button can be used if you already have an account." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Login" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Once the Docker Hub account is setup it can be used to login from the command line" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "```bash\n", + "docker login\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It will prompt for a username and password. Instead of using an actual password an Access Token can be created and supplied. At this [link to Docker Hub account settings](https://hub.docker.com/settings/security) a new access token can be created with only Read & Write access by selecting the New Access Token button. It will only be displayed one time and it should be stored somewhere secure." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Tag images" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Additional tags can be added to an image with the command `docker tag `. Since the image built before was tagged with latest it needs to be changed to something unique and more descriptive for version control. This can be done with a command like:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "```bash\n", + "docker tag docker.io/ncote/pythia-era5-viz:latest docker.io/ncote/pythia-era5-viz:2024-06-20\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "There is now an additional tag for the image called `docker.io/ncote/pythia-era5-viz:2024-06-20`. No new space was used to add this tag. It still references the same image ID from the original build. An image can be tagged multiple times with different names without using up more space." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Push images" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Once logged in to Docker Hub the ability to push images directly to the namespace specified is opened up. This is accomplished for the new image tag by running the following:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "```bash\n", + "docker push docker.io/ncote/pythia-era5-viz:2024-06-20\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It will take a bit to upload all the layers to the registry, but once complete the image is available for others to use by specifying the full image tag. In the example provided the full image tag is `docker.io/ncote/pythia-era5-viz:2024-06-20`" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Sharing the image" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now that the image has been pushed to a public container registry it's available for anyone to use. They can either run it directly with a command similar to what was run earlier:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`docker run -e ENV_NAME=ERA5_interactive -p 5006:5006 docker.io/ncote/pythia-era5-viz:2024-06-20`" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If the image does not exist on the local machine the run command will pull it directly. If it's preferred to pull the image down prior to running it that can also be accomplished by running:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`docker pull docker.io/ncote/pythia-era5-viz:2024-06-20`" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/notebooks/Containerfile b/notebooks/Containerfile new file mode 100644 index 00000000..423c4a2a --- /dev/null +++ b/notebooks/Containerfile @@ -0,0 +1,33 @@ +# Use the latest official micromamba image as the base image +FROM docker.io/mambaorg/micromamba:latest + +# Change to the root user in order to install OS packages +USER root + +# Update apt and install git +RUN apt-get update && apt-get install -y git-all + +# Set the working directory in the container to /home/mambauser/app +WORKDIR /home/mambauser/app + +# Run git clone to get the repo contents in to /home/mambauser/app +RUN git clone https://github.com/ProjectPythia/ERA5_interactive-cookbook.git + +# Create a conda environment from the environment.yml file included in the repo +RUN micromamba env create -f ERA5_interactive-cookbook/environment.yml +# Activate the environment by providing ENV_NAME as an environment variable at runtime + +# Copy the notebook with the panel application to the working directory +RUN mv ERA5_interactive-cookbook/notebooks/04_dashboard.ipynb . + +# Remove the rest of the repository as no other files are required +RUN rm -r ERA5_interactive-cookbook/ + +# Make panel application port to the world outside this container +EXPOSE 5006 + +# Set the user to be mambauser instead of root when the container runs +USER mambauser + +# Specify the command to run that starts the application +CMD ["panel", "serve", "04_dashboard.ipynb", "--allow-websocket-origin=*", "--autoreload"] \ No newline at end of file From 3ffbe1ccbf3090ee36c8a0047ee00ed9f1bd1be4 Mon Sep 17 00:00:00 2001 From: Nick Cote Date: Wed, 26 Jun 2024 16:23:26 -0600 Subject: [PATCH 02/13] Remove link to localhost site --- notebooks/07_container_create.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/07_container_create.ipynb b/notebooks/07_container_create.ipynb index a7b68406..fbe003bf 100644 --- a/notebooks/07_container_create.ipynb +++ b/notebooks/07_container_create.ipynb @@ -176,7 +176,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The site is now accessible at [http://localhost:5006/04_dashboard](http://localhost:5006/04_dashboard). " + "The site is now accessible at http://localhost:5006/04_dashboard. " ] }, { From d3a2f2cc8f9a98a5c2a5ecb94fb85dbeceaf0c2d Mon Sep 17 00:00:00 2001 From: Nick Cote Date: Wed, 26 Jun 2024 16:44:47 -0600 Subject: [PATCH 03/13] Updated toc caption to remove redundancy --- _toc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_toc.yml b/_toc.yml index a26a1fe4..7f38a6b9 100644 --- a/_toc.yml +++ b/_toc.yml @@ -16,6 +16,6 @@ parts: - file: notebooks/05_data_preprocessing - file: notebooks/06_era5_anomaly - - caption: Creating the Dashboard in a Container + - caption: Containerization chapters: - file: notebooks/07_container_create \ No newline at end of file From cf2f396d5e2ed882a2edb717aae4f8e35e3ae09e Mon Sep 17 00:00:00 2001 From: Nick Cote Date: Fri, 2 Aug 2024 11:00:10 -0600 Subject: [PATCH 04/13] Try to shink image --- notebooks/Containerfile | 2 +- notebooks/environment.yml | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 notebooks/environment.yml diff --git a/notebooks/Containerfile b/notebooks/Containerfile index 423c4a2a..8bc4590d 100644 --- a/notebooks/Containerfile +++ b/notebooks/Containerfile @@ -14,7 +14,7 @@ WORKDIR /home/mambauser/app RUN git clone https://github.com/ProjectPythia/ERA5_interactive-cookbook.git # Create a conda environment from the environment.yml file included in the repo -RUN micromamba env create -f ERA5_interactive-cookbook/environment.yml +RUN micromamba env create -f ERA5_interactive-cookbook/notebooks/environment.yml # Activate the environment by providing ENV_NAME as an environment variable at runtime # Copy the notebook with the panel application to the working directory diff --git a/notebooks/environment.yml b/notebooks/environment.yml new file mode 100644 index 00000000..001b6d97 --- /dev/null +++ b/notebooks/environment.yml @@ -0,0 +1,7 @@ +name: ERA5_interactive +channels: + - conda-forge +dependencies: + - xarray + - panel + - hvplot \ No newline at end of file From fa58b1b8cb5c625edc9d11a801fcf782902b13ab Mon Sep 17 00:00:00 2001 From: Nick Cote Date: Fri, 2 Aug 2024 12:50:18 -0600 Subject: [PATCH 05/13] update --- notebooks/Containerfile | 8 ++++---- notebooks/environment.yml | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/notebooks/Containerfile b/notebooks/Containerfile index 8bc4590d..59034145 100644 --- a/notebooks/Containerfile +++ b/notebooks/Containerfile @@ -11,17 +11,17 @@ RUN apt-get update && apt-get install -y git-all WORKDIR /home/mambauser/app # Run git clone to get the repo contents in to /home/mambauser/app -RUN git clone https://github.com/ProjectPythia/ERA5_interactive-cookbook.git +RUN git clone https://github.com/NicholasCote/ERA5_interactive-cookbook-ncote.git # Create a conda environment from the environment.yml file included in the repo -RUN micromamba env create -f ERA5_interactive-cookbook/notebooks/environment.yml +RUN micromamba env create -f ERA5_interactive-cookbook-ncote/notebooks/environment.yml # Activate the environment by providing ENV_NAME as an environment variable at runtime # Copy the notebook with the panel application to the working directory -RUN mv ERA5_interactive-cookbook/notebooks/04_dashboard.ipynb . +RUN mv ERA5_interactive-cookbook-ncote/notebooks/04_dashboard.ipynb . # Remove the rest of the repository as no other files are required -RUN rm -r ERA5_interactive-cookbook/ +RUN rm -r ERA5_interactive-cookbook-ncote/ # Make panel application port to the world outside this container EXPOSE 5006 diff --git a/notebooks/environment.yml b/notebooks/environment.yml index 001b6d97..d0b99f2d 100644 --- a/notebooks/environment.yml +++ b/notebooks/environment.yml @@ -4,4 +4,5 @@ channels: dependencies: - xarray - panel - - hvplot \ No newline at end of file + - hvplot + - nbconvert \ No newline at end of file From ef1fdaf2c210e3e475c16cf9d2993756f2a9ab41 Mon Sep 17 00:00:00 2001 From: Nick Cote Date: Fri, 2 Aug 2024 13:34:00 -0600 Subject: [PATCH 06/13] add zarr --- notebooks/environment.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/notebooks/environment.yml b/notebooks/environment.yml index d0b99f2d..eaeaa12c 100644 --- a/notebooks/environment.yml +++ b/notebooks/environment.yml @@ -5,4 +5,5 @@ dependencies: - xarray - panel - hvplot - - nbconvert \ No newline at end of file + - nbconvert + - zarr \ No newline at end of file From 140445687d1cd3e246770088a718a1ec3eac9aca Mon Sep 17 00:00:00 2001 From: Nick Cote Date: Fri, 2 Aug 2024 13:40:37 -0600 Subject: [PATCH 07/13] add fsspec --- notebooks/environment.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/notebooks/environment.yml b/notebooks/environment.yml index eaeaa12c..5df0b762 100644 --- a/notebooks/environment.yml +++ b/notebooks/environment.yml @@ -2,8 +2,9 @@ name: ERA5_interactive channels: - conda-forge dependencies: - - xarray - - panel + - fsspec - hvplot - nbconvert + - panel + - xarray - zarr \ No newline at end of file From f799cbcf495c98d9aead68d274ad15a98d878b36 Mon Sep 17 00:00:00 2001 From: Nick Cote Date: Fri, 2 Aug 2024 13:49:14 -0600 Subject: [PATCH 08/13] add aiohttp --- notebooks/environment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/notebooks/environment.yml b/notebooks/environment.yml index 5df0b762..c2c09869 100644 --- a/notebooks/environment.yml +++ b/notebooks/environment.yml @@ -2,6 +2,7 @@ name: ERA5_interactive channels: - conda-forge dependencies: + - aiohttp - fsspec - hvplot - nbconvert From 23addc570fe7452b80b3299eca4c0508766b5d25 Mon Sep 17 00:00:00 2001 From: Nick Cote Date: Fri, 2 Aug 2024 13:56:28 -0600 Subject: [PATCH 09/13] add datashader --- notebooks/environment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/notebooks/environment.yml b/notebooks/environment.yml index c2c09869..fc0e3a45 100644 --- a/notebooks/environment.yml +++ b/notebooks/environment.yml @@ -3,6 +3,7 @@ channels: - conda-forge dependencies: - aiohttp + - datashader - fsspec - hvplot - nbconvert From 62338612713b6f21ea8ed7e7222f59ea96f217f0 Mon Sep 17 00:00:00 2001 From: Nick Cote Date: Fri, 2 Aug 2024 14:38:14 -0600 Subject: [PATCH 10/13] dask --- notebooks/environment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/notebooks/environment.yml b/notebooks/environment.yml index fc0e3a45..cccf2d86 100644 --- a/notebooks/environment.yml +++ b/notebooks/environment.yml @@ -3,6 +3,7 @@ channels: - conda-forge dependencies: - aiohttp + - dask - datashader - fsspec - hvplot From 2f6858a97bf09991e735d6822f26155791ab7cc7 Mon Sep 17 00:00:00 2001 From: Nick Cote Date: Fri, 2 Aug 2024 15:09:10 -0600 Subject: [PATCH 11/13] add requirements file --- notebooks/Dockerfile | 27 +++++++++++++++++++++++++++ notebooks/requirements.txt | 8 ++++++++ 2 files changed, 35 insertions(+) create mode 100644 notebooks/Dockerfile create mode 100644 notebooks/requirements.txt diff --git a/notebooks/Dockerfile b/notebooks/Dockerfile new file mode 100644 index 00000000..bba231cf --- /dev/null +++ b/notebooks/Dockerfile @@ -0,0 +1,27 @@ +# Use the latest official micromamba image as the base image +FROM python:slim + +# Update apt and install git +RUN apt-get update && apt-get install -y git-all + +# Set the working directory in the container to /home/mambauser/app +WORKDIR /home/mambauser/app + +# Run git clone to get the repo contents in to /home/mambauser/app +RUN git clone https://github.com/NicholasCote/ERA5_interactive-cookbook-ncote.git + +# Create a conda environment from the environment.yml file included in the repo +RUN pip install -r ERA5_interactive-cookbook-ncote/notebooks/requirements.txt +# Activate the environment by providing ENV_NAME as an environment variable at runtime + +# Copy the notebook with the panel application to the working directory +RUN mv ERA5_interactive-cookbook-ncote/notebooks/04_dashboard.ipynb . + +# Remove the rest of the repository as no other files are required +RUN rm -r ERA5_interactive-cookbook-ncote/ + +# Make panel application port to the world outside this container +EXPOSE 5006 + +# Specify the command to run that starts the application +CMD ["panel", "serve", "04_dashboard.ipynb", "--allow-websocket-origin=*", "--autoreload"] \ No newline at end of file diff --git a/notebooks/requirements.txt b/notebooks/requirements.txt new file mode 100644 index 00000000..8c31d325 --- /dev/null +++ b/notebooks/requirements.txt @@ -0,0 +1,8 @@ +dask +datashader +fsspec +hvplot +nbconvert +panel +xarray +zarr \ No newline at end of file From 0f9bcbe405b856c3f99a85d0e28c4200db5b3e43 Mon Sep 17 00:00:00 2001 From: Nick Cote Date: Fri, 2 Aug 2024 15:18:31 -0600 Subject: [PATCH 12/13] aiohttp --- notebooks/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/notebooks/requirements.txt b/notebooks/requirements.txt index 8c31d325..3031b83b 100644 --- a/notebooks/requirements.txt +++ b/notebooks/requirements.txt @@ -1,3 +1,4 @@ +aiohttp dask datashader fsspec From afa663aaeccb4cae85aa5bf728b323db14f857e8 Mon Sep 17 00:00:00 2001 From: Nick Cote Date: Fri, 2 Aug 2024 16:25:19 -0600 Subject: [PATCH 13/13] Slim down image size for workshop --- notebooks/Containerfile | 15 ++++----------- notebooks/Dockerfile | 27 --------------------------- notebooks/environment.yml | 13 ------------- 3 files changed, 4 insertions(+), 51 deletions(-) delete mode 100644 notebooks/Dockerfile delete mode 100644 notebooks/environment.yml diff --git a/notebooks/Containerfile b/notebooks/Containerfile index 59034145..4b102fb2 100644 --- a/notebooks/Containerfile +++ b/notebooks/Containerfile @@ -1,21 +1,17 @@ # Use the latest official micromamba image as the base image -FROM docker.io/mambaorg/micromamba:latest - -# Change to the root user in order to install OS packages -USER root +FROM python:slim # Update apt and install git RUN apt-get update && apt-get install -y git-all # Set the working directory in the container to /home/mambauser/app -WORKDIR /home/mambauser/app +WORKDIR /home/python/app # Run git clone to get the repo contents in to /home/mambauser/app RUN git clone https://github.com/NicholasCote/ERA5_interactive-cookbook-ncote.git # Create a conda environment from the environment.yml file included in the repo -RUN micromamba env create -f ERA5_interactive-cookbook-ncote/notebooks/environment.yml -# Activate the environment by providing ENV_NAME as an environment variable at runtime +RUN pip install -r ERA5_interactive-cookbook-ncote/notebooks/requirements.txt # Copy the notebook with the panel application to the working directory RUN mv ERA5_interactive-cookbook-ncote/notebooks/04_dashboard.ipynb . @@ -26,8 +22,5 @@ RUN rm -r ERA5_interactive-cookbook-ncote/ # Make panel application port to the world outside this container EXPOSE 5006 -# Set the user to be mambauser instead of root when the container runs -USER mambauser - # Specify the command to run that starts the application -CMD ["panel", "serve", "04_dashboard.ipynb", "--allow-websocket-origin=*", "--autoreload"] \ No newline at end of file +CMD ["panel", "serve", "04_dashboard.ipynb", "--allow-websocket-origin=*"] \ No newline at end of file diff --git a/notebooks/Dockerfile b/notebooks/Dockerfile deleted file mode 100644 index bba231cf..00000000 --- a/notebooks/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -# Use the latest official micromamba image as the base image -FROM python:slim - -# Update apt and install git -RUN apt-get update && apt-get install -y git-all - -# Set the working directory in the container to /home/mambauser/app -WORKDIR /home/mambauser/app - -# Run git clone to get the repo contents in to /home/mambauser/app -RUN git clone https://github.com/NicholasCote/ERA5_interactive-cookbook-ncote.git - -# Create a conda environment from the environment.yml file included in the repo -RUN pip install -r ERA5_interactive-cookbook-ncote/notebooks/requirements.txt -# Activate the environment by providing ENV_NAME as an environment variable at runtime - -# Copy the notebook with the panel application to the working directory -RUN mv ERA5_interactive-cookbook-ncote/notebooks/04_dashboard.ipynb . - -# Remove the rest of the repository as no other files are required -RUN rm -r ERA5_interactive-cookbook-ncote/ - -# Make panel application port to the world outside this container -EXPOSE 5006 - -# Specify the command to run that starts the application -CMD ["panel", "serve", "04_dashboard.ipynb", "--allow-websocket-origin=*", "--autoreload"] \ No newline at end of file diff --git a/notebooks/environment.yml b/notebooks/environment.yml deleted file mode 100644 index cccf2d86..00000000 --- a/notebooks/environment.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: ERA5_interactive -channels: - - conda-forge -dependencies: - - aiohttp - - dask - - datashader - - fsspec - - hvplot - - nbconvert - - panel - - xarray - - zarr \ No newline at end of file