Skip to content

build microservice

build microservice #50

name: build microservice
# Assumption:
# You've created the following GitHub secrets in your repository:
# OpenShiftServerURL
# OS-${license-plate}-Token (build tokens from OpenShift-- you need one for each namespace)
on:
workflow_dispatch:
inputs:
microservice:
description: "Microservice"
required: true
type: choice
options:
- address-service
- bcsc-service
- captcha-service
- msp-service
- spa-env-server
- splunk-forwarder
license-plate:
description: Which OpenShift project are you building?
required: true
type: choice
options:
- 0752cb
- 3f9283
- 61ab99
- a3c641
- be8465
- e1aae2
- f0463d
# environment:
# description: "Environment to deploy to"
# required: true
# type: choice
# options:
# - dev
# - test
# - prod
env:
LICENSE_PLATE: ${{ github.event.inputs.license-plate }}
NAMESPACE: ${{ github.event.inputs.license-plate }}-tools
IMAGE_NAME: ${{ github.event.inputs.microservice }}
BUILD_NAME: ${{ github.event.inputs.microservice }}-main-build
SOURCE_IMAGE_TAG: "latest"
TARGET_IMAGE_TAG: "dev"
# WORKING_DIRECTORY: ./${{ github.event.inputs.microservice }}
jobs:
validate:
name: Validate microservice/namespace combination
runs-on: ubuntu-latest
outputs:
good_to_go: ${{ steps.set_output.outputs.checks_valid }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: set output
id: set_output
run: |
if [[ -z ${{ github.event.inputs.microservice }} ]]; then
echo "checks_valid=false" >> "$GITHUB_OUTPUT"
echo "Deployment skipped because microservice not set"
elif [[ -z ${{ github.event.inputs.license-plate }} ]]; then
echo "checks_valid=false" >> "$GITHUB_OUTPUT"
echo "Deployment skipped because license plate not set"
elif [[ ( $IMAGE_NAME == "bcsc-service") && ( $LICENSE_PLATE != "a3c641") ]]; then
echo "checks_valid=false" >> "$GITHUB_OUTPUT"
echo "Deployment skipped because BCSC service is only used in a3c641. Selected license-plate: $LICENSE_PLATE"
elif [[ ( $IMAGE_NAME == "msp-service") && ( $LICENSE_PLATE == "3f9283") ]]; then
echo "checks_valid=false" >> "$GITHUB_OUTPUT"
echo "Deployment skipped because 3f9283 uses a custom msp-service. See the project repo for details"
else
echo "checks_valid=true" >> "$GITHUB_OUTPUT"
echo "License plate/microservice combination is valid, moving to next step"
fi
build:
needs: [validate]
if: needs.validate.outputs.good_to_go == 'true'
runs-on: ubuntu-latest
steps:
- name: Test action
run: echo "test action reached. License plate $LICENSE_PLATE Namespace $NAMESPACE Image name $IMAGE_NAME"
- uses: redhat-actions/openshift-tools-installer@v1
with:
source: "mirror"
oc: "latest"
- name: Log in to Openshift
run: oc login --token=${{ secrets[format('OS_{0}_Token', github.event.inputs.license-plate)] }} --server=${{ secrets.OpenShiftServerURL}}
- name: Check version
run: oc version
- name: Generate Build
run: oc start-build ${BUILD_NAME} -n ${NAMESPACE} --follow
- name: Time delay
# to give time for Openshift to process the build so it doesn't tag the wrong image
run: sleep 30s
- name: Deploy to Target Environment
run: oc tag ${NAMESPACE}/${IMAGE_NAME}:${SOURCE_IMAGE_TAG} ${NAMESPACE}/${IMAGE_NAME}:${TARGET_IMAGE_TAG}
# see OpenShift/RedHat documentation for more info on "oc tag" syntax
# example: `oc tag f0463d-dev/address-service:latest f0463d-dev/address-service:dev