-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaction.yml
154 lines (141 loc) · 5.47 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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: Login to registry - to fail in the beggining of action if creds are incorrect
uses: redhat-actions/podman-login@v1
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.registry_username }}
password: ${{ inputs.registry_token }}
- 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: Set up QEMU
if: inputs.archs != 'amd64'
uses: docker/setup-qemu-action@v3
- name: Build image
if: steps.check_exclude_file.outputs.files_exists == 'false'
id: build-image
# https://github.com/marketplace/actions/buildah-build
uses: redhat-actions/buildah-build@v2
with:
dockerfiles: ${{ inputs.dockerfile }}
image: ${{ inputs.image_name}}
archs: ${{ inputs.archs }}
context: ${{ inputs.docker_context }}
tags: ${{ steps.tags.outputs.tags }}
- name: Push image to Quay.io/${{ inputs.registry_namespace }} namespace
if: steps.check_exclude_file.outputs.files_exists == 'false'
id: push-to-registry
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ inputs.registry }}/${{ inputs.registry_namespace }}
username: ${{ inputs.registry_username }}
password: ${{ inputs.registry_token }}
- name: Add action path to path, so that local files are accessible
run: echo "${{ github.action_path }}" >> "$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 }}."