Skip to content

Deploy Docker Image 🐳 #2

Deploy Docker Image 🐳

Deploy Docker Image 🐳 #2

name: Deploy Docker Image 🐳
on:
# for each change in DESCRIPTION/Dockerfile (main branch) this job will be triggered
push:
branches:
- main
paths:
- DESCRIPTION
- Dockerfile
# give possibility to run it manually
workflow_dispatch:
permissions: write-all
env:
REGISTRY: ghcr.io
IMAGE_NAME: r-pkg-example
R_VERSION: 4.3
PLATFORMS: linux/amd64
concurrency:
group: deploy-docker-image-${{ github.ref }} # manage concurrency (if there are two jobs deploy-docker-image on the same branch, one wwill be cancelled)
cancel-in-progress: true
jobs:
build-docker-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
# Install QEMU and buildx for multi platform images (see https://docs.docker.com/build/building/multi-platform/)
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# Set up buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
id: buildx
with:
install: true
# Set up cache (it will accelerate docker builds reusing the cache)
- name: Cache Docker layers ♻️
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.IMAGE_NAME }}
restore-keys: |
${{ runner.os }}-buildx-${{ env.IMAGE_NAME }}
- name: Log in to the Container registry 🗝
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image 🏗
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
push: true
tags: "${{ env.REGISTRY }}/philippbaessler/${{ env.IMAGE_NAME }}:${{ env.R_VERSION }}"
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
platforms: ${{ env.PLATFORMS }}
- name: Move cache ♻️
run: |
rm -rf /tmp/.buildx-cache
if [ -f /tmp/.buildx-cache-new ]
then {
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
}
fi
shell: bash