forked from magpiemodel/magpie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
137 lines (122 loc) · 4.19 KB
/
Copy pathDockerfile
File metadata and controls
137 lines (122 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# MAgPIE - Model of Agricultural Production and its Impact on the Environment
# Dockerfile for complete MAgPIE setup
#
# To build this image:
# docker build -t magpie .
#
# To run MAgPIE interactively:
# docker run -it -v /path/to/your/gamslice.txt:/opt/gams/gamslice.txt magpie
#
# Then inside the container:
# Rscript start.R
#
# To persist output data:
# docker run -it -v /path/to/your/gamslice.txt:/opt/gams/gamslice.txt \
# -v $(pwd)/output:/opt/magpie/output magpie
#
# To use a checked out copy of magpie on your system, run within the
# repository folder:
# docker run -it -v /path/to/your/gamslice.txt:/opt/gams/gamslice.txt \
# -v $(pwd):/opt/magpie magpie
FROM ubuntu:24.04
# Install system dependencies (before WORKDIR to maximize cache hits)
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt update && DEBIAN_FRONTEND=noninteractive apt install -y \
# We do not want a minimal image, as we want to use this interactively
unminimize \
# Basic tools
wget \
curl \
git \
unzip \
# Build tools
build-essential \
cmake \
# R and dependencies
r-base \
r-base-dev \
# System libraries required for R packages
libfontconfig1 \
libfontconfig1-dev \
libfreetype-dev \
libfribidi-dev \
libgdal-dev \
libgit2-dev \
libglpk-dev \
libharfbuzz-dev \
libjpeg-dev \
libnetcdf-dev \
libpng-dev \
libpoppler-cpp-dev \
libssl-dev \
libtiff5-dev \
libudunits2-dev \
libxml2-dev \
libcairo2-dev \
libuv1-dev \
pari-gp \
qpdf \
# Pandoc
pandoc \
# Other utilities
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Install GAMS
# Note: GAMS requires a license file. This downloads GAMS but you need to provide your own license.
# The license file (gamslice.txt) should be mounted or copied into the container.
ARG GAMS_VERSION=51.3.0
ARG GAMS_DOWNLOAD_URL=https://d37drm4t2jghv5.cloudfront.net/distributions/${GAMS_VERSION}/linux/linux_x64_64_sfx.exe
# Download and install GAMS
RUN cd /tmp && \
wget -q ${GAMS_DOWNLOAD_URL} -O gams_linux.exe && \
chmod +x gams_linux.exe && \
mkdir -p /opt/gams && \
./gams_linux.exe -d /opt/gams > /dev/null && \
rm gams_linux.exe && \
cp -r /opt/gams/**/* /opt/gams
# Add GAMS to PATH
ENV GAMS_PATH="/opt/gams"
ENV PATH="${GAMS_PATH}:${PATH}"
# Copy GAMS license file if provided
# To use this, you need to have gamslice.txt in the same directory as the Dockerfile
# and uncomment the following line:
# COPY gamslice.txt /opt/gams/gamslice.txt
# Set up R package manager pak
ENV RSPM='https://packagemanager.posit.co/cran/__linux__/noble/latest'
ENV RENV_CONFIG_REPOS_OVERRIDE='https://packagemanager.posit.co/cran/__linux__/noble/latest'
RUN <<EOF
echo "options(repos = c(pikpiam = 'https://pik-piam.r-universe.dev',
CRAN = Sys.getenv('RSPM')))" > ~/.Rprofile
EOF
RUN Rscript -e 'install.packages("pak")'
RUN Rscript -e 'pak::pkg_install("languageserver")'
# Set working directory
WORKDIR /opt/magpie
# Clone the MAgPIE project
RUN git clone --depth=1 https://github.com/magpiemodel/magpie.git .
# Install R package dependencies using renv
# We use a temporarily mounted directory to cache build artifacts between
# docker builds and in the end copy it to the original renv cache location
# to not confuse renv when we start runs later.
RUN --mount=type=cache,target=/tmp/renv-cache \
RENV_PATHS_CACHE=/tmp/renv-cache \
RENV_CONFIG_INSTALL_VERBOSE=true \
RENV_CONFIG_PAK_ENABLED=true \
Rscript -e '"dummy evaluation to start the renv auto-setup"' && \
mkdir -p /root/.cache/R/renv/cache && \
cp -r /tmp/renv-cache/* /root/.cache/R/renv/cache/ 2>/dev/null
# Verify installations
RUN echo "Verifying installations..." && \
git --version && \
R --version && \
pandoc --version && \
tex --version && \
gams || echo "GAMS installed but may require license activation"
# Set environment variables
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
# Default command: Start MAgPIE interactively
# Users can run: docker run -it magpie
# Or specify a run script: docker run magpie Rscript start.R default direct
CMD ["bash"]