Skip to content

Add alternative "cron" commands where the project id is user-settable… #21

Add alternative "cron" commands where the project id is user-settable…

Add alternative "cron" commands where the project id is user-settable… #21

---
name: Create and publish a Docker image
# Run this workflow every time a change is pushed to the branch called `release`
on:
push:
branches:
- main
env:
# GitHub container registry
REGISTRY: ghcr.io
# Name used for Docker image
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Set permissions granted to the `GITHUB_TOKEN` for the actions in this job
permissions:
contents: read
packages: write
id-token: write
steps:
# Checkout the repository
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Generate XNAT container service labels
id: xnat-command-label
run: |
import json
import os
repo_dir = os.getenv('GITHUB_WORKSPACE')
command_list = []
for file in os.listdir(repo_dir):
if file.endswith(".json"):
with open(file) as f:
command_object = json.load(f)
command_string = json.dumps(command_object)
command_list.append(command_string)
commands = ','.join(command_list)
with open(os.environ['GITHUB_OUTPUT'], 'a') as github_output:
print(f"nrglabel=[{commands}]", file=github_output)
shell: python
# Log into the container registry
- name: Log in to the Container registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags and labels) to be applied to the image. See [docker/metadata-action](https://github.com/docker/metadata-action#about)
# The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
# The current version does not allow for labels to be added containing the # symbol, so we add the
# custom nrg label in the build-push-action below
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# labels: 'org.nrg.commands=${{ steps.xnat-command-label.outputs.nrglabel }}'
tags: |
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
# Build the image from the Dockerfile in the repo and push to the container registry.
# The `context` parameter defines the build's context as the set of files located in the
# specified path. For more information,
# see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the
# `docker/build-push-action` repository.
# Tag and label the image using the output from the metadata step above
- name: Build and push Docker image
id: push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: |
${{ steps.meta.outputs.labels }}
org.nrg.commands=${{ steps.xnat-command-label.outputs.nrglabel }}