Skip to content

Commit 3fbd4a4

Browse files
committed
Add the ability to optionally push images (SOFTWARE-5013)
1 parent 4850922 commit 3fbd4a4

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

action.yml

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
name: 'Build Container Action'
2-
3-
description: 'Builds and caches the image'
1+
name: 'OSG Build Container Action'
2+
description: 'Builds and optionally caches/pushes the image'
43

54
inputs:
65
osg_series:
@@ -41,6 +40,27 @@ inputs:
4140
Store built images in GitHub the GitHub cache (default: true)
4241
required: false
4342
default: true
43+
push_image:
44+
description: >-
45+
Push the built image to a container registry (default: false).
46+
Requires 'registry_url', 'registry_user', and 'registry_pass'
47+
arguments.
48+
required: false
49+
default: false
50+
registry_url:
51+
description: >
52+
URL for the target container registry
53+
required: false
54+
registry_user:
55+
description: >-
56+
Username for the target container registry. Should be kept in
57+
some form of GitHub secret.
58+
required: false
59+
registry_pass:
60+
description: >-
61+
Password for the target container registry. Should be kept in
62+
some form of GitHub secret.
63+
required: false
4464

4565
outputs:
4666
tags:
@@ -60,15 +80,22 @@ runs:
6080
steps:
6181
- uses: actions/checkout@v2
6282

83+
- name: Check input requirements
84+
if: inputs.push_image && inputs.registry_url && inputs.registry_user && ! inputs.registry_pass
85+
shell: bash
86+
run: |
87+
echo "::error ::'push_image' specified but missing 'registry_url', 'registry_user', or 'registry_pass'"
88+
exit 1
89+
6390
- id: generate-tags
6491
name: Generate tag list
6592
shell: bash
6693
env:
94+
REGISTRY: ${{ inputs.registry_url }}
6795
OSG_REPO: ${{ inputs.osg_repo }}
6896
OSG_SERIES: ${{ inputs.osg_series }}
6997
OUTPUT_IMAGE: ${{ inputs.output_image }}
7098
run: |
71-
TIMESTAMP=$(date +%Y%m%d-%H%M)
7299
DEFAULT_TAG=${OSG_SERIES}-${OSG_REPO}
73100
74101
if [[ -n "${OUTPUT_IMAGE}" ]]; then
@@ -86,6 +113,12 @@ runs:
86113
exit 1
87114
fi
88115
116+
# If we're pushing images, we need to prepend the registry for the build-push-action
117+
if [[ -n "${REGISTRY}" ]]; then
118+
IMAGE_NAME=${REGISTRY}/${IMAGE_NAME}
119+
fi
120+
121+
TIMESTAMP=$(date +%Y%m%d-%H%M)
89122
TIMESTAMP_IMAGE=${IMAGE_NAME}-${TIMESTAMP}
90123
91124
echo "tag_list=${IMAGE_NAME},${TIMESTAMP_IMAGE}" >> ${GITHUB_OUTPUT}
@@ -95,10 +128,18 @@ runs:
95128
- name: Set up Docker Buildx
96129
uses: docker/setup-buildx-action@v1
97130

131+
- name: Container Registry Login
132+
if: inputs.push_image
133+
uses: docker/login-action@v1
134+
with:
135+
registry: ${{ inputs.registry_url }}
136+
username: ${{ inputs.registry_user }}
137+
password: ${{ inputs.registry_pass }}
138+
98139
- name: Build and push Docker images
99140
uses: docker/[email protected]
100141
with:
101-
push: false
142+
push: ${{ inputs.push_image }}
102143
context: ${{ inputs.context }}
103144
build-args: |
104145
BASE_YUM_REPO=${{ inputs.osg_repo }}

0 commit comments

Comments
 (0)