Skip to content

ODD Collector release #32

ODD Collector release

ODD Collector release #32

name: ODD Collector release
on:
workflow_dispatch:
inputs:
collector-name:
description: 'Select service to build'
required: true
default: 'odd-collector'
type: choice
options:
- odd-collector
- odd-collector-aws
- odd-collector-gcp
- odd-collector-azure
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/${{ inputs.collector-name }}
jobs:
construct_image_type:
runs-on: ubuntu-latest
name: Constructs image type based on input choice
outputs:
image_type: ${{ steps.set_image_type.outputs.IMAGE_TYPE }}
steps:
- name: Set IMAGE_TYPE
id: set_image_type
run: |
if [ "${{ inputs.collector-name }}" == "odd-collector" ]; then
echo "::set-output name=IMAGE_TYPE::generic"
else
IMAGE_TYPE=$(echo "${{ inputs.collector-name }}" | awk -F'-' '{print $NF}')
echo "::set-output name=IMAGE_TYPE::$IMAGE_TYPE"
fi
- name: Check ENV variables
run: |
echo ">>>>> IMAGE_NAME: $IMAGE_NAME"
echo ">>>>> IMAGE_TYPE: ${{ steps.set_image_type.outputs.IMAGE_TYPE }}"
lint:
runs-on: ubuntu-latest
name: Run black as linter
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
with:
options: "--check --verbose"
src: ./${{ inputs.collector-name }}
version: "22.3.0"
build_and_push:
runs-on: ubuntu-latest
needs: construct_image_type
name: Build and push docker image to GHCR
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.ORG_TOKEN_GHCR }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Extract only version part of a tag
id: tag
run: |
TAG_FULL="${{ steps.meta.outputs.tags }}"
IMAGE_TYPE="${{ needs.construct_image_type.outputs.image_type }}"
TAG_VERSION=$(echo "$TAG_FULL" | grep -o "$IMAGE_TYPE-[^ ]*" | sed "s/$IMAGE_TYPE-//")
echo "TAG_VERSION=$TAG_VERSION" >> $GITHUB_ENV
- name: Check ENV variables
run: |
echo ">>>>> TAG_VERSION = $TAG_VERSION"
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./${{ inputs.collector-name }}
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG_VERSION }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}