-
Notifications
You must be signed in to change notification settings - Fork 239
138 lines (124 loc) · 4.43 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: build-image
on:
workflow_call:
inputs:
image-name:
required: true
type: string
build-context:
required: true
type: string
dockerfile:
required: true
type: string
r-version:
required: true
type: string
parent-image:
required: false
default: ''
type: string
model-version:
required: false
default: ''
type: string
platforms:
required: false
default: "linux/amd64"
type: string
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: lowercase image name
id: name
run: echo "image_name=$(echo ${{ inputs.image-name }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: set PARENT_IMAGE only if specified
id: parent
shell: bash
run: |
REGISTRY=$(
[[ ${{ github.event_name }} == 'pull_request' ]] &&
echo "ghcr.io/${{ github.actor }}/${{ github.repository }}" ||
echo "docker.io/pecan")
echo "PARENT_IMAGE_IF_SET=$(
[[ -n '${{ inputs.parent-image }}' ]] &&
echo "PARENT_IMAGE=${REGISTRY}/"'${{ inputs.parent-image }}'
)" >> $GITHUB_OUTPUT
- name: set MODEL_VERSION only if specified
id: modelver
shell: bash
run: |
echo "MODEL_VERSION_IF_SET=$(
[[ -n '${{ inputs.model-version }}' ]] &&
echo 'MODEL_VERSION=${{ inputs.model-version }}'
)" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
# create metadata for image
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
name=ghcr.io/${{ github.actor }}/${{ github.repository }}/${{ steps.name.outputs.image_name }}
name=pecan/${{ steps.name.outputs.image_name }},enable=${{ github.event_name != 'pull_request' }}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
# setup docker build
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Inspect Builder
run: |
echo "Name: ${{ steps.buildx.outputs.name }}"
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
echo "Status: ${{ steps.buildx.outputs.status }}"
echo "Flags: ${{ steps.buildx.outputs.flags }}"
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
# login to registries
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# build the docker images
- name: Build and push ${{ steps.name.outputs.image_name }}
uses: docker/build-push-action@v6
with:
context: ${{ inputs.build-context }}
file: ${{ inputs.dockerfile }}
push: true
platforms: ${{ inputs.platforms }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.meta.outputs.version }}
IMAGE_VERSION=${{ steps.meta.outputs.version }}
PECAN_VERSION=${{ steps.meta.outputs.version }}
R_VERSION=${{ inputs.r-version }}
${{ steps.parent.outputs.PARENT_IMAGE_IF_SET }}
${{ steps.modelver.outputs.MODEL_VERSION_IF_SET }}
GITHUB_PAT=${{ secrets.GITHUB_TOKEN }}
PECAN_GIT_BRANCH=${{ github.head_ref || github.ref_name }}
PECAN_GIT_CHECKSUM=${{ github.sha }}
PECAN_GIT_DATE=${{ github.event.repository.updated_at }}