Skip to content

Commit

Permalink
optimize dev container setup
Browse files Browse the repository at this point in the history
  • Loading branch information
rpodcast committed Dec 9, 2022
1 parent 480d611 commit 56fa450
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 892 deletions.
15 changes: 2 additions & 13 deletions .devcontainer/.env
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
INSTALL_ZSH=false
INSTALL_FISH=true
UPGRADE_PACKAGES=true
RENV_PATHS_CACHE_HOST=/opt/local/renv/cache
RENV_PATHS_CACHE_CONTAINER=/renv/cache
RENV_PATHS_CACHE=/renv/cache
USER=eric
USERID=1000
GROUPID=1000
PASSWORD=1rstudio
VOLUME_PATH=/home/eric/r_projects
LOCAL_PORT=3955
QUARTO_VERSION=latest
RSTUDIO_VERSION=2022.02.1-461
S6_VERSION=v1.21.7.0
COMPOSE_PROJECT_NAME=rweekly
DISABLE_AUTH=true
PASSWORD=rstudio
89 changes: 7 additions & 82 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,88 +1,13 @@
###################################################################################################################
# Adapted from https://github.com/microsoft/vscode-dev-containers/blob/master/containers/r/.devcontainer/Dockerfile
# licence: MIT
###################################################################################################################
FROM ghcr.io/rocker-org/devcontainer/tidyverse:4.2

FROM rocker/r-ver:4.1.3
# key dependencies for utilities
RUN apt-get update -qq \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends libxt6 curl python3-pip libsodium-dev imagemagick libmagick++-dev

# Options for setup script
ARG USERNAME
ARG INSTALL_ZSH="false"
ARG USER_UID="1000"
ARG USER_GID="1000"
ARG UPGRADE_PACKAGES="false"
ARG INSTALL_OHMYZSH="false"
ARG INSTALL_NONFREE="false"
ARG QUARTO_VERSION=latest

# key dependencies for certain R packages
RUN apt-get update \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends software-properties-common curl wget libssl-dev libxml2-dev libsodium-dev imagemagick libmagick++-dev libgit2-dev libssh2-1-dev zlib1g-dev librsvg2-dev libudunits2-dev libcurl4-openssl-dev python3-pip pandoc libzip-dev libfreetype6-dev libfontconfig1-dev tk libpq5 libxt6 openssh-client openssh-server \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*

COPY library-scripts/common-debian.sh /tmp/library-scripts/
RUN apt-get update && bash /tmp/library-scripts/common-debian.sh ${INSTALL_ZSH} ${USERNAME} ${USER_UID} ${USER_GID} ${UPGRADE_PACKAGES} ${INSTALL_OHMYZSH} ${INSTALL_NONFREE}

# install R packages needed for VSCode interaction and package management
RUN install2.r --error --skipinstalled --ncpus -4 languageserver renv remotes httpgd

# install radian via python and pip3
RUN apt-get update \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends python3-setuptools

RUN pip3 install radian

# install dot net core runtime for the R Tools plugin
RUN wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O /tmp/packages-microsoft-prod.deb \
&& dpkg -i /tmp/packages-microsoft-prod.deb

RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-transport-https \
&& apt-get -y install --no-install-recommends dotnet-sdk-3.1

# ensure that the renv package cache env var is accessible in default R installation
RUN echo "RENV_PATHS_CACHE=/renv/cache" >> /usr/local/lib/R/etc/Renviron

# copy the modified .Rprofile template to the renv cache
#COPY library-scripts/.Rprofile-vscode /renv/.Rprofile-vscode

# [Optional] Uncomment this section to add Quarto to the container
RUN /rocker_scripts/install_quarto.sh

# [Optional] Uncomment this section to add Hugo to the container
# Customize version number as appropriate
#RUN curl -L https://github.com/gohugoio/hugo/releases/download/v0.87.0/hugo_extended_0.87.0_Linux-64bit.deb -o /tmp/hugo.deb
#RUN apt-get -y install ./tmp/hugo.deb

# [Optional] Uncomment this section to add addtional system dependencies needed for project
# RUN apt-get update \
# && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends ---packages list----

# [Optional] Uncomment this section for linking a local pusleaudio sound system on a linux host
# to the container.
#RUN apt-get update \
# && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends libpulse0 libasound2 libasound2-plugins pulseaudio-utils

# install obs-cli (Go version)
# https://github.com/muesli/obs-cli/releases
#ADD https://github.com/muesli/obs-cli/releases/download/v0.4.0/obs-cli_0.4.0_linux_x86_64.tar.gz /obs-cli-linux.tar.gz
#RUN tar -zxvf obs-cli-linux.tar.gz
#RUN cp /obs-cli /usr/local/bin/obs-cli
#RUN chmod 755 /usr/local/bin/obs-cli

# install obs-cli (Javascript version)
# https://github.com/leafac/obs-cli/releases
#ADD https://github.com/leafac/obs-cli/releases/download/v2.2.3/obs-cli-linux /usr/local/bin/obs-cli-js
#RUN chmod 755 /usr/local/bin/obs-cli-js

# [Optional] install additional R packages
# install additional R packages
RUN install2.r --error --skipinstalled --ncpus -4 tidyRSS pkgsearch lubridate dplyr rtweet readr longurl tidyr twitterwidget urltools

RUN installGithub.r rweekly/rweekly.tools rweekly/rweekly.highlights

# [Optional] Set the default user. Omit if you want to keep the default as root.
USER $USERNAME
USER rstudio
105 changes: 0 additions & 105 deletions .devcontainer/README.md

This file was deleted.

36 changes: 19 additions & 17 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.134.1/containers/r
{
"name": "R",
"name": "${localWorkspaceFolderBasename}",
"dockerComposeFile": "docker-compose.yml",
"workspaceFolder": "/workspace",
"service": "vscode",

"features": {
"fish": "latest"
"ghcr.io/meaningful-ooo/devcontainer-features/fish:1": {},
"ghcr.io/rocker-org/devcontainer-features/pandoc:latest": {},
"ghcr.io/guiyomh/features/vim:0": {},
"ghcr.io/devcontainers/features/node:1": {}
},

// Set *default* container specific settings.json values on container create.
Expand All @@ -29,6 +30,7 @@
"r.terminalPath": "/usr/local/bin/radian",
"r.interpreterPath": "/usr/local/bin/R",
"r.debugger.timeouts.startup": 8000,
"r.lsp.diagnostics": false,
"editor.wordWrap": "on",
"editor.tabSize": 2,
"path-autocomplete.pathMappings": {
Expand All @@ -42,34 +44,34 @@
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"REditorSupport.r",
//"/renv/cache/r-latest.vslx",
"ionutvmi.path-autocomplete",
"usernamehw.errorlens",
"mhutchie.git-graph",
"wayou.vscode-todo-highlight",
"tomoki1207.pdf",
"DavidAnson.vscode-markdownlint",
"Rubymaniac.vscode-paste-and-indent",
"GrapeCity.gc-excelviewer",
"IBM.output-colorizer",
//"Mohamed-El-Fodil-Ihaddaden.shinysnip",
"hediet.vscode-drawio",
//"MS-vsliveshare.vsliveshare-pack",
"ms-python.python",
"RDebugger.r-debugger",
//"GitHub.copilot",
"eamodio.gitlens",
"GitHub.vscode-pull-request-github",
"quarto.quarto"
//"hoovercj.vscode-power-mode"
]
"quarto.quarto",
"redhat.vscode-yaml"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "R --version",
//"postCreateCommand": "python3 -m pip install jupyter",
// I tried automating the npm reqs for running rstudio server inside the contianer
// but these commands do not seem to work
//"postCreateCommand": [
// "npm install -g npm",
// "npm install -g localtunnel"
//]

// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "docker"
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
//"remoteUser": "vscode"
}

26 changes: 1 addition & 25 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,10 @@ services:
build:
context: .
dockerfile: Dockerfile
args:
USERNAME: ${USER}
QUARTO_VERSION: ${QUARTO_VERSION}
user: ${USER}
volumes:
- ..:/workspace:cached
- ${RENV_PATHS_CACHE_HOST}:/renv/cache
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
command: sleep infinity
env_file: .env

rstudiodevcontainer:
build:
context: ./rstudio_docker
args:
S6_VERSION: ${S6_VERSION}
RSTUDIO_VERSION: ${RSTUDIO_VERSION}
QUARTO_VERSION: ${QUARTO_VERSION}
volumes:
- ${VOLUME_PATH}:${VOLUME_PATH}
- /home/${USER}/.ssh:/home/${USER}/.ssh
- ${RENV_PATHS_CACHE_HOST}:${RENV_PATHS_CACHE_CONTAINER}
- ${VOLUME_PATH}/.devcontainer/rstudio_config_dir:/home/${USER}/.config/rstudio
restart:
unless-stopped
ports:
- ${LOCAL_PORT}:8787
env_file: .env
env_file: .env
Loading

0 comments on commit 56fa450

Please sign in to comment.