|
| 1 | +# Building the GeoLab "slim" image |
| 2 | + |
| 3 | +The GeoLab slim image is a base image containing minimal software for working in the platform. |
| 4 | + |
| 5 | +GeoLab environments run as **containers** based on **images** — self-contained packages that include an operating system, software libraries, and Python packages together. This guide documents the steps using Docker to create the geolab-slim image. |
| 6 | + |
| 7 | +GeoLab images use the `pangeo/base-notebook` image as the starting point. This base image contains the fundamentals needed for an environment in JupyterHub. You customize it by editing four files before building: |
| 8 | + |
| 9 | +| File | What it controls | |
| 10 | +| :--- | :--------------- | |
| 11 | +| `apt.txt` | System-level software (installed via `apt`) | |
| 12 | +| `environment.yml` | Conda packages and channels | |
| 13 | +| `requirements.txt` | Python packages from PyPI (installed via `pip`) | |
| 14 | +| `start` | The command that launches when the container starts | |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## Installing System Software with apt |
| 19 | + |
| 20 | +`apt` is the Ubuntu package manager — it installs system-level tools like compilers, runtime libraries, and command-line utilities. Add any packages you need, one per line, to `apt.txt`. |
| 21 | + |
| 22 | +> **Tip:** Only add packages here that aren't available through conda. Most scientific Python libraries are better managed in `environment.yml`. |
| 23 | +
|
| 24 | +--- |
| 25 | + |
| 26 | +## Installing Conda Packages |
| 27 | + |
| 28 | +Conda manages Python (and non-Python) packages within isolated environments. Edit `environment.yml` to add packages by name under the appropriate section. Always use the `conda-forge` channel for the broadest package availability. |
| 29 | + |
| 30 | +> **Tip:** Prefer conda packages over pip when a package is available in both. Conda resolves environment-wide dependencies more reliably. |
| 31 | +
|
| 32 | +--- |
| 33 | + |
| 34 | +## Installing pip Packages |
| 35 | + |
| 36 | +Some packages are only available on PyPI (Python's package index) and must be installed with `pip`. Add them to `requirements.txt`, one per line. You can pin a specific version with `==` to ensure reproducibility. |
| 37 | + |
| 38 | +> **Tip:** Pin versions for packages critical to your workflow (e.g., `earthscope-sdk==1.4.1`). This prevents silent breakage when upstream packages release updates. |
| 39 | +
|
| 40 | +--- |
| 41 | + |
| 42 | +## Start Script |
| 43 | + |
| 44 | +`start` runs when a user launches a container. Its job is to start the main process — typically JupyterLab. |
| 45 | +For this image the contents simply executes the command provided by the Hub. |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## Building and Pushing the Image |
| 50 | + |
| 51 | +Once your configuration files are ready, you build the image locally and push it to a container registry so GeoLab can access it. |
| 52 | + |
| 53 | +**Step 1 — Build the image** |
| 54 | + |
| 55 | +The `--platform linux/amd64` flag ensures the image runs on standard cloud hardware regardless of whether you're building on an Apple Silicon or an Intel machine. `Dockerfile` is the GeoLab-specific Dockerfile that wires together your four config files. |
| 56 | + |
| 57 | +```bash |
| 58 | +docker build --no-cache -f Dockerfile \ |
| 59 | + --platform linux/amd64 \ |
| 60 | + -t username/geolab-slim:latest-amd64 . |
| 61 | +``` |
| 62 | + |
| 63 | +Replace `username` with your Docker Hub username (or your registry path) and `latest-amd64` with your version tag of choice. |
| 64 | + |
| 65 | +> **What does `--no-cache` do?** It forces Docker to re-run every build step from scratch, ensuring your latest `apt.txt`, `environment.yml`, and `requirements.txt` changes are picked up rather than reused from a previous build. |
| 66 | +
|
| 67 | +**Step 2 — Push to a registry** |
| 68 | + |
| 69 | +Push the finished image to Docker Hub, AWS ECR, or another registry so GeoLab can pull it: |
| 70 | + |
| 71 | +```bash |
| 72 | +docker push username/geolab-slim:latest-amd64 |
| 73 | +``` |
| 74 | + |
| 75 | +> **First time?** You'll need to log in first with `docker login` (Docker Hub) or the appropriate CLI for your registry. |
| 76 | +
|
| 77 | +--- |
| 78 | + |
| 79 | +## Running Your Image in GeoLab |
| 80 | + |
| 81 | +1. Open GeoLab. |
| 82 | +2. Choose **Environment → Other**. |
| 83 | + |
| 84 | +  |
| 85 | + |
| 86 | +3. Enter the full image name from your registry, e.g.: |
| 87 | + ``` |
| 88 | + username/geolab-slim:latest-amd64 |
| 89 | + ``` |
| 90 | + |
| 91 | +  |
| 92 | + |
| 93 | +4. Select **Start**. |
| 94 | + |
| 95 | +GeoLab will pull and launch your custom environment. The first launch may take a minute while the image downloads. |
| 96 | + |
| 97 | +## Final steps |
| 98 | + |
| 99 | +If the image works as desired create a PR against the `main` branch for review by the ownership team. |
| 100 | +Once accepted the production image will be built and deployed automatically in the EarthScope AWS container registry. |
| 101 | + |
| 102 | +## Local build and test |
| 103 | + |
| 104 | +An image built for your machine can be created using: |
| 105 | + |
| 106 | +```bash |
| 107 | +docker build --no-cache -f Dockerfile -t geolab-slim:test . |
| 108 | +``` |
| 109 | + |
| 110 | +> **Not for GeoLab!** Without the guarantee of `--platform linux/amd64` this image is not for GeoLab |
| 111 | +
|
| 112 | +Run a container using this image with: |
| 113 | + |
| 114 | +```bash |
| 115 | +docker run --rm -p 8888:8888 geolab-slim:test |
| 116 | +``` |
| 117 | + |
| 118 | +Then use a web browser to connect to: `http://127.0.0.1:8888/lab`, |
| 119 | +open `smoke_tests.ipynb` and run all cells. |
0 commit comments