-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdockerfile-app
69 lines (54 loc) · 2.45 KB
/
dockerfile-app
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
# Pull your base docker image
# Using rocker for R and the light 'versioned' tag (not the RStudio)
FROM rocker/tidyverse:4.0.4
# Packages to enable ODBC and installation of the Microsoft drivers via curl
RUN apt-get update -y && apt-get install -y \
curl \
freetds-bin \
freetds-dev \
git \
gnupg2 \
odbc-postgresql \
tdsodbc \
unixodbc \
unixodbc-dev \
tzdata
# See about installing ODBC drivers here: https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
# Note that the driver version installed needs to match the version used in the code
# Here debian stretch (as per tidyverse:4)
RUN curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update -y
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17 mssql-tools
# Permissions are such that works fine as root but not from RStudio where user is not root
# so MUST do the following else an unhelpful error message tells you the file does not exist
COPY odbc/* /etc/
RUN chmod a+rw /etc/odbc.ini && chmod a+rw /etc/odbcinst.ini
# YOU MUST BUILD WITH build_args i.e. --build-arg USER_ID=$(id -u) \
# Now install and set-up as per calling user
# See https://vsupalov.com/docker-shared-permissions/
ARG USER_NAME
ARG USER_ID
ARG GROUP_ID
RUN addgroup --gid $GROUP_ID $USER_NAME
RUN adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID $USER_NAME
# Install necessary libraries and R set-up
# Do separately to the app installation so that unless you change the necessary
# libraries you can debug end edit the app without rebuilding the full image
RUN install2.r odbc renv
COPY dev/renv.lock /home/$USER_NAME/renv.lock
RUN Rscript -e "renv::restore(lockfile='/home/$USER_NAME/renv.lock')"
# COPY .Renviron NOT .Rprofile since you just want the secrets
# and .Rprofile will try to run renv::activate() which is not available
COPY .Renviron /home/$USER_NAME/
# Now copy app and supporting files in /app to the image
# COPY app/app.R /home/$USER_NAME/app.R
COPY app/app /home/$USER_NAME/app
COPY .Renviron /home/$USER_NAME/app/
# Start the container with a 'dummy' process that prevents the container
# immediately stopping
RUN chown -R $USER_NAME /home/$USER_NAME
RUN chmod -R a+rw /home/$USER_NAME/app
USER $USER_NAME
WORKDIR /home/$USER_NAME/app
CMD tail -f /dev/null