Update Dockerfile and instructions for new meson build systems

[skip ci]
This creates the Docker containers for 5.5 and 6.0

(cherry picked from commit 1b3c1c33ce)
6.x
Willi Mutschler 2024-02-14 16:33:58 +01:00 committed by Sébastien Villemot
parent 862261c9b9
commit edca9c8f45
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
2 changed files with 112 additions and 40 deletions

View File

@ -1,4 +1,4 @@
# Copyright 2023 Dynare Team
# Copyright 2023-2024 Dynare Team
# This file is part of Dynare.
#
# Dynare is free software: you can redistribute it and/or modify
@ -26,38 +26,38 @@
# with the system libraries and adds the path of Dynare to the MATLAB and Octave startup scripts. #
# #
# MATLAB LICENSE: #
# The container is created using a network license, so no information on the license is inside the container #
# see https://git.dynare.org/dynare/dynare/docker/README.md#matlab-license for more information. #
# The container is created without any information on a license. To use Dynare with MATLAB, you need to #
# provide a valid license, see https://git.dynare.org/dynare/dynare/docker/README.md#matlab-license. #
##############################################################################################################
# Default values which MATLAB and Dynare release to install in the container
# The Dynare release must conform to a corresponding tag on https://git.dynare.org/dynare/dynare
# Note that Dynare 6.x uses the meson build system, while Dynare 4.x and 5.x use the autoconf/automake build system
# MATLAB release must conform to a corresponding tag on https://hub.docker.com/r/mathworks/matlab/tags
# Octave version the one shipped with the Ubuntu version used in the base container (in 20.04 it is 6.4.0)
ARG MATLAB_RELEASE=R2023a
ARG DYNARE_RELEASE=5.4
# Octave version is the one shipped with the Ubuntu version used in the base container (or from a PPA)
ARG MATLAB_RELEASE=R2023b
ARG DYNARE_RELEASE=6.0
# Specify the list of products to install into MATLAB with mpm
ARG MATLAB_PRODUCT_LIST="Symbolic_Math_Toolbox Statistics_and_Machine_Learning_Toolbox Optimization_Toolbox Econometrics_Toolbox Parallel_Computing_Toolbox Control_System_Toolbox Global_Optimization_Toolbox"
# Specify MATLAB Install Location.
# Specify MATLAB install location
ARG MATLAB_INSTALL_LOCATION="/opt/matlab/${MATLAB_RELEASE}"
# Specify license server information using the format: port@hostname
# Specify license server information using the format: port@hostname
ARG LICENSE_SERVER
# Specify the base image with MATLAB installed.
# Specify the base image with pre-installed MATLAB
FROM mathworks/matlab:${MATLAB_RELEASE}
USER root
# Declare build arguments to use at the current build stage.
# Declare build arguments to use at the current build stage
ARG MATLAB_RELEASE
ARG MATLAB_PRODUCT_LIST
ARG MATLAB_INSTALL_LOCATION
ARG LICENSE_SERVER
ARG DYNARE_RELEASE
# Install mpm dependencies.
# Install mpm dependencies
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install --no-install-recommends --yes \
@ -70,6 +70,7 @@ RUN export DEBIAN_FRONTEND=noninteractive \
# Run mpm to install additional toolboxes for MATLAB in the target location and delete the mpm installation afterwards.
# If mpm fails to install successfully, then print the logfile in the terminal, otherwise clean up.
# Hint: Sometimes there is a segmentation fault when running mpm, just re-run the build command in this case.
RUN wget -q https://www.mathworks.com/mpm/glnxa64/mpm \
&& chmod +x mpm \
&& ./mpm install \
@ -79,11 +80,39 @@ RUN wget -q https://www.mathworks.com/mpm/glnxa64/mpm \
|| (echo "MPM Installation Failure. See below for more information:" && cat /tmp/mathworks_root.log && false) \
&& rm -f mpm /tmp/mathworks_root.log
# Install dynare dependencies.
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install --no-install-recommends --yes \
build-essential \
# Install specific build-system dependencies based on DYNARE_RELEASE and keep this layer small to reduce image size (apt cache cleanup)
RUN case "$DYNARE_RELEASE" in \
6.*) \
export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install --no-install-recommends --yes \
gcc \
g++ \
meson \
pkgconf \
python3-pip\
&& apt-get clean \
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/* ;; \
5.*|4.*) \
export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install --no-install-recommends --yes \
build-essential \
autoconf \
automake \
doxygen \
&& apt-get clean \
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/*;; \
*) \
echo "Unsupported DYNARE_RELEASE version: $DYNARE_RELEASE. No dependencies will be installed." ;; \
esac
# Install common dependencies for Dynare and keep this layer small to reduce image size (apt cache cleanup)
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install --no-install-recommends --yes \
gfortran \
libboost-graph-dev \
libgsl-dev \
@ -94,8 +123,6 @@ RUN export DEBIAN_FRONTEND=noninteractive \
flex \
libfl-dev \
bison \
autoconf \
automake \
texlive \
texlive-publishers \
texlive-latex-extra \
@ -109,7 +136,6 @@ RUN export DEBIAN_FRONTEND=noninteractive \
tex-gyre \
latexmk \
libjs-mathjax \
doxygen \
x13as \
liboctave-dev \
octave-control \
@ -123,10 +149,30 @@ RUN export DEBIAN_FRONTEND=noninteractive \
ghostscript \
epstool \
git \
git-lfs \
&& apt-get clean \
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/*
# Dynare 6.x is only compatible with Octave 7.1.0 to 8.4.0
# The current base image of R2023b ships is based on Ubuntu 22.04 which ships Octave 6.2.0,
# so we add an inofficial Octave PPA to install a compatible version
# Once the MATLAB containers are based on Ubuntu 24.04, we can remove this step and use the default Octave version from the Ubuntu repository
# Note: the pkg install -forge command takes a long time
RUN case "$DYNARE_RELEASE" in \
6.*) \
export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install --no-install-recommends --yes software-properties-common && \
add-apt-repository -y ppa:ubuntuhandbook1/octave && \
apt-get update && \
apt-get remove --purge --yes octave octave-control octave-econometrics octave-io octave-statistics octave-struct octave-parallel && \
apt-get install --no-install-recommends --yes octave octave-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
octave --eval "pkg install -forge struct io statistics optim control econometrics parallel" ;; \
esac
# Rename libraries (see matlab-support package: https://salsa.debian.org/debian/matlab-support/-/blob/master/debian/matlab-support.postinst)
RUN if [ -f "${MATLAB_INSTALL_LOCATION}/sys/os/glnxa64/libgcc_s.so.1" ]; then \
mv ${MATLAB_INSTALL_LOCATION}/sys/os/glnxa64/libgcc_s.so.1 ${MATLAB_INSTALL_LOCATION}/sys/os/glnxa64/libgcc_s.so.1.bak; \
@ -163,20 +209,34 @@ ENV MLM_LICENSE_FILE=$LICENSE_SERVER
# Get Dynare sources as matlab user
USER matlab
WORKDIR /home/matlab
RUN git lfs install
RUN git clone --depth 1 --branch ${DYNARE_RELEASE} --recurse-submodules https://git.dynare.org/dynare/dynare.git
# Compile Dynare
USER matlab
WORKDIR /home/matlab
RUN cd dynare \
&& autoreconf -si \
&& ./configure --with-matlab=${MATLAB_INSTALL_LOCATION} MATLAB_VERSION=${MATLAB_RELEASE} \
&& make -j$(($(nproc)+1))
# Dynare 6.x: install meson 1.3.1 using python3-pip because meson package in the Ubuntu repositories is too old
# Once the MATLAB containers are based on Ubuntu 24.04, this step can be removed
RUN case "$DYNARE_RELEASE" in \
6.*) \
cd dynare && \
pip3 install meson==1.3.1 && \
export PATH="/home/matlab/.local/bin:${PATH}" && \
meson setup -Dmatlab_path=${MATLAB_INSTALL_LOCATION} -Dbuildtype=debugoptimized build-matlab && \
meson compile -C build-matlab && \
meson setup -Dbuild_for=octave -Dbuildtype=debugoptimized build-octave && \
meson compile -C build-octave ;; \
5.*|4.*) \
cd dynare && \
autoreconf -si && \
./configure --with-matlab=${MATLAB_INSTALL_LOCATION} MATLAB_VERSION=${MATLAB_RELEASE} && \
make -j$(($(nproc)+1)) ;; \
*) \
echo "Unsupported DYNARE_RELEASE version: $DYNARE_RELEASE. Compilation steps will be skipped." ;; \
esac
# Add path of dynare to startup script for Octave.
# Add path of dynare to startup script for Octave
RUN echo "addpath /home/matlab/dynare/matlab" >> /home/matlab/.octaverc
# Add path of dynare to startup script for MATLAB.
# Add path of dynare to startup script for MATLAB
# Note that if startup.m file exists (in newer MATLAB containers), it is a MATLAB function
# and the last line is an "end", so we append the path to the second-to-last line
# For some reason we have to do this as root, otherwise the file is not writable
@ -195,6 +255,6 @@ RUN filename="/home/matlab/Documents/MATLAB/startup.m" && \
fi && \
chown matlab:matlab "$filename"
# Set user and work directory.
# Set user and work directory
USER matlab
WORKDIR /home/matlab

View File

@ -1,5 +1,5 @@
# Dynare Docker Containers
We provide a range of pre-configured Docker containers for [Dynare](https://dynare.org), which include both Octave and MATLAB (pre-configured with Dynare already in the PATH) and all recommended toolboxes. These containers are ideal for using Dynare in CI/CD environments ([example Workflow for GitHub Actions](https://github.com/wmutschl/DSGE_mod/tree/master/.github/workflows)) or High Performance Computing clusters with either [Docker, ENROOT or Singularity](https://wiki.bwhpc.de/e/BwUniCluster2.0/Containers).
We provide a range of pre-configured Docker containers for [Dynare](https://dynare.org), which include both Octave and MATLAB (pre-configured with Dynare already in the PATH) and all recommended toolboxes. These containers are ideal for using Dynare in CI/CD environments ([example Workflow for GitHub Actions](https://github.com/JohannesPfeifer/DSGE_mod/tree/master/.github/workflows)) or High Performance Computing clusters with either [Docker, ENROOT or Singularity](https://wiki.bwhpc.de/e/BwUniCluster2.0/Containers).
To minimize maintenance efforts while ensuring high levels of security, reliability, and performance, our Docker containers are built from the official [MATLAB container base image](https://hub.docker.com/r/mathworks/matlab) using a custom [Dockerfile](Dockerfile). For more information on building and customizing the containers, see the [built instructions and customization](#built-instructions-and-customization) section below. Additionally, we provide an example [docker-compose file](docker-compose.yml) for complete access to the Ubuntu Desktop via VNC.
@ -7,7 +7,9 @@ To minimize maintenance efforts while ensuring high levels of security, reliabil
| Tags | Dynare Version | MATLAB® Version | Octave Version | Operating System | Base Image |
|--------|----------------|-----------------|----------------|------------------|-------------------------|
| latest | 5.4 | R2023a | 5.2.0 | Ubuntu 20.04 | mathworks/matlab:R2023a |
| latest | 6.0 | R2023b | 8.4.0 (PPA) | Ubuntu 22.04 | mathworks/matlab:R2023b |
| 6.0 | 6.0 | R2023b | 8.4.0 (PPA) | Ubuntu 22.04 | mathworks/matlab:R2023b |
| 5.5 | 5.5 | R2023b | 6.4.0 | Ubuntu 22.04 | mathworks/matlab:R2023b |
| 5.4 | 5.4 | R2023a | 5.2.0 | Ubuntu 20.04 | mathworks/matlab:R2023a |
| 5.3 | 5.3 | R2022b | 5.2.0 | Ubuntu 20.04 | mathworks/matlab:R2022b |
| 5.2 | 5.2 | R2022a | 5.2.0 | Ubuntu 20.04 | mathworks/matlab:R2022a |
@ -15,14 +17,21 @@ To minimize maintenance efforts while ensuring high levels of security, reliabil
| 5.0 | 5.0 | R2021b | 5.2.0 | Ubuntu 20.04 | mathworks/matlab:R2021b |
| 4.6.4 | 4.6.4 | R2021a | 5.2.0 | Ubuntu 20.04 | mathworks/matlab:R2021a |
Note that we use an inofficial [PPA](https://launchpad.net/~ubuntuhandbook1/+archive/ubuntu/octave) (maintained by [https://ubuntuhandbook.org](https://ubuntuhandbook.org)) to install Octave 8.4.0 on Ubuntu 22.04, the usual disclaimer on PPAs applies.
Once Ubuntu 24.04 is released, we will switch to the version from the official repositories.
## How to interact with the container
To pull the latest image to your machine, execute:
```sh
docker pull dynare/dynare:latest
```
In the following we assume that you have access to a MATLAB license using e.g. a [network license server of a University](https://uni-tuebingen.de/de/3107#c4656) and show different workflows how to interact with the container.
Obviously, you would need to adjust the environmental variable `MLM_LICENSE_FILE` to your use-case, please refer to the [MATLAB license](#matlab-license) section on licensing information and how to pass a personal license.
or a specific version:
```sh
docker pull dynare/dynare:6.0
```
In the following we assume that you have access to a MATLAB license and show different workflows how to interact with the container.
Obviously, you need to adjust the environmental variable `MLM_LICENSE_FILE` to your use-case, please refer to the [MATLAB license](#matlab-license) section on licensing information and how to pass a personal license.
Alternatively, if you don't have access to a license or the closed-source mentality of MATLAB is an irreconcilable issue for you, you can equally well use Dynare with the free and open-source alternative Octave.
### Run Dynare in an interactive MATLAB session in the browser
@ -31,9 +40,9 @@ To launch the container with the `-browser` option, execute:
```sh
docker run -it --rm -p 8888:8888 -e MLM_LICENSE_FILE=27000@matlab-campus.uni-tuebingen.de --shm-size=512M dynare/dynare:latest -browser
```
You will receive a URL to access MATLAB in a web browser, for example: `http://localhost:8888` or another IP address that you can use to reach your server, such as through a VPN like [Tailscale](https://tailscale.com) if you are behind a firewall. Enter the URL provided into a web browser. If prompted, enter credentials for a MathWorks account associated with a MATLAB license. If you are using a network license manager, switch to the Network License Manager tab and enter the license server address instead. After providing your license information, a MATLAB session will start in the browser. This may take several minutes. To modify the behavior of MATLAB when launched with the `-browser` flag, pass environment variables to the `docker run` command. For more information, see [Advanced Usage](https://github.com/mathworks/matlab-proxy/blob/main/Advanced-Usage.md).
You will receive a URL to access MATLAB in a web browser, for example: `http://localhost:8888` or another IP address that you can use to reach your server, such as through a VPN like [Tailscale](https://tailscale.com) if you are behind a firewall. Enter the URL provided into a web browser. Note that if you set `MLM_LICENSE_FILE` to empty or leave it out from the command, you will be prompted to enter credentials for a MathWorks account associated with a MATLAB license. If you are using a network license manager, switch to the Network License Manager tab and enter the license server address instead. After providing your license information, a MATLAB session will start in the browser. This may take several minutes. To modify the behavior of MATLAB when launched with the `-browser` flag, pass environment variables to the `docker run` command. For more information, see [Advanced Usage](https://github.com/mathworks/matlab-proxy/blob/main/Advanced-Usage.md).
Note that the `-browser` flag is supported by base images starting from `mathworks/matlab:R2022a` using [noVNC](https://novnc.com). Some browsers, like Safari, may not support this workflow.
Note that the `-browser` flag is supported by base images starting from `mathworks/matlab:R2022a` using [noVNC](https://novnc.com). Some browsers may not support this workflow.
### Run Ubuntu desktop and interact with it via VNC
@ -45,7 +54,7 @@ To connect to the Ubuntu desktop, either:
- Point a browser to port 6080 of the docker host machine running this container (`http://hostname:6080`).
- Use a VNC client to connect to display 1 of the docker host machine (`hostname:1`). The VNC password is `matlab` by default, you can change that by adjusting the `PASSWORD` environment variable in the run command.
- If you are behind a firewall, we recommend to use a VPN such as [Tailscale](https://tailscale.com).
- If you are behind a firewall, we recommend to use a VPN such as [Tailscale](https://tailscale.com) such that you can access the VNC server via the Tailscale address of the server.
### Run Dynare with Octave in an interactive command prompt
@ -92,6 +101,7 @@ The Desktop window of MATLAB will open on your machine. Note that the command ab
### MATLAB license
To run this container, your license must be [configured for cloud use](https://mathworks.com/help/install/license/licensing-for-mathworks-products-running-on-the-cloud.html). Individual and Campus-Wide licenses are already configured for cloud use. If you have a different license type, please contact your license administrator to configure it for cloud use. You can identify your license type and administrator by viewing your MathWorks Account. Administrators can consult the "Administer Network Licenses" documentation. If you don't have a MATLAB license, you can obtain a trial license at [MATLAB Trial for Docker](https://de.mathworks.com/campaigns/products/trials/targeted/dkr.html).
Lastly, if you run the container via a GitHub workflow, you don't need to provide a license as the IP of the GitHub runner is already covered by a sponsored MATLAB license.
#### Network license
If you're using a network license, you can pass the port and hostname via the `MLM_LICENSE_FILE` environmental variable in your `docker run` command or Docker Compose file. Here's an example `docker run` command that uses a network license:
@ -102,14 +112,14 @@ docker run --init -it --rm -e MLM_LICENSE_FILE=27000@matlab-campus.uni-tuebingen
#### Personal License
To use a personal license, you must first create a license file via the MATHWORKS License Center, refer to [Option 2](https://de.mathworks.com/matlabcentral/answers/235126-how-do-i-generate-a-matlab-license-file#answer_190013) for detailed instructions.
For this process, you will need the `username` and a `host ID`. In the container, the username is predefined as 'matlab'.
For this process, you will need the `username` and a `host ID`. In the container, the username is predefined as `matlab`.
The `host ID` corresponds to the MAC address of any network adapter in the container.
In Docker, you can supply a [randomly generated MAC address](https://miniwebtool.com/mac-address-generator/) (e.g., A6-7E-1A-F4-9A-92) during the docker run command.
Download the file from MATHWORKS License Center and ensure you provide the container with access to the license file by mounting it as a (read-only) volume.
Here is an example `docker run` command that utilizes a license file named `matlab-license.lic`, which is located in your home folder:
Here is an example `docker run` command that utilizes a license file named `license.lic`, which is located in a folder `$HOME/matlab-license` on the host machine; the MAC address associated with the license is set to `A6-7E-1A-F4-9A-92`:
```sh
docker run --init -it --rm --mac-address A6-7E-1A-F4-9A-92 --shm-size=512M -v $HOME/matlab-license.lic:/licenses/license.lic:ro -e MLM_LICENSE_FILE=/licenses/license.lic dynare/dynare:latest matlab -batch "cd dynare/examples; dynare example1"
docker run --init -it --rm --mac-address A6-7E-1A-F4-9A-92 --shm-size=512M -v $HOME/matlab-license/:/licenses:ro -e MLM_LICENSE_FILE=/licenses/license.lic dynare/dynare:latest matlab -batch "cd dynare/examples; dynare example1"
```
### Environment variables
@ -120,7 +130,9 @@ When running the `docker run` command, you can specify environment variables usi
Here are the commands to create the Docker images available at [Docker Hub](https://hub.docker.com/r/dynare/dynare):
```sh
docker build --build-arg MATLAB_RELEASE=R2023a --build-arg DYNARE_RELEASE=5.4 -t dynare/dynare:latest .
docker build --build-arg MATLAB_RELEASE=R2023b --build-arg DYNARE_RELEASE=6.0 -t dynare/dynare:latest .
docker build --build-arg MATLAB_RELEASE=R2023b --build-arg DYNARE_RELEASE=6.0 -t dynare/dynare:6.0 .
docker build --build-arg MATLAB_RELEASE=R2023b --build-arg DYNARE_RELEASE=5.5 -t dynare/dynare:5.5 .
docker build --build-arg MATLAB_RELEASE=R2023a --build-arg DYNARE_RELEASE=5.4 -t dynare/dynare:5.4 .
docker build --build-arg MATLAB_RELEASE=R2022b --build-arg DYNARE_RELEASE=5.3 -t dynare/dynare:5.3 .
docker build --build-arg MATLAB_RELEASE=R2022a --build-arg DYNARE_RELEASE=5.2 -t dynare/dynare:5.2 .