Skip to content

Commit c528b19

Browse files
committed
Consolidate output image inputs; add 'cache_key' output
(SOFTWARE-5013)
1 parent 27a929a commit c528b19

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

action.yml

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ name: 'Build Container Action'
33
description: 'Builds and caches the image'
44

55
inputs:
6-
tag_name:
7-
description: 'user specified tag name'
8-
required: false
9-
default: ''
106
osg_series:
117
description: >-
128
OSG release series used to install packages, intended for use
@@ -33,8 +29,11 @@ inputs:
3329
description: 'Path to container files, including Dockerfile'
3430
required: false
3531
default: '.'
36-
image_name:
37-
description: 'Name of the image to build, e.g. "opensciencegrid/software-base"'
32+
output_image:
33+
description: >-
34+
Name of the image and tag for the resultant image build
35+
following the <name>/<tag> format,
36+
e.g. "opensciencegrid/osgvo-docker-pilot:3.6-release"
3837
required: false
3938
default: ''
4039

@@ -44,39 +43,49 @@ outputs:
4443
Image name, including timestamp tag. Intended for use as a unique,
4544
immutable identifier. For example,
4645
"opensciencegrid/osgvo-docker-pilot:3.6-release-20221207-1729"
47-
value: ${{ steps.create_timestamp_tag.outputs.tags }}
46+
value: ${{ steps.generate-tags.outputs.ts_image }}
47+
cache_key:
48+
description: >-
49+
Key referencing the GitHub cache containing the layers of the
50+
built container image
51+
value: ${{ steps.generate-tags.outputs.cache_key }}
4852

4953
runs:
5054
using: "composite"
5155
steps:
5256
- uses: actions/checkout@v2
5357

54-
- id: generate-image-name
58+
- id: generate-tags
59+
name: Generate tag list
5560
shell: bash
61+
env:
62+
OSG_REPO: ${{ inputs.osg_repo }}
63+
OSG_SERIES: ${{ inputs.osg_series }}
64+
OUTPUT_IMAGE: ${{ inputs.output_image }}
5665
run: |
57-
if [[ -n "${{ inputs.image_name }}" ]]; then
58-
IMAGE_NAME="${{ inputs.image_name }}"
66+
TIMESTAMP=$(date +%Y%m%d-%H%M)
67+
DEFAULT_TAG=${OSG_SERIES}-${OSG_REPO}
68+
69+
if [[ -n "${OUTPUT_IMAGE}" ]]; then
70+
IMAGE_NAME=${OUTPUT_IMAGE%:*}
5971
elif [[ ${{ inputs.context }} == "." ]] || \
6072
[[ ${{ inputs.context }} == "./" ]]; then
6173
# Try to guess the image name from our docker repo naming conventions
6274
# E.g., opensciencegrid/docker-frontier-squid
63-
IMAGE_NAME=${GITHUB_REPOSITORY/opensciencegrid\/docker-//}
75+
IMAGE_NAME=${GITHUB_REPOSITORY/opensciencegrid\/docker-//}-${DEFAULT_TAG}
6476
elif [[ -d ${{ inputs.context }} ]]; then
6577
# Assume that the containing dir is the image name
66-
IMAGE_NAME=$(basename ${{ inputs.context }})
78+
IMAGE_NAME=$(basename ${{ inputs.context }})-${DEFAULT_TAG}
6779
else
68-
echo "No image_name provided and ${{ inputs.context }} is not a directory"
80+
echo "No output_image provided and ${{ inputs.context }} is not a directory"
6981
exit 1
7082
fi
71-
echo "::set-output name=image::${IMAGE_NAME,,}"
7283
73-
- id: create_timestamp_tag
74-
shell: bash
75-
run: echo "::set-output name=tags::${IMAGE}:${TAGNAME:-$DEFAULTTAG}-$(date +%Y%m%d-%H%M)"
76-
env:
77-
IMAGE: ${{ steps.generate-image-name.outputs.image }}
78-
TAGNAME: ${{ inputs.tag_name }}
79-
DEFAULTTAG : ${{ inputs.osg_series }}-${{ inputs.repo }}
84+
TIMESTAMP_IMAGE=${IMAGE_NAME}-${TIMESTAMP}
85+
86+
echo "tag_list=${IMAGE_NAME},${TIMESTAMP_IMAGE}" >> ${GITHUB_OUTPUT}
87+
echo "ts_image=${TIMESTAMP-IMAGE}" >> ${GITHUB_OUTPUT}
88+
echo "cache_key=$(tr ':/' '_' <<< $TIMESTAMP_IMAGE)_buildx_${GITHUB_SHA}" >> ${GITHUB_OUTPUT}
8089
8190
- name: Set up Docker Buildx
8291
uses: docker/setup-buildx-action@v1
@@ -90,12 +99,12 @@ runs:
9099
BASE_YUM_REPO=${{ inputs.osg_repo }}
91100
BASE_OS=${{ inputs.base_os }}
92101
BASE_OSG_SERIES=${{ inputs.osg_series }}
93-
TIMESTAMP_TAG=${{ steps.create_timestamp_tag.outputs.tags }}
94-
tags: "latest"
102+
TIMESTAMP_TAG=${{ steps.generate-tags.outputs.ts_image }}
103+
tags: ${{ steps.generate-tags.outputs.tag_list }}
95104
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
96105

97106
- name: Cache Docker images
98107
uses: actions/cache@v2
99108
with:
100109
path: /tmp/.buildx-cache
101-
key: ${{ steps.generate-image-name.outputs.image }}_${{ inputs.osg_series}}_${{ inputs.osg_repo }}_buildx_${{ github.sha }}_${{ github.run_id }}
110+
key: ${{ steps.generate-tags.outputs.cache_key }}

0 commit comments

Comments
 (0)