Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Update versioning strategy and doc #17

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
156 changes: 78 additions & 78 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
name: CI

on:
schedule:
- cron: '0 10 * * 0' # every Sunday at 10am
push:
branches:
- main
- develop
tags:
- '*.*.*'
pull_request:
Expand All @@ -19,39 +16,10 @@ env:
default_branch: main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Lint Dockerfiles
uses: docker://hadolint/hadolint:latest
with:
entrypoint: hadolint
args: Dockerfile
- name: Check that packages in requirements.txt files are in asc order
run: |
sort -f --check conda/sage-bionetworks/requirements.txt

test:
needs: [lint]
configure:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set environment variables
run: |
cp .env.example .env
export $(grep -v '^#' .env | xargs -d '\n')
- name: Validate docker-compose.yml
run: docker-compose -f docker-compose.yml config >/dev/null

build-and-publish:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Prepare build
id: prep
- name: Create configuration
run: |
DOCKER_IMAGE=${{ env.docker_repository }}
VERSION=noop
Expand All @@ -62,8 +30,7 @@ jobs:
PUSH_IMAGE=true
PUSH_NOTEBOOKS=true
elif [[ $GITHUB_REF == refs/tags/* ]]; then
# VERSION=${GITHUB_REF#refs/tags/}
VERSION=$(cat RSTUDIO_VERSION)
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
Expand All @@ -77,25 +44,70 @@ jobs:
PUSH_NOTEBOOKS=true
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
if [[ $VERSION == "edge" ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:edge-${GITHUB_SHA::8}"
elif [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR}"
TAGS="$TAGS,${DOCKER_IMAGE}:${MAJOR}"
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}-${GITHUB_SHA::8}"
PUSH_IMAGE=true
PUSH_NOTEBOOKS=true
# elif [ "${{ github.event_name }}" = "push" ]; then
# TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=version_major::${MAJOR}
echo ::set-output name=version_minor::${MINOR}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=push_image::${PUSH_IMAGE}
echo ::set-output name=push_notebooks::${PUSH_NOTEBOOKS}
printf "%s\n" \
"version=${VERSION}" \
"version_major=${MAJOR}" \
"version_minor=${MINOR}" \
"tags=${TAGS}" \
"created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
"push_image=${PUSH_IMAGE}" \
"push_notebooks=${PUSH_NOTEBOOKS}" | tee -a .github_env

- name: Upload .github_env
uses: actions/upload-artifact@v2
with:
name: GITHUB_ENV
path: .github_env

lint:
needs: [configure]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Lint Dockerfiles
uses: docker://hadolint/hadolint:latest
with:
entrypoint: hadolint
args: Dockerfile
- name: Check that packages in requirements.txt files are in asc order
run: |
sort -f --check conda/sage-bionetworks/requirements.txt

test:
needs: [lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set environment variables
run: |
cp .env.example .env
export $(grep -v '^#' .env | xargs -d '\n')
- name: Validate docker-compose.yml
run: docker-compose -f docker-compose.yml config >/dev/null

build-and-publish:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Download .github_env
uses: actions/download-artifact@v2
with:
name: GITHUB_ENV
path: .

- name: Restore $GITHUB_ENV
run: cat .github_env >> $GITHUB_ENV

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand Down Expand Up @@ -128,8 +140,6 @@ jobs:
push: false
platforms: linux/amd64
tags: rstudio-cached:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

- name: Create .env
run: |
Expand All @@ -144,69 +154,59 @@ jobs:
run: |
docker run --rm \
--env-file .env \
-v $(pwd)/notebooks:/data \
-v $(pwd):/project \
rstudio-cached:latest \
render /data/examples/*.Rmd
render /project/notebooks/*.Rmd

- name: Push image
if: steps.prep.outputs.push_image == 'true'
if: env.push_image == 'true'
id: docker_push
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.prep.outputs.tags }}
platforms: linux/amd64
tags: ${{ env.tags }}
labels: |
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.created=${{ env.created }}
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.version=${{ env.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.name }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

- name: Update Docker Hub repository description
if: steps.prep.outputs.push_image == 'true'
uses: peter-evans/dockerhub-description@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: ${{ env.docker_repository }}

- name: Prepare to publish HTML notebooks to GH Pages
if: steps.prep.outputs.push_notebooks == 'true'
if: env.push_notebooks == 'true'
run: |
git clone ${{ env.clone_url }} \
--branch gh-pages --single-branch gh-pages

# Update gh-pages: version specified
NOTEBOOKS_TARGET_DIR=gh-pages/${{ steps.prep.outputs.version }}/notebooks
NOTEBOOKS_TARGET_DIR=gh-pages/${{ env.version }}/notebooks
rm -fr ${NOTEBOOKS_TARGET_DIR}
mkdir -p ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/examples/*.html ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/*.html ${NOTEBOOKS_TARGET_DIR}

# Update gh-pages: latest, major, and minor versions
if [ ! -z "${{ steps.prep.outputs.version_major }}" ]; then
if [ ! -z "${{ env.version_major }}" ]; then
# Update latest (e.g. "1.2.3" => "latest")
NOTEBOOKS_TARGET_DIR=gh-pages/latest/notebooks
rm -fr ${NOTEBOOKS_TARGET_DIR}
mkdir -p ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/examples/*.html ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/*.html ${NOTEBOOKS_TARGET_DIR}

# Update major version (e.g. "1.2.3" => "1")
NOTEBOOKS_TARGET_DIR=gh-pages/${{ steps.prep.outputs.version_major }}/notebooks
NOTEBOOKS_TARGET_DIR=gh-pages/${{ env.version_major }}/notebooks
rm -fr ${NOTEBOOKS_TARGET_DIR}
mkdir -p ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/examples/*.html ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/*.html ${NOTEBOOKS_TARGET_DIR}

# Update minor version (e.g. "1.2.3" => "1.2")
NOTEBOOKS_TARGET_DIR=gh-pages/${{ steps.prep.outputs.version_minor }}/notebooks
NOTEBOOKS_TARGET_DIR=gh-pages/${{ env.version_minor }}/notebooks
rm -fr ${NOTEBOOKS_TARGET_DIR}
mkdir -p ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/examples/*.html ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/*.html ${NOTEBOOKS_TARGET_DIR}
fi
cd gh-pages
git config --local user.email "[email protected]"
Expand All @@ -217,7 +217,7 @@ jobs:
# that.

- name: Push to gh-pages
if: steps.prep.outputs.push_notebooks == 'true'
if: env.push_notebooks == 'true'
uses: ad-m/github-push-action@master
with:
branch: gh-pages
Expand Down
49 changes: 24 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# RStudio
# Sage Bionetworks Docker image for RStudio

[![GitHub Release](https://img.shields.io/github/release/Sage-Bionetworks/docker-rstudio.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/Sage-Bionetworks/docker-rstudio/releases)
[![GitHub CI](https://img.shields.io/github/workflow/status/Sage-Bionetworks/docker-rstudio/CI.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/Sage-Bionetworks/docker-rstudio)
[![GitHub License](https://img.shields.io/github/license/Sage-Bionetworks/docker-rstudio.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/Sage-Bionetworks/docker-rstudio/blob/main/LICENSE)
[![Docker Pulls](https://img.shields.io/docker/pulls/sagebionetworks/rstudio.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=pulls&logo=docker)](https://hub.docker.com/r/sagebionetworks/rstudio)

Docker image for analyses using RStudio and Python-Conda

## Introduction

The motivation for this project is to encourage the use of portable development
Expand Down Expand Up @@ -58,10 +56,10 @@ by the [CI/CD workflow of this repository](.github/workflows/ci.yml).

Rmd Notebook | Description | HTML Notebook
-------- | ----------- | -------------
[notebook.Rmd](notebooks/examples/notebook.Rmd) | Default RStudio notebook. | [![HTML notebook](https://img.shields.io/badge/latest-blue.svg?color=1283c3&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://sage-bionetworks.github.io/rstudio/latest/notebooks/notebook.html)
[r-and-python.Rmd](notebooks/examples/r-and-python.Rmd) | Shows how to use R and Python together. | [![HTML notebook](https://img.shields.io/badge/latest-blue.svg?color=1283c3&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://sage-bionetworks.github.io/rstudio/latest/notebooks/r-and-python.html)
[sagethemes.Rmd](notebooks/examples/sagethemes.Rmd) | Example notebook provided by the R library [sagethemes]. | [![HTML notebook](https://img.shields.io/badge/latest-blue.svg?color=1283c3&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://sage-bionetworks.github.io/rstudio/latest/notebooks/sagethemes.html)
[synapse.Rmd](notebooks/examples/synapse.Rmd) | Shows how to interact with Synapse API. | [![HTML notebook](https://img.shields.io/badge/latest-blue.svg?color=1283c3&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://sage-bionetworks.github.io/rstudio/latest/notebooks/synapse.html)
[notebook.Rmd](notebooks/notebook.Rmd) | Default RStudio notebook. | [![HTML notebook](https://img.shields.io/badge/latest-blue.svg?color=1283c3&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://sage-bionetworks.github.io/docker-rstudio/latest/notebooks/notebook.html)
[r-and-python.Rmd](notebooks/r-and-python.Rmd) | Shows how to use R and Python together. | [![HTML notebook](https://img.shields.io/badge/latest-blue.svg?color=1283c3&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://sage-bionetworks.github.io/docker-rstudio/latest/notebooks/r-and-python.html)
[sagethemes.Rmd](notebooks/sagethemes.Rmd) | Example notebook provided by the R library [sagethemes]. | [![HTML notebook](https://img.shields.io/badge/latest-blue.svg?color=1283c3&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://sage-bionetworks.github.io/docker-rstudio/latest/notebooks/sagethemes.html)
[synapse.Rmd](notebooks/synapse.Rmd) | Shows how to interact with Synapse API. | [![HTML notebook](https://img.shields.io/badge/latest-blue.svg?color=1283c3&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://sage-bionetworks.github.io/docker-rstudio/latest/notebooks/synapse.html)

> Important: Please make sure when you write your own notebooks that no
> sensitive information ends up being publicly available. Please check with the
Expand All @@ -70,15 +68,19 @@ Rmd Notebook | Description | HTML Notebook

## Usage

1. Create and edit the configuration file. You can initially start RStudio using
1. Clone this GitHub repository.
2. Create and edit the configuration file. You can initially start RStudio using
this configuration as-is.

cp .env.example .env

2. Start RStudio. Add the option `-d` or `--detach` to run in the background.
3. Start RStudio. Add the option `-d` or `--detach` to run in the background.

docker compose up

> If the command `docker compose` is not available for your system, [install
> docker-compose] and use the command `docker-compose`.

RStudio is now available at http://localhost. On the login page, enter the
default username (`rstudio`) and the password specified in `.env`.

Expand Down Expand Up @@ -214,9 +216,9 @@ HTML notebook that will be saved to the same directory with the extension
```console
docker run --rm \
--env-file .env \
-v $(pwd)/notebooks:/data \
-v $(pwd):/project \
sagebionetworks/rstudio:4.1.0 \
render /data/examples/*.Rmd
render /project/notebooks/*.Rmd
```

## Versioning
Expand All @@ -227,23 +229,20 @@ This repository uses [semantic versioning] to track the releases of this
project. This repository uses "non-moving" GitHub tags, that is, a tag will
always point to the same git commit once it has been created.

### Docker tags
### Docker and GitHub Pages tags

The artifact published by this repository is the Docker image
[sagebionetworks/rstudio]. The versions of the image are aligned with the
versions of R/RStudio, not the GitHub tags of this repository.
The artifact published by this repository are HTML notebooks published to GitHub
Pages and the Docker image [sagebionetworks/rstudio]. The tags of these
artifacts are aligned with the GitHub tags.

The table below describes the image tags available.

| Tag name | Moving | Description
|---------------------------------|--------|------------
| `latest` | Yes | Latest stable release.
| `edge` | Yes | Lastest commit made to the default branch.
| `weekly` | Yes | Weekly release from the default branch.
| `<major>` | Yes | Latest stable major release of R/RStudio.
| `<major>.<minor>` | Yes | Latest stable minor release of R/RStudio.
| `<major>.<minor>.<patch>` | Yes | Latest stable patch release of R/RStudio.
| `<major>.<minor>.<patch>-<sha>` | No | Same as above but with the reference to the git commit.
| Tag name | Description | Moving
|---------------------------------|--------------------------------------------------------|-------
| `latest` | Latest stable release. | Yes
| `edge` | Lastest commit made to the default branch. | Yes
| `edge-<sha>` | Same as above with the reference to the git commit. | No
| `<major>.<minor>.<patch>` | Latest stable patch release `<major>.<minor>.<patch>`. | No

You should avoid using a moving tag like `latest` when deploying containers in
production, because this makes it hard to track which version of the image is
Expand Down Expand Up @@ -283,4 +282,4 @@ Thinking about contributing to this project? Get started by reading our
[Sage-Bionetworks-Challenges/challenge-analysis]: https://github.com/Sage-Bionetworks-Challenges/challenge-analysis
[Sage-Bionetworks/docker-rstudio]: https://github.com/Sage-Bionetworks/docker-rstudio
[Docker Engine]: https://docs.docker.com/engine/install/
[Docker Compose]: https://docs.docker.com/compose/install/
[install docker-compose]: https://docs.docker.com/compose/install/
File renamed without changes.
File renamed without changes.