-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1503 from brian-team/docker_images
Automatically build docker images for each Brian release
- Loading branch information
Showing
4 changed files
with
224 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# docker buildx build --push --platform linux/amd64,linux/arm64/v8 -o type=image -t briansimulator/brian -f docker/Dockerfile . | ||
# docker run -it --init --rm -p 8888:8888 briansimulator/brian | ||
|
||
ARG BASE_IMAGE_TAG=3.12-slim-bookworm | ||
FROM python:${BASE_IMAGE_TAG} | ||
|
||
LABEL maintainer="Ben Evans <B.D.Evans@sussex.ac.uk>" \ | ||
org.opencontainers.image.vendor="The Brian Development Team" \ | ||
org.opencontainers.image.licenses="CeCILL 2.1" \ | ||
org.opencontainers.image.title="Brian Docker Image" \ | ||
org.opencontainers.image.description="Docker image for Brian - a free, open source simulator for spiking neural networks" \ | ||
org.opencontainers.image.homepage="https://briansimulator.org" \ | ||
org.opencontainers.image.url="https://hub.docker.com/r/briansimulator/brian" \ | ||
org.opencontainers.image.source="https://github.com/brian-team/brian2" \ | ||
org.opencontainers.image.documentation="https://brian2.readthedocs.io/" | ||
|
||
# Install dependencies | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
g++ \ | ||
git \ | ||
libgsl-dev \ | ||
sudo \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Copy wheels into the image | ||
COPY dist /tmp/dist | ||
|
||
# Install Brian2 and recommended packages | ||
RUN python -m pip install --no-cache-dir --only-binary=:all: \ | ||
scipy \ | ||
matplotlib \ | ||
jupyterlab \ | ||
pytest \ | ||
pytest-xdist \ | ||
&& python -m pip install /tmp/dist/Brian2*_$(uname -m).whl brian2tools \ | ||
&& rm -rf /tmp/dist | ||
|
||
# Create a non-root user | ||
ARG USER="monty" \ | ||
GROUP="monty" \ | ||
PASSWORD="monty" | ||
RUN groupadd ${GROUP} && \ | ||
useradd -ms /bin/bash -g ${GROUP} -G sudo ${USER} && \ | ||
echo "${USER}:${PASSWORD}" | chpasswd | ||
ENV HOME="/home/${USER}" | ||
RUN chown -R ${USER}:${USER} ${HOME} | ||
USER ${USER} | ||
|
||
# Copy tutorial notebooks and example scripts to home directory | ||
WORKDIR ${HOME} | ||
RUN git clone https://github.com/brian-team/brian2.git \ | ||
&& mv brian2/examples examples \ | ||
&& mv brian2/tutorials tutorials \ | ||
&& chmod -R +x tutorials \ | ||
&& chmod -R +x examples \ | ||
&& find . -name '*.ipynb' -exec jupyter trust {} \; \ | ||
&& rm -rf brian2 | ||
|
||
EXPOSE 8888 | ||
CMD ["jupyter", "lab", "--ip=0.0.0.0", "--no-browser"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Docker instructions | ||
|
||
## Run docker image | ||
To run the docker image, you can use | ||
|
||
`docker run -it --init -p 8888:8888 briansimulator/brian` | ||
|
||
This will start a JupyterLab instance inside the container, which you can access from your local browser via the last link | ||
printed to the terminal (`http://127.0.0.1:8888/lab?token=…`) | ||
|
||
Or if you prefer a simple `bash` terminal rather than JupyterLab: | ||
|
||
`docker run -it --init briansimulator/brian /bin/bash` | ||
|
||
Or to run the tests: | ||
|
||
`docker run -it --init --rm briansimulator/brian python -c 'import brian2; brian2.test(test_standalone="cpp_standalone")'` | ||
|
||
## Build docker image | ||
To build the docker image locally, follow the following instructions: | ||
|
||
### Build package wheel | ||
You need to first build the package wheel(s) for linux using [`cibuildwheel`](https://cibuildwheel.readthedocs.io). Install it via | ||
`pip install cibuildwheel` (or use `pipx`) | ||
|
||
#### Build wheel for local architecture | ||
Run `cibuildwheel` to build a package for your architecture: | ||
``` | ||
export CIBW_BUILD='cp312-manylinux*' | ||
cibuildwheel --platform linux --arch auto64 --output-dir dist | ||
``` | ||
|
||
#### Build multi-arch wheel | ||
First install `qemu` for cross-compilation, e.g. on Debian/Ubuntu: | ||
|
||
`sudo apt install qemu-user-static` | ||
|
||
Then, run | ||
``` | ||
export CIBW_BUILD='cp312-manylinux*' | ||
cibuildwheel --platform linux --arch auto64,aarch64 --output-dir dist | ||
``` | ||
|
||
### Build docker image | ||
|
||
You can then build the docker image via | ||
|
||
`docker build -t briansimulator/brian -f docker/Dockerfile .` | ||
|
||
Alternatively, to test multi-architecture builds and push to docker hub, first login: | ||
|
||
`docker login` | ||
|
||
Create a new builder that uses the docker-container driver (only needed once): | ||
``` | ||
docker buildx create \ | ||
--name container \ | ||
--driver=docker-container \ | ||
default | ||
``` | ||
Then execute: | ||
|
||
``` | ||
docker buildx build \ | ||
--builder=container \ | ||
--push \ | ||
--platform linux/amd64,linux/arm64/v8 \ | ||
-o type=image \ | ||
-t briansimulator/brian \ | ||
-f docker/Dockerfile \ | ||
. | ||
``` |