forked from user-workshop-cicd/r.package.example
-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (70 loc) · 2.29 KB
/
build-docker-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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 }}/${{ github.repository_owner }}/${{ 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