Skip to content

Publish RStudio Docker image #45

Publish RStudio Docker image

Publish RStudio Docker image #45

name: Publish RStudio Docker image
# To MaastrichtU-IDS GitHub Container Registry
# https://github.com/orgs/MaastrichtU-IDS/packages
on:
workflow_dispatch:
push:
branches:
- main
# - dev
paths:
- 'Dockerfile'
- '.github/workflows/publish-docker.yml'
schedule:
- cron: '0 3 * * 1'
# Monday at 3:00 GMT+1
# env:
# IMAGE_PUSHED: ghcr.io/maastrichtu-ids/rstudio:latest
# BASE_IMAGE: rocker/verse:latest
jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
actions: write
packages: write
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.actor}}
# password: ${{secrets.CONTAINER_REGISTRY_GITHUB_TOKEN}}
password: ${{secrets.GITHUB_TOKEN}}
- name: Generate image ID and version
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/rstudio
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Build and publish RStudio Docker image
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
# build-args: BASE_IMAGE=${{ env.BASE_IMAGE }}
builder: ${{ steps.buildx.outputs.name }}
push: true
# tags: ${{ env.IMAGE_PUSHED }}
tags: ${{ env.IMAGE_ID }}:${{ env.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
# - name: Log into GitHub Container Registry
# # TODO: Create a token with `read:packages` and `write:packages` scopes
# # And save it as an Actions secret CONTAINER_REGISTRY_GITHUB_TOKEN
# run: echo "${{ secrets.CONTAINER_REGISTRY_GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# - name: Build image
# run: docker build . --file Dockerfile --tag $IMAGE_PUSHED
# - name: Push image to GitHub Container Registry
# run: |
# docker push $IMAGE_PUSHED