Skip to content

Commit 86eef52

Browse files
committed
Added Dockerfile commands to build casatools container, locally and via GitHub Actions.
1 parent 48a4188 commit 86eef52

8 files changed

Lines changed: 167 additions & 7 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
tags: [ 'v*.*.*' ]
7+
pull_request:
8+
branches: [ "main" ]
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
# Dynamically set the image name to lowercase 'ghcr.io/MPoL-dev/examples'
13+
IMAGE_NAME: ${{ github.repository }}
14+
15+
jobs:
16+
build-and-push:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
# Sets up QEMU for multi-platform support (e.g., amd64, arm64)
27+
- name: Set up QEMU
28+
uses: docker/setup-qemu-action@v3
29+
30+
# Sets up Docker Buildx (required for multi-arch builds and advanced caching)
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
# Log in to GitHub Container Registry
35+
- name: Log in to the Container Registry
36+
if: github.event_name != 'pull_request'
37+
uses: docker/login-action@v3
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
# Extract metadata (tags, labels) for Docker
44+
- name: Extract Docker metadata
45+
id: meta
46+
uses: docker/metadata-action@v5
47+
with:
48+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
49+
tags: |
50+
type=ref,event=branch
51+
type=semver,pattern={{version}}
52+
type=sha,format=short
53+
54+
# Build and push Docker image
55+
- name: Build and push Docker image
56+
uses: docker/build-push-action@v6
57+
with:
58+
context: ./casatools-env
59+
file: ./Dockerfile
60+
push: ${{ github.event_name != 'pull_request' }}
61+
tags: ${{ id.meta.outputs.tags }}
62+
labels: ${{ id.meta.outputs.labels }}
63+
# Specifying platforms ensures optimization across target architectures
64+
platforms: linux/amd64,linux/arm64
65+
# Utilizing GitHub Actions native caching dramatically speeds up subsequent builds
66+
cache-from: type=gha
67+
cache-to: type=gha,mode=max
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Download and extract datasets
22

3-
Contend with the fact that `casatools` frequently lags supported SPEC 0 Python versions, creating a situation where one needs a Python version old enough to run `casatools` but new enough to support modern development. These requirements are often mutually exclusive and require multiple Python versions as part of the same analysis.
4-
5-
We've tried to decouple these somewhat, by isolating the `casatools` dependency to this specific example folder.
6-
73
# Installation and running
84

9-
As of 21 May 2026, the latest version supported by `casatools` is Python 3.10.
5+
In this 'example,' one merely downloads and extracts the ALMA datasets to a common data format like `.npz` or `.asdf`. This step requires the `casatools` package, which frequently has restrictions on Python versions and installation environments.
6+
7+
To simplify this step for users of the tutorials, one can use our Docker container via
8+
```
9+
./run.sh
10+
```
1011

11-
You can run to download individual datasets, or all of them at once.
12+
Depending on the speed of your internet connection, it may take some time to download the several Gb measurement sets from the archive servers.
1213

14+
Upon successful completion, you should see the following items in your directory:
1315

14-
For subsequent examples, you will be asked to copy some of the data products into those folders.
16+
Alternatively, if one already has their own Python environment compatible casatools, one can install the [relevant packages](../casatools-env/requirements.txt) into that environment.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
docker run --rm --platform linux/amd64 \
4+
-v "$(pwd)":/workspace \
5+
casatools-env \
6+
snakemake -c1 all

casatools-env/Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# casatools-env/Dockerfile
2+
# need to force the platform here so that casatools is available for the right
3+
# architecture. Doesn't work with Apple Silicon.
4+
FROM --platform=linux/amd64 ubuntu:24.04
5+
6+
ENV DEBIAN_FRONTEND=noninteractive
7+
8+
# Install core system dependencies
9+
RUN apt-get update && apt-get install -y \
10+
python3.12 \
11+
python3.12-dev \
12+
python3.12-venv \
13+
python3-pip-whl \
14+
gfortran \
15+
libgomp1 \
16+
wget \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
WORKDIR /workspace
20+
21+
RUN python3.12 -m venv /opt/casa_venv
22+
23+
# Add the virtual environment binaries to the container path
24+
# This automatically "activates" the venv
25+
ENV PATH="/opt/casa_venv/bin:$PATH"
26+
27+
# Upgrade pip inside the virtual environment
28+
RUN pip install --no-cache-dir --upgrade pip setuptools wheel
29+
30+
# Copy and install requirements
31+
COPY requirements.txt /workspace/requirements.txt
32+
RUN pip install --no-cache-dir -r requirements.txt
33+
34+
# create casa data directory
35+
# https://casadocs.readthedocs.io/en/stable/notebooks/external-data.html
36+
RUN mkdir -p /root/.casa/data
37+
38+
COPY casasiteconfig.py /workspace/casasiteconfig.py
39+
ENV CASASITECONFIG="/workspace/casasiteconfig.py"
40+
41+
# Trigger the initial measures data download inside the container build,
42+
# so that this isn't redone each time the user runs the container
43+
# https://casadocs.readthedocs.io/en/stable/api/casaconfig.html#casasiteconfig-py
44+
RUN python3 -c "from casaconfig import pull_data; pull_data('/root/.casa/data')"

casatools-env/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Docker image with casatools
2+
3+
This folder contains the instructions and Dockerfile for how to build a Docker container that will run `casatools`, necessary for the `00-download-and-extract-datasets` example. In the normal course of events, this container is built automatically as part of the GitHub Actions workflow, and you can download it from the GitHub Container Registry following the instructions in the [00 example](../00-download-and-extract-datasets/README.md).
4+
5+
The following instructions are aimed at developers of the examples. It is assumed that you have already installed a [Docker environment](https://www.docker.com/), e.g., such as Docker Desktop.
6+
7+
Building the container locally, from within this directory, and tag as `casatools-env`
8+
```
9+
docker build --platform linux/amd64 -t casatools-env .
10+
```
11+
Note that the `--platform linux/amd64` is necessary to accommodate the modular casa packages, which to my understanding are not built for Apple Silicon architecture.
12+
13+
Run the container and enter a bash shell
14+
```
15+
docker run --rm -it --platform linux/amd64 casatools-env
16+
```

casatools-env/build_locally.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
# note: it is not required to run this script to build the container,
4+
# it should already be built by GitHub workflows and available via the
5+
# GitHub Container Registry
6+
# However, if you want to build the container locally, then use this
7+
docker build --platform linux/amd64 -t casatools-env .

casatools-env/casasiteconfig.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# https://casadocs.readthedocs.io/en/stable/api/casaconfig.html#casasiteconfig-py
2+
# An example site config file.
3+
# Place this in a location checked by casaconfig:
4+
# /opt/casa/casasiteconfig.py
5+
# /home/casa/casasiteconfig.py
6+
# the environment value CASASITECONFIG - use the fully qualified path
7+
# anywhere in the python path, e.g. the site-packages directory in the CASA being used
8+
9+
# This file should be edited to set measurespath as appropriate
10+
11+
# Set this to point to the location where the site maintained casarundata can be found
12+
# by default datapath will include measurespath
13+
14+
measurespath = "/root/.casa/data"
15+
16+
# turn off all auto updates of data
17+
measures_auto_update = False
18+
data_auto_update = False
File renamed without changes.

0 commit comments

Comments
 (0)