Skip to content

Commit

Permalink
Merge pull request #18 from mokztk/devel/4.3
Browse files Browse the repository at this point in the history
based on rocker/rstudio:4.3.3 (from Devel/4.3)
  • Loading branch information
mokztk committed Apr 26, 2024
2 parents 52840df + f4054f7 commit abde873
Show file tree
Hide file tree
Showing 12 changed files with 499 additions and 131 deletions.
34 changes: 24 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# rocker/tidyverse に日本語設定と頻用パッケージ、および TinyTeX, Radian を追加
# ENV CRAN=https://packagemanager.posit.co/cran/__linux__/jammy/2023-06-14
# rocker/rstudio:4.3.3 をベースにtidyverse, 日本語設定等を追加する(amd64/arm64共通)
# ENV CRAN=https://p3m.dev/cran/__linux__/jammy/2024-04-23

FROM rocker/tidyverse:4.3.0
# rocker/tidyverse:4.3.3 の Dockerfile を参考にベースを構築
# https://github.com/rocker-org/rocker-versioned2/blob/master/dockerfiles/rstudio_4.3.3.Dockerfile
# https://github.com/rocker-org/rocker-versioned2/blob/master/dockerfiles/tidyverse_4.3.3.Dockerfile

# Ubuntuミラーサイトの設定
#RUN sed -i.bak -e 's%http://[^ ]\+%mirror://mirrors.ubuntu.com/mirrors.txt%g' /etc/apt/sources.list
RUN sed -i.bak -e "s%http://[^ ]\+%http://ftp.udx.icscoe.jp/Linux/ubuntu/%g" /etc/apt/sources.list
FROM rocker/rstudio:4.3.3 AS tidyverse

COPY my_scripts/install_tidyverse.sh /my_scripts/install_tidyverse.sh
RUN chmod 775 /my_scripts/install_tidyverse.sh \
&& /my_scripts/install_tidyverse.sh

CMD ["/init"]

# 上記の rocker/tidyverse 相当のイメージに日本語設定などを追加

FROM tidyverse AS my_rstudio

# 日本語設定と必要なライブラリ(Rパッケージ用は別途スクリプト内で導入)
RUN set -x \
Expand All @@ -29,9 +39,10 @@ RUN /my_scripts/install_radian.sh
RUN /my_scripts/install_notojp.sh
RUN /my_scripts/install_coding_fonts.sh

# QuartoをTypst対応の1.4系に更新(2024-04時点の最新で 1.4.553)
RUN QUARTO_VERSION=1.4.553 /rocker_scripts/install_quarto.sh

USER rstudio
RUN /my_scripts/install_tinytex.sh
#RUN /my_scripts/install_tex_packages.sh

# ${R_HOME}/etc/Renviron のタイムゾーン指定(Etc/UTC)を上書き
RUN echo "TZ=Asia/Tokyo" >> /home/rstudio/.Renviron
Expand All @@ -44,6 +55,9 @@ ENV LANG=ja_JP.UTF-8 \
LC_ALL=ja_JP.UTF-8 \
TZ=Asia/Tokyo \
PASSWORD=password \
DISABLE_AUTH=true

DISABLE_AUTH=true \
RUNROOTLESS=false

# Amd64版との整合性のためrootlessモードは解除しておく

CMD ["/init"]
64 changes: 0 additions & 64 deletions Dockerfile_arm64

This file was deleted.

44 changes: 25 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
# About this image

- **rocker/tidyverse** に日本語設定、頻用パッケージ、TinyTeX関係をインストールした作業用イメージ
- ARM64 版も rocker/r-ver を出発点に rocker/tidyverse +日本語設定、頻用パッケージを導入する
- **rocker/rstudio** に rocker/tidyverse 相当のパッケージと日本語設定、頻用パッケージをインストールした作業用イメージ
- rocker/rstudio を出発点にすることで Amd64 (x86_64) / Arm64 の Dockerfile を共通化
- rocker/tidyverse 相当のうち、容量の大きな dbplyr database backend は RSQLite 以外を省略
- RStudio server を開くまでもないような作業用に、[radian: A 21 century R console](https://github.com/randy3k/radian)を追加する
- `reticulate` で最低限の python 連携も使用できるようにする
- [rocker-org/rocker-versioned2](https://github.com/rocker-org/rocker-versioned2) のように、目的別のスクリプトを使って Dockerfile 自体は極力シンプルにしてみる

```
docker image build -t "mokztk/rstudio:4.3.3" .
docker run --rm -d -p 8787:8787 --name rstudio mokztk/rstudio:4.3.3
# rocker/tidyverse 相当までの build
docker image build --target tidyverse -t "mokztk/tidyverse:4.3.3" .
```

## 詳細

### Ubuntu mirror

- x86_64 の場合は日本のミラーサーバーで一番回線が太い ICSCoE(IPA産業サイバーセキュリティセンター)に変更
- arm64 は置かれていないミラーサーバーも多いので変更しない
arm64 が置かれていないミラーサーバーも多いので変更しない

### 日本語環境、フォント

Expand All @@ -27,37 +35,34 @@
- BIZ UD Gothic + JetBrains Mono の合成フォント
- 半角:全角 3:5版ではなく、通常の1:2でリガチャ有効のバージョン(UDEVGothicLG-*.ttf)を使用
- RStudio Serverのエディタ用カスタムフォントとして導入
- **[原ノ味フォント](https://github.com/trueroad/HaranoAjiFonts)**
- TinyTeX (LuaLaTeX, XeLaTeX) で日本語PDFを作成するために `tinytex::tlmgr_install("haranoaji")` で導入
- 予めインストールしておかないと、[Knit to PDF] 時の自動インストールで躓く

### R の頻用パッケージ

- [インストール済みのパッケージ一覧](package_list.md)
- 容量節約のため、`--deps TRUE`指定(依存関係 Suggestsまで含める)は外し、インストール後にDLしたアーカイブは削除
- rockerのスクリプトに倣い、インストール後にRSPMのバイナリパッケージで導入された *.so を整理
- arm64版では、容量の大きな dbplyr database backend は省略

### [Quarto](https://quarto.org/)
### [Quarto](https://quarto.org/) & [Typst](https://typst.app/)

- x86_64, arm64 とも rocker/rstudio で既に導入されている
- rocker/rstudio で Quarto 1.3系が既に導入されているが、Typst 対応の 1.4系(2024-04-26時点で最新の 1.4.553)に更新
- Typst は Quarto 1.4 に含まれているものを使用
- Rパッケージ `quarto` もインストールし R Console からも使えるようにする

### Python3 & [radian: A 21 century R console](https://github.com/randy3k/radian)

- rocker project で用意されている `/rocker_scripts/install_python.sh` を利用して Python3 をインストール
- R から Python を使えるよう、`reticulate` に必要な Pandas などもインストール(`Seaborn` も含む)
- radian のコード補完のためには `jedi` が必要なのであわせてインストール
- python 3.10 の依存関係でトラブルが発生するので暫定的にダウングレード(3.10.6-1\~22.04.2ubuntu1.1 -> 3.10.6-1\~22.04.2ubuntu1)

### TinyTeX

- 2023年3月で TeX Live 2022 が更新終了(frozen)となったので、日本語 TeX 開発コミュニティ texjp.org のサーバにあるTeX Live 2022 のアーカイブを利用する
- TinyTeX はそれに合わせて "2023.03" をインストール
- TinyTeX のセットアップまで行い、その他に必要なパッケージは自動インストールに任せる
- 初回に日本語PDFを作成するときに自動でインストールされる(XeLaTeX + BXjscls の文書で約50個)
- LuaLaTeXの場合、原ノ味フォントはインストールしておかないと進まなくなるので `haranoaji` だけ手動で入れておく
- `/my_scripts/install_tex_packages.sh` をユーザー rstudio 権限で実行してインストールすることも可能
- arm64 は非対応なので、セットアップは行わない
- Quarto-Typst で日本語PDFも作成できるため、あまり使わない?
- TinyTeX はパッケージはインストールしてあるが、セットアップをしていない状態。
- 必要に応じてユーザー `rstudio` 権限でセットアップスクリプト `/my_script/install_tinytex.sh` を実行する(RStudio の Terminal で可)。
- TeX Live は引き続き日本語 TeX 開発コミュニティ texjp.org のサーバにある TeX Live 2022 (frozen) のアーカイブを利用
- TinyTeX はそれに合わせて "2023.03" をインストール
- LuaLaTeXの場合に、原ノ味フォントを先にインストールしておかないと進まなくなるので `haranoaji` だけセットアップ時にインストールしておく
- その他に必要なパッケージは、初回に日本語PDFを作成するときに自動でインストールされる(XeLaTeX + BXjscls の文書で約50個)

### 環境変数 PASSWORD の仮設定

Expand All @@ -66,7 +71,7 @@

### rootless モードの解除 (Arm64)

- arm64版の rocker/rstudio (rocker/r-ver に RStudio Server を追加した場合も) は rootless モードで動いており、起動時にユーザー rstudio が削除される
- arm64版の rocker/rstudio は rootless モードで動いており、起動時にユーザー rstudio が削除される
- amd64(x86_64)版と設定ファイルなどを共用するために rootless モードを解除して、従来どおりユーザー rstudio を使用する
- 今後、amd64 も rootless になるようならば要検討

Expand All @@ -88,3 +93,4 @@
- **2023-04-06** :bookmark:[4.2.2_2023Mar](https://github.com/mokztk/RStudio_docker/releases/tag/4.2.2_2023Mar) : `rocker/tidyverse:4.2.2` にあわせて更新。ARM64版を試作
- **2023-06-21** :bookmark:[4.2.2_2023Mar_2](https://github.com/mokztk/RStudio_docker/releases/tag/4.2.2_2023Mar_2) : Noto Sans JP フォントの導入に失敗していたのを修正
- **2023-06-23** :bookmark:[4.3.0_2023Jun](https://github.com/mokztk/RStudio_docker/releases/tag/4.3.0_2023Jun) : `rocker/tidyverse:4.3.0` にあわせて更新
- **2024-04-26** :bookmark:[4.3.3_2024Apr](https://github.com/mokztk/RStudio_docker/releases/tag/4.3.3_2024Apr) : `rocker/rstudio:4.3.3` をベースにQuarto 1.4を追加。Amd64/Arm64のDockerfileを1本化
2 changes: 1 addition & 1 deletion my_scripts/install_coding_fonts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -x
## https://github.com/yuru7/udev-gothic
mkdir -p /home/rstudio/.config/rstudio/fonts/UDEVGothicLG/400/italic
mkdir -p /home/rstudio/.config/rstudio/fonts/UDEVGothicLG/700/italic
wget -q https://github.com/yuru7/udev-gothic/releases/download/v1.3.0/UDEVGothic_v1.3.0.zip -O UDEVGothic.zip
wget -q https://github.com/yuru7/udev-gothic/releases/download/v1.3.1/UDEVGothic_v1.3.1.zip -O UDEVGothic.zip
unzip -j -d UDEVGothic UDEVGothic.zip
cp UDEVGothic/UDEVGothicLG-Regular.ttf /home/rstudio/.config/rstudio/fonts/UDEVGothicLG/400
cp UDEVGothic/UDEVGothicLG-Italic.ttf /home/rstudio/.config/rstudio/fonts/UDEVGothicLG/400/italic
Expand Down
9 changes: 0 additions & 9 deletions my_scripts/install_pandas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ set -x

# R から {reticulate} で Python3 を使えるようにセットアップ

# python 3.10 関連の依存関係のトラブルに対する workaround
cat << EOF >> /etc/apt/preferences
Package: *python3.10*
Pin: version 3.10.6-1~22.04.2ubuntu1
Pin-Priority: 1000
EOF
apt-get update
apt-get install -y --allow-downgrades python3.10

# Python3のインストール
source /rocker_scripts/install_python.sh

Expand Down
21 changes: 0 additions & 21 deletions my_scripts/install_quarto.sh

This file was deleted.

19 changes: 15 additions & 4 deletions my_scripts/install_r_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@

set -x

# from https://github.com/rocker-org/rocker-versioned2/blob/master/scripts/install_tidyverse.sh
# a function to install apt packages only if they are not installed
function apt_install() {
if ! dpkg -s "$@" >/dev/null 2>&1; then
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
apt-get update
fi
apt-get install -y --no-install-recommends "$@"
fi
}
# 依存ライブラリの追加
apt-get update
apt-get install -y --no-install-recommends \
apt_install \
cmake \
gdebi-core \
libcairo2-dev \
libcurl4-openssl-dev \
Expand Down Expand Up @@ -38,14 +48,16 @@ Rscript -e "update.packages(ask = FALSE)"
install2.r --error --ncpus -1 --skipinstalled \
here \
pacman \
pak \
knitr \
quarto \
tidylog \
furrr \
glmnetUtils \
glmmTMB \
ggeffects \
pROC \
cmprsk \
psych \
car \
mice \
ggmice \
Expand All @@ -56,7 +68,6 @@ install2.r --error --ncpus -1 --skipinstalled \
ggsci \
ggrepel \
patchwork \
tableone \
gt \
gtsummary \
flextable \
Expand Down
14 changes: 12 additions & 2 deletions my_scripts/install_tidyverse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ set -x
# 容量の大きな database backend は RSQLite 以外省略
# Ref: https://github.com/rocker-org/rocker-versioned2/blob/master/scripts/install_tidyverse.sh

# a function to install apt packages only if they are not installed
function apt_install() {
if ! dpkg -s "$@" >/dev/null 2>&1; then
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
apt-get update
fi
apt-get install -y --no-install-recommends "$@"
fi
}

# 依存ライブラリの追加
apt-get update
apt-get install -y --no-install-recommends \
apt_install \
libxml2-dev \
libcairo2-dev \
libgit2-dev \
Expand Down Expand Up @@ -38,6 +47,7 @@ install2.r --error --skipinstalled \
## dplyr database backends
install2.r --error --skipmissing --skipinstalled \
dbplyr \
dtplyr \
DBI \
RSQLite \
fst
Expand Down
16 changes: 16 additions & 0 deletions package_list.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: "Installed packages"
output:
md_document:
variant: "markdown_github"
---

```{r, message = FALSE}
library(tidyverse)
.packages(all.available = TRUE) %>%
sessioninfo::package_info(pkgs = ., include_base = FALSE) %>%
as_tibble() %>%
select(package, ondiskversion, date, source) %>%
knitr::kable()
```
Loading

0 comments on commit abde873

Please sign in to comment.