Introduction:
This project template allows to create R projects based on Docker images to maximize computational reproducibility. It works in very simple way. The workflow is depicted in figure below. If you want to use this template for your own project, there are several steps, that needs to be taken. The first three steps (A,B,C) should be done to create a R project. The last step (D) is focused on how to run R studio inside the Docker container. All of these steps can also be found in this video tutorial.
R projects based on Docker images workflow:
A. Steps taken on Gitlab and Docker hub
- Create an account on Docker hub
- There is need to create an empty repository and create access token
- Create an account on Gitlab
- There is need to create an empty repository (do not check add readme)
- There is also need to create project variables in which there will be stored information for Gitlab Continuous Integration (CI)
- You can set this variables via the following way: in a created project go to:
settings - CI/CD - Variables. Than click
expand
set the following variables:CI_REGISTRY
= docker.io (name of a registry)CI_REGISTRY_IMAGE
= index.docker.io/lukasjirinovak/paqvalidation:latest (registry with username project and tag)CI_REGISTRY_PASSWORD
= xxxxxxxxxxxxxxx (This is access token generated by Docker hub after logging into account).CI_REGISTRY_USER
= lukasjirinovak (username on Docker Hub)- It can happen that for some reason CI/CD variables are causing problems with authentication. If that happens, this problem might be bypassed by adding these variables directly into
gitlab-ci.yml
. However, this might be potentially dangerous, as you are giving your access token publicly available. This allows someone to read and write your Docker Hub repository, based on access permissions set.
- It can happen that for some reason CI/CD variables are causing problems with authentication. If that happens, this problem might be bypassed by adding these variables directly into
- You can set this variables via the following way: in a created project go to:
settings - CI/CD - Variables. Than click
B.Steps taken on local repository
- There is need to download this project template to local repository
- In local repository, open file named
replacement_function.ps1
- In this file there is need to edit the following objects (quoted text represents example):
docker_user_new
= “737823971” - Username created on Docker Hubdocker_project_new
= “eee”- Name of repository created on Docker Hubdocker_project_and_user_new
= “737823971/eee:latest” - Name of a user and name of repository created on Docker Hub, the argumentlatest
should not be changedfull_project_name_new
= “RRE” - Name of the project you want to create from this templateimage_version_new
= “rocker/tidyverse:4.2.1” - name of an image used to build docker container;- number
4.2.1
indicates version of an image, if you want to use the most recent version of thetidyverse
image, it can be found here
- number
MAINTAINER_new
= “Lukas Novak lukasjirinovak@gmail.com” - name of a person who created new projectgit_user_name_new
= “lukas.novak” - Username created on remote repository (e.g. Gitlab, Github)git_user_email_new
= “lukasjirinovak@gmail.com” - Email associated with remote repositorygit_url_new
= “https://gitlab.com/lukas.novak/RRE.git" - url of newly created remote repository which was done in the step A (2.1)R_project_name_new
= “project-name” - name of R project
- After the previous steps are finished, there is a need to open
replacement_function.ps1
in PowerShell.
- In local repository, open file named
C. Uploading files on Gitlab
- Open terminal in folder where you have project files stored
- In terminal there is need to type the following code:
git config --global user.name "lukas.novak"
- Username created on remote repository (e.g. Gitlab, Github)git config --global user.email "lukasjirinovak@gmail.com"
- Email associated with remote repositorygit init
- initialize git repository in the current foldergit remote add origin "https://gitlab.com/lukas.novak/RRE.git
- add remote repository created in the step A (2.1)git add .
- add all filesgit commit -m "initial commit"
- commit with initial messagegit push --set-upstream origin master
- “set new branch upstream”git push
- push files to remote repository