Skip to content

Commit 25cb7ed

Browse files
committed
first update
1 parent 5cfb53b commit 25cb7ed

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

version-stable-r-development.Rmd

+24-21
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,30 @@ environments or projects.
2222
## Version-stable deployments
2323

2424
When deploying R applications (e.g. a Shiny app) using Docker containers, it is
25-
important to control versioning of R and packages for the sake of reproducibilty
25+
important to control versioning of R and packages for the sake of reproducibility
2626
and stability of the deployments. For this reason,
27-
[version-stable](https://github.com/rocker-org/rocker-versioned) images are
27+
[version-stable](https://github.com/rocker-org/rocker-versioned2) images are
2828
provided as part of the [Rocker project](https://www.rocker-project.org/) and
2929
used as a basis for deploying productive applications.
3030

3131
Each version-stable Rocker image has an associated _tag_ for all non-latest R
32-
versions (e.g. `rocker/r-ver:3.6.1`). Besides being specific to the
32+
versions (e.g. `rocker/r-ver:4.3.2`). Besides being specific to the
3333
corresponding version of R, each tag fixes the version of contributed packages
34-
(by using as package repository the MRAN snapshot of the last day CRAN
34+
(by using as package repository the CRAN snapshot of the last day CRAN
3535
distributed that R version as latest release). See
36-
[VERSIONS.md](https://github.com/rocker-org/rocker-versioned/blob/master/VERSIONS.md)
36+
[wiki/Versions](https://github.com/rocker-org/rocker-versioned2/wiki/Versions).
37+
If that R version is the latest, the CRAN date will not be set and the latest packages will always be installed.
38+
3739

3840
The `Dockerfile` of a deployed application then defines a given version-stable
3941
image tag to start `FROM`, e.g.
4042
```dockerfile
41-
FROM rocker/r-ver:3.6.1
43+
FROM rocker/r-ver:4.3.2
4244
```
4345
See
4446
[SmaRP/Dockerfile](https://github.com/miraisolutions/SmaRP/blob/master/Dockerfile)
4547
for an example.
48+
<!-- NOTE: Not yet merged into master -->
4649

4750

4851
## Align local development and deployment environments
@@ -57,7 +60,7 @@ The idea is then to rely on the same version-stable rocker containers used for
5760
the deployments, using a containerized versioned RStudio instance for the local
5861
development. This is available through Rocker's [versioned
5962
stack](https://www.rocker-project.org/images/#the-versioned-stack), so we could
60-
use e.g. `rocker/rstudio:3.6.1`.
63+
use e.g. `rocker/rstudio:4.3.2`.
6164

6265
Note that the same version-stable instance of RStudio can be used across all
6366
different projects for which such version is relevant. For this reason, a
@@ -69,12 +72,12 @@ install. See the specific section below about 'TinyTeX considerations'.
6972

7073
### Running versioned RStudio instances
7174

72-
Assume we want to run a containerized versioned instance of RStudio for R 3.6.1,
75+
Assume we want to run a containerized versioned instance of RStudio for R 4.3.2,
7376
possibly alongside instances for other versions of R.
7477

7578
First of all, we need to get the image from docker-hub
7679
```{bash pull}
77-
docker pull rocker/verse:3.6.1
80+
docker pull rocker/verse:4.3.2
7881
```
7982

8083
We then want to have a running instance on `localhost` (`127.0.0.1`), with the
@@ -83,7 +86,7 @@ following setup:
8386
- No authentication required (local setup).
8487
- Enable root by setting the environment variable `ROOT` to `TRUE`, so that e.g.
8588
`sudo apt-get` can be used in RStudio.
86-
- Use a version-specific port, e.g. `3500` for R 3.5.0, `3610` for R 3.6.1 and
89+
- Use a version-specific port, e.g. `4000` for R 4.0.0, `4320` for R 4.3.2 and
8790
so on, so that we can use `localhost` for concurrent R version instances.
8891
- The development code of all relevant projects should live outside the
8992
container and be shared with it (and possibly many of them), e.g. under
@@ -94,19 +97,19 @@ the container.
9497
the container user (`rstudio`) must match the UID of the host user (`$UID`).
9598
- In order for the RStudio setting to persist if the container is recreated
9699
(e.g. after pulling a new `rocker` image), we also use a shared volume (like
97-
`~/.rstudio-docker/3.6.1`) for the `home/rstudio/.rstudio` directory, which is
100+
`~/.rstudio-docker/4.2.3`) for the `home/rstudio/.rstudio` directory, which is
98101
version-specific in case of multiple R versions
99102
- If we want to use Meld via the [compareWith](https://github.com/miraisolutions/compareWith/) addins, we need to
100103
- map the `DISPLAY` environment variable and volume `/tmp/.X11-unix`
101104
- add `DISPLAY` to `Renviron`
102105
- install Meld
103106
- install `dbus-x11`
104107
- Use a version-specific name for the container running the RStudio instance,
105-
e.g. `rstudio_3.6.1`.
108+
e.g. `rstudio_4.2.3`.
106109

107110

108111
```{bash run}
109-
R_VER=3.6.1
112+
R_VER=4.3.2
110113
SHARED_DIR=RStudioProjects
111114
docker run -d --restart=always \
112115
-p 127.0.0.1:$(echo $R_VER | sed 's/[.]//g')0:8787 \
@@ -166,19 +169,19 @@ run_rstudio_ver() {
166169

167170
which you can re-use as compact command for any R version as follows
168171
```{bash run_rstudio_ver-use}
169-
run_rstudio_ver 3.6.1 RStudioProjects
172+
run_rstudio_ver 4.3.2 RStudioProjects
170173
```
171174

172175
Note that `--restart=always` specifies that the container should stay up and restart
173176
itself after stopping, e.g. upon machine reboot or docker upgrade, so that it is
174177
always available. Still, you can explicitly stop the running container with
175178
```{bash stop}
176-
docker stop rstudio_3.6.1
179+
docker stop rstudio_4.3.2
177180
```
178181
Alternatively, you can omit `--restart=always` and explicitly start the
179182
container whenever needed with
180183
```{bash start}
181-
docker start rstudio_3.6.1
184+
docker start rstudio_4.3.2
182185
```
183186

184187
Note that `start`/`stop` operations do not affect the persistence of files
@@ -213,21 +216,21 @@ If you are using LaTeX and start seeing errors like
213216
Remote repository is newer than local (2018 < 2019)
214217
```
215218
it means that you have to re-install TinyTeX. This happens e.g. with
216-
`rocker/verse:3.6.1`, since it was build at the end of 2018 but the current
219+
`rocker/verse:4.3.2`, since it was build at the end of 2018 but the current
217220
Tex Live repo is 2019. You can fix this via a **user-specific** re-installation of
218221
TinyTeX for R. **NOTE** however that this will uninstall the system-level
219222
TinyTeX pre-installed in `rocker/verse`.
220223

221224
First, make sure `/home/rstudio/bin` is part of the `PATH` environment variable.
222225
Check this by running
223226
```{bash check-path}
224-
docker exec --user rstudio rstudio_3.6.1 R --slave -e 'Sys.getenv("PATH")'
227+
docker exec --user rstudio rstudio_4.3.2 R --slave -e 'Sys.getenv("PATH")'
225228
```
226229
If you don't see `/home/rstudio/bin`, you can make sure it is part of the `PATH` for R via
227230
```{bash set-path}
228-
docker exec --user rstudio rstudio_3.6.1 sh -c 'echo "PATH=$HOME/bin:\${PATH}" >> $HOME/.Renviron'
231+
docker exec --user rstudio rstudio_4.3.2 sh -c 'echo "PATH=$HOME/bin:\${PATH}" >> $HOME/.Renviron'
229232
# check again
230-
docker exec --user rstudio rstudio_3.6.1 R --slave -e 'Sys.getenv("PATH")'
233+
docker exec --user rstudio rstudio_4.3.2 R --slave -e 'Sys.getenv("PATH")'
231234
```
232235

233236
Then, from the running RStudio, run
@@ -239,7 +242,7 @@ tinytex::reinstall_tinytex()
239242
### Cleanup
240243

241244
```{bash cleanup}
242-
docker rm $(docker stop rstudio_3.6.1)
245+
docker rm $(docker stop rstudio_4.3.2)
243246
```
244247

245248

0 commit comments

Comments
 (0)