-
Notifications
You must be signed in to change notification settings - Fork 6
78 lines (68 loc) · 2.17 KB
/
docker-build-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
name: docker-build-image
on:
push:
branches:
- 'main'
tags:
- "v*"
pull_request:
branches:
- 'main'
env:
CACHE_IMAGE: ghcr.io/r-geoflow/geoflow-shiny-cache
DOCKER_BUILDKIT: 1
RENV_PATHS_ROOT: ~/.cache/R/renv
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/r-geoflow/geoflow-shiny
flavor: latest=true
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
- name: Login to image repository
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: image=moby/buildkit:master,network=host
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build Docker image
run: |
docker buildx build \
--cache-from type=registry,ref=$CACHE_IMAGE:latest \
--cache-to type=registry,ref=$CACHE_IMAGE:latest,mode=max \
--tag ghcr.io/r-geoflow/geoflow-shiny:latest \
--build-arg RENV_PATHS_ROOT=${{ env.RENV_PATHS_ROOT }} \
--output type=docker,dest=/tmp/docker-image.tar \
.
- name: Load Docker image
if: github.ref_type == 'tag'
run: |
docker load -i /tmp/docker-image.tar
- name: Conditional push Docker image
if: github.ref_type == 'tag'
run: |
TAG_NAME=$(basename ${GITHUB_REF})
docker tag ghcr.io/r-geoflow/geoflow-shiny:latest ghcr.io/r-geoflow/geoflow-shiny:${TAG_NAME}
docker push ghcr.io/r-geoflow/geoflow-shiny:latest
docker push ghcr.io/r-geoflow/geoflow-shiny:${TAG_NAME}