forked from sclorg/build-and-push-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
127 lines (117 loc) · 4.28 KB
/
action.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
name: 'Build and push images to registry'
description: 'This GitHub Action builds a container image and pushes it to the specified registry.'
author: 'RHSCL team'
branding:
icon: circle
color: blue
inputs:
registry:
description: 'Registry to push container image to'
required: true
registry_namespace:
description: 'Namespace of the registry, where the image would be pushed'
required: true
image_name:
description: 'How the resulting image will be named'
required: true
registry_username:
description: 'Login to specified registry'
required: true
registry_token:
description: 'Token to access the specified registry'
required: true
tag:
description: 'Tag of the built image'
required: false
default: ''
archs:
description: 'Label the image with this architecture. For multiple architectures, seperate them by a comma'
required: false
default: "amd64"
dockerfile:
description: 'Dockerfile to build the image with a relative path'
required: false
default: 'Dockerfile'
docker_context:
description: 'Docker build context'
required: false
default: '.'
use_default_tags:
description: 'Tags built image with default tags - SHA, latest, current date'
required: false
default: 'true'
readme:
description: 'If path to readme is set, the readme is updated to the registry. Only quay.io is supported.'
required: false
default: ''
quay_application_token:
description: 'Application token is used for updating description for images'
required: false
default: ''
runs:
using: "composite"
steps:
- name: Checkout git
uses: actions/checkout@v4
with:
submodules: true
- name: Prepare needed variables
shell: bash
id: vars
run: |
tmp="${{ inputs.dockerfile }}"
dockerfile="${tmp#*/}"
distribution="${dockerfile#*Dockerfile.}"
# if the Dockerfile name does not have dist. suffix we use CentOS7
[[ "$distribution" == Dockerfile ]] && distribution="centos7"
echo "cur_date=$(date +'%Y%m%d')" >> "$GITHUB_OUTPUT"
echo "dockerfile_path=${tmp%/*}" >> "$GITHUB_OUTPUT"
echo "distribution=${distribution}" >> "$GITHUB_OUTPUT"
# exclusion mechanism.
# when .exlude-<distribution> file in Dockerfile folder exists,
# the particular image would not be built
- name: Check if .exclude-${{ steps.vars.outputs.distribution }} is present in ${{ steps.vars.outputs.dockerfile_path }} directory
id: check_exclude_file
# https://github.com/marketplace/actions/file-existence
uses: andstor/file-existence-action@v3
with:
files: "${{ steps.vars.outputs.dockerfile_path }}/.exclude-${{ steps.vars.outputs.distribution }}"
- name: Check if ${{ inputs.dockerfile }} is present
if: steps.check_exclude_file.outputs.files_exists == 'false'
id: check_dockerfile_file
# https://github.com/marketplace/actions/file-existence
uses: andstor/file-existence-action@v3
with:
files: "${{ inputs.dockerfile }}"
fail: true # fails the Action if Dockerfile is missing
- name: Prepare tags
shell: bash
id: tags
run: |
tags="${{ inputs.tag }}"
if [ ${{ inputs.use_default_tags }} == true ]; then
tags="$tags latest ${{ steps.vars.outputs.cur_date }} ${{ github.sha }}"
fi
echo "tags=$tags" >> "$GITHUB_OUTPUT"
- name: Add action path to path, so that local files are accessible
run: |
echo "${{ github.action_path }}" >> "$GITHUB_PATH"
ls
pwd
echo $GITHUB_PATH
cat $GITHUB_PATH
ls $(cat $GITHUB_PATH)
shell: bash
- name: Upload README to quay.io registry
if: inputs.readme != '' && inputs.quay_application_token != ''
env:
QUAY_API_TOKEN: ${{ inputs.quay_application_token }}
IMAGE_NAME: ${{ inputs.image_name}}
REGISTRY_NAMESPACE: ${{ inputs.registry_namespace }}
README_PATH: ${{ inputs.readme }}
run: update_quay_description.py
shell: bash
- name: Print image url
if: steps.check_exclude_file.outputs.files_exists == 'false'
shell: bash
run: echo "Image ${{ inputs.image_name }} has been pushed to ${{ steps.push-to-registry.outputs.registry-paths }}."