Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Docker Image CI

on:
push:
tags:
- "*"

jobs:

build:

runs-on: ubuntu-latest

steps:
- name: Check Out Repo
uses: actions/checkout@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker lagers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./docker/Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ secrets.DOCKER_USER }}/treat-hub:${{ env.VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
4 changes: 2 additions & 2 deletions docker/Dockerfile.txt → docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ ADD https://api.github.com/repos/trr266/treat/git/refs/heads/main version.json

RUN cd /home/rstudio && sudo -H -u rstudio git clone https://github.com/trr266/treat.git

COPY RProfile.R /home/rstudio/.Rprofile
COPY docker/RProfile.R /home/rstudio/.Rprofile
RUN cp /home/rstudio/treat/_config.csv /home/rstudio/treat/config.csv

RUN chown rstudio.rstudio /home/rstudio/.Rprofile
RUN chown rstudio.rstudio /home/rstudio/treat/config.csv
RUN chown rstudio.rstudio /home/rstudio/treat/config.csv
62 changes: 62 additions & 0 deletions info/docker_info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## why would I want to use R in Docker?

This documentation is a brief introduction to Docker. First of all, you may have the question: why would I want to use R in Docker?

To answer that question you can either read the following text or watch this video:

https://youtu.be/_dfLOzuIg2o?t=18

Often when you send code that works fine on your computer to someone else they get thrown errors while executing it. This can have various reasons, such as a different operating system, a different version of R or R packages. Maybe they don't even have R on their PC and don't want to go through the process of installing it, but still want to run your code. Docker is solving those problems.

A Docker container can be understood as a virtual machine running on your computer. With docker, you can create a virtual environment, so-called images, and in our case install the right R version and packages. Someone wanting to reproduce your code just has to download the image and can easily run the virtual machine with the right R version and Packages pre-installed.

In short, you would use Docker because:

-it allows you to solve dependencies problems (including the operating system and R package versions).

-it makes sure that your Projects are reproducible for eternity. Because the Versions of the OS, R, and the additional packages stay the same in the Docker container. Whenever you want to restart the project, the environment configuration remains the same. Docker is just like a time capsule to take you back.

-Accessibility: a docker image can be easily pulled and run locally, and it saves you from installing R and all the packages.

## workflow for pulling down the treat image and run it locally:

Precondition:

you have installed Docker, if not here are installation tutorials:

Download Tutorial for Windows:

https://www.youtube.com/watch?v=5nX8U8Fz5S0

Download Tutorial for MacOS (min 12:18):

https://youtu.be/pTFZFxd4hOI?t=738

once docker is installed, check the Docker settings to make sure that you have at least 2 CPUs, 4 GB of memory.

You also need WRDS access to Compustat (North America and Global) to reproduce the analysis.

Workflow:

1. Issue the following command into your terminal to pull the image from Docker Hub and run it in your environment:
`docker run -d -p 8787:8787 -e PASSWORD=password --name (not sure)`

2. Open your browser and point it to: [http://localhost:8787](http://localhost:8787/)

3. Login with username "rstudio" and the password "password"

4. Enter WRDS login Data into the "config.csv" like this:

```
wrds_user, 'yourusername', wrds_pwd, 'yourpassword',
```

5. Go to Rstudio in your browser and click on Build on the upper right side of your screen -> click Build all.

The script is now running and it can take some time. Eventually, you will be greeted with the two files in the output directory: "paper.pdf" and "presentation.pdf".

## How could I start with docker?

an introduction of Docker in 100 seconds:

https://www.youtube.com/watch?v=Gjnup-PuquQ&ab_channel=Fireship