Introduction:
This project template allows the creation of R projects based on Docker images to maximize computational reproducibility. It works in a very simple way. The workflow is depicted in the figure below. If you want to use this template for your own project, there are several steps that need to be taken. The first three steps (A, B, C) should be done to create an R project. The last step (D) focuses on how to run R Studio inside a 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 a need to create an empty repository and create an access token.
- Create an account on Gitlab
- There is a need to create an empty repository (do not check add readme).
- There is also a need to create project variables in which there will be stored information for Gitlab Continuous Integration (CI).
- You can set these variables in the following way: in a created project, go to:
settings - CI/CD - Variables. Then click
expand
and 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 the access token generated by Docker Hub after logging into the account).CI_REGISTRY_USER
= lukasjirinovak (username on Docker Hub)- It may happen that for some reason, CI/CD variables cause problems with authentication. If that happens, this problem might be bypassed by adding these variables directly into
gitlab-ci.yml
. However, this can be potentially dangerous, as you are making your access token publicly available. This allows someone to read and write your Docker Hub repository, based on access permissions set.
- It may happen that for some reason, CI/CD variables cause problems with authentication. If that happens, this problem might be bypassed by adding these variables directly into
- You can set these variables in the following way: in a created project, go to:
settings - CI/CD - Variables. Then click
B. Steps Taken on Local Repository
- There is a need to download this project template to the local repository.
- In the local repository, open the file named
replacement_function.ps1
. - In this file, there is a need to edit the following objects (quoted text represents an example):
docker_user_new
= “737823971” - Username created on Docker Hub.docker_project_new
= “eee” - Name of the repository created on Docker Hub.docker_project_and_user_new
= “737823971/eee:latest” - Name of the user and name of the repository created on Docker Hub; the argumentlatest
should not be changed. 4.full_project_name_new
= “RRE” - Name of the project you want to create from this template. 5.image_version_new
= “rocker/tidyverse:4.2.1” - Name of an image used to build the Docker container;- The number
4.2.1
indicates the version of an image. If you want to use the most recent version of thetidyverse
image, it can be found here. MAINTAINER_new
= “Lukas Novak lukasjirinovak@gmail.com” - Name of the person who created the new project.git_user_name_new
= “lukas.novak” - Username created on the remote repository (e.g., Gitlab, Github).git_user_email_new
= “lukasjirinovak@gmail.com” - Email associated with the remote repository.git_url_new
= “https://gitlab.com/lukas.novak/RRE.git" - URL of the newly created remote repository which was done in step A (2.1).R_project_name_new
= “project-name” - Name of the R project.
- The number
- After the previous steps are finished, there is a need to open
replacement_function.ps1
in PowerShell.
- In the local repository, open the file named
C. Uploading Files on Gitlab
- Open a terminal in the folder where you have the project files stored.
- In the terminal, there is a need to type the following code:
git config --global user.name "lukas.novak"
- Username created on the remote repository (e.g., Gitlab, Github).git config --global user.email "lukasjirinovak@gmail.com"
- Email associated with the remote repository.git init
- Initialize a git repository in the current folder.git remote add origin "https://gitlab.com/lukas.novak/RRE.git"
- Add the remote repository created in step A (2.1).git add .
- Add all files.git commit -m "initial commit"
- Commit with the initial message.git push --set-upstream origin master
- Set a new branch upstream.git push
- Push files to the remote repository.