-
Notifications
You must be signed in to change notification settings - Fork 77
/
action.yaml
126 lines (126 loc) · 5.11 KB
/
action.yaml
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
#
# Copyright (C) 2019-2024 vdaas.org vald team <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: "Build Docker images"
description: "A action to build Docker images and publish them"
inputs:
target:
description: "Build target"
required: true
default: "base"
builder:
description: "Buildx builder name"
required: true
default: ""
platforms:
description: "If it is specified, specified platforms will be used."
required: false
default: ""
outputs:
IMAGE_NAME:
description: "Image name"
value: ${{ steps.image_name.outputs.IMAGE_NAME }}
ALTER_IMAGE_NAME:
description: "Alter image name"
value: ${{ steps.image_name.outputs.ALTER_IMAGE_NAME }}
PRIMARY_TAG:
description: "Primary tag"
value: ${{ steps.determine_tag_name.outputs.PRIMARY_TAG }}
PLATFORMS:
description: "Target platforms"
value: ${{ steps.determine_platforms.outputs.PLATFORMS }}
EXTRA_TAGS:
description: "Extra tags"
value: ${{ steps.add_extra_tags.outputs.EXTRA_TAGS }}
runs:
using: "composite"
steps:
- name: Image name
shell: bash
id: image_name
run: |
image_name=`make docker/name/${TARGET}`
alter_org=`make docker/name/org/alter`
alter_image_name=`make ORG="${alter_org}" docker/name/${TARGET}`
echo "IMAGE_NAME is: ${image_name}"
echo "ALTER_IMAGE_NAME is: ${alter_image_name}"
echo "IMAGE_NAME=${image_name}" >> $GITHUB_OUTPUT
echo "ALTER_IMAGE_NAME=${alter_image_name}" >> $GITHUB_OUTPUT
env:
TARGET: ${{ inputs.target }}
- name: Determine tag name
id: determine_tag_name
uses: ./.github/actions/determine-docker-image-tag
- name: Determine platforms
shell: bash
id: determine_platforms
run: |
if [ "${TARGET_PLATFORMS}" = "" ]; then
if [[ "$GITHUB_REF" =~ ^refs/heads/main$ ]] || [[ "$GITHUB_REF" =~ ^refs/heads/master$ ]] || [[ "$GITHUB_REF" =~ ^refs/heads/release.* ]] || [[ "${PRIMARY_TAG}" == "nightly" ]]; then
platforms=`make docker/platforms`
elif [ "${{ github.event_name }}" = "pull_request" ]; then
platforms="linux/amd64"
elif [ "${{ github.event_name }}" = "pull_request_target" ]; then
platforms="linux/amd64"
else
platforms=`make docker/platforms`
fi
else
platforms="${TARGET_PLATFORMS}"
fi
echo "PLATFORMS is determined: ${platforms}"
echo "PLATFORMS=${platforms}" >> $GITHUB_OUTPUT
env:
TARGET_PLATFORMS: ${{ inputs.platforms }}
- name: Add extra tags
shell: bash
id: add_extra_tags
run: |
extra_tags="-t ${ALTER_IMAGE_NAME}:${PRIMARY_TAG}"
if [[ "$GITHUB_REF" =~ ^refs/tags/.* ]]; then
latest_tags="-t ${IMAGE_NAME}:latest -t ${ALTER_IMAGE_NAME}:latest"
extra_tags="${extra_tags} ${latest_tags}"
fi
if [[ "$GITHUB_REF" =~ ^refs/heads/main$ ]] || [[ "$GITHUB_REF" =~ ^refs/heads/master$ ]] || [[ "$GITHUB_REF" =~ ^refs/heads/release.* ]] || [[ "${PRIMARY_TAG}" == "nightly" ]]; then
commit_hash=${GITHUB_SHA::8}
hash_tags="-t ${IMAGE_NAME}:${commit_hash} -t ${ALTER_IMAGE_NAME}:${commit_hash}"
extra_tags="${extra_tags} ${hash_tags}"
fi
echo "EXTRA_TAGS is determined: ${extra_tags}"
echo "EXTRA_TAGS=${extra_tags}" >> $GITHUB_OUTPUT
env:
IMAGE_NAME: ${{ steps.image_name.outputs.IMAGE_NAME }}
ALTER_IMAGE_NAME: ${{ steps.image_name.outputs.ALTER_IMAGE_NAME }}
PRIMARY_TAG: ${{ steps.determine_tag_name.outputs.PRIMARY_TAG }}
- name: Build and Push
shell: bash
id: build_and_push
run: |
make \
REMOTE="true" \
DOCKER="docker" \
BUILDKIT_INLINE_CACHE=0 \
DOCKER_OPTS="--platform ${PLATFORMS} --builder ${BUILDER} ${LABEL_OPTS} --label org.opencontainers.image.version=${PRIMARY_TAG} --label org.opencontainers.image.title=${TARGET}" \
EXTRA_ARGS="${EXTRA_TAGS}" \
TAG="${PRIMARY_TAG}" \
docker/build/${TARGET}
env:
TARGET: ${{ inputs.target }}
DOCKER_BUILDKIT: "1"
PLATFORMS: ${{ steps.determine_platforms.outputs.PLATFORMS }}
BUILDER: ${{ inputs.builder }}
LABEL_OPTS: "--label org.opencontainers.image.url=${{ github.event.repository.html_url }} --label org.opencontainers.image.source=${{ github.event.repository.html_url }} --label org.opencontainers.image.revision=${{ github.sha }}"
EXTRA_TAGS: ${{ steps.add_extra_tags.outputs.EXTRA_TAGS }}
PRIMARY_TAG: ${{ steps.determine_tag_name.outputs.PRIMARY_TAG }}