Skip to content

Create and publish a Keystone image #30

Create and publish a Keystone image

Create and publish a Keystone image #30

---
name: Create and publish a Keystone image
on:
schedule:
- cron: '0 0 * * 0' # Run Weekly at midnight UTC
pull_request:
workflow_dispatch:
inputs:
project-version:
description: 'Version of OpenStack Keystone to build defaults to openstack-constraints if unspecified'
required: false
type: string
openstack-constraints:
description: 'Version of OpenStack Constraints to use'
required: true
default: "master"
type: choice
options:
- master
- stable/2024.1
- stable/2025.1
rackspace-plugin-version:
description: 'Version of the Rackspace Keystone plugin to use'
required: true
default: "main"
type: choice
options:
- main
apache-mod-wsgi-version:
description: 'Version of Apache mod_wsgi to use'
required: true
default: "5.0.2"
type: choice
options:
- "5.0.2"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/keystone
openstack_constraints: openstack_constraints
rackspace_plugin: rackspace_plugin
mod_wsgi: mod_wsgi
project_version: ${{ github.event.inputs.project-version }}
jobs:
init:
runs-on: ubuntu-latest
outputs:
openstack-constraints: ${{ steps.generate-matrix.outputs.openstack_constraints }}
rackspace-plugin-version: ${{ steps.generate-matrix.outputs.rackspace_plugin }}
apache-mod-wsgi-version: ${{ steps.generate-matrix.outputs.mod_wsgi }}
steps:
- name: echo environment variables
run: |
echo "${{ github.event.inputs }}"
- name: generate-matrix
id: generate-matrix
run: |
if [ "${{ github.event_name == 'workflow_dispatch' }}" = "true" ]; then
openstack_constraints="$(echo '${{ github.event.inputs.openstack-constraints }}' | jq -R '[select(length>0)]')"
rackspace_plugin="$(echo '${{ github.event.inputs.rackspace-plugin-version }}' | jq -R '[select(length>0)]')"
mod_wsgi="$(echo '${{ github.event.inputs.apache-mod-wsgi-version }}' | jq -R '[select(length>0)]')"
else
openstack_constraints="${{ env.openstack_constraints }}"
rackspace_plugin="${{ env.rackspace_plugin }}"
mod_wsgi="${{ env.mod_wsgi }}"
fi
echo "openstack_constraints=${openstack_constraints}" >> $GITHUB_OUTPUT
echo "rackspace_plugin=${rackspace_plugin}" >> $GITHUB_OUTPUT
echo "mod_wsgi=${mod_wsgi}" >> $GITHUB_OUTPUT
build-and-push-image:
needs: init
strategy:
matrix:
openstack-constraints: ${{ fromJSON(needs.init.outputs.openstack-constraints)}}
rackspace-plugin-version: ${{ fromJSON(needs.init.outputs.rackspace-plugin-version) }}
apache-mod-wsgi-version: ${{ fromJSON(needs.init.outputs.apache-mod-wsgi-version) }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Dynamically set MY_DATE environment variable
run: echo "MY_DATE=$(date +%s)" >> $GITHUB_ENV
- name: Dynamically set OS_VERSION_PARSE environment variable
run: |
VERSION=$(echo -n "${{ matrix.openstack-constraints }}" | awk -F'/' '{($2=="" ? x=$1 : x=$2); print x}')
echo "OS_VERSION_PARSE=${VERSION}" >> $GITHUB_ENV
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: ContainerFiles/keystone
push: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.OS_VERSION_PARSE }}-latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.OS_VERSION_PARSE }}-${{ env.MY_DATE }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
OS_VERSION=${{ env.project_version != '' && env.project_version || matrix.openstack-constraints }}
OS_CONSTRAINTS=${{ matrix.openstack-constraints }}
RXT_VERSION=${{ matrix.rackspace-plugin-version }}
- name: Run Trivy vulnerability scanner
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
uses: aquasecurity/trivy-action@0.28.0
with:
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.OS_VERSION_PARSE }}-${{ env.MY_DATE }}'
output: trivy.txt
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
- name: Publish Trivy Output to Summary
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
run: |
if [[ -s trivy.txt ]]; then
{
echo "### Security Output"
echo "<details><summary>Click to expand</summary>"
echo ""
echo '```terraform'
cat trivy.txt
echo '```'
echo "</details>"
} >> $GITHUB_STEP_SUMMARY
fi