Merge pull request #56 from lalithkota/1.2 #59
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Docker and Push | |
on: | |
push: | |
branches: | |
- "**" | |
tags-ignore: | |
- '**' | |
workflow_dispatch: | |
jobs: | |
docker-build: | |
name: Docker Build and Push | |
runs-on: ubuntu-latest | |
env: | |
NAMESPACE: ${{ secrets.docker_hub_organisation || 'openg2p' }} | |
OS_KAFKA_CONNECTOR_SERVICE_NAME: reporting-opensearch-kafka-connector | |
REPORTING_INIT_SERVICE_NAME: reporting-init-shell-tools | |
steps: | |
- uses: actions/checkout@v3 | |
- id: files | |
uses: jitterbit/get-changed-files@v1 | |
- name: Docker build OS Kafka Connector | |
run: | | |
OS_KAFKA_CONNECTOR_DOCKER_BUILD="false" | |
for changed_file in ${{ steps.files.outputs.all }}; do | |
if [[ ${changed_file} =~ ^opensearch-kafka-connector ]]; then | |
OS_KAFKA_CONNECTOR_DOCKER_BUILD="true" | |
break | |
fi | |
done | |
if [ "$OS_KAFKA_CONNECTOR_DOCKER_BUILD" != "true" ]; then | |
echo "Nothing to build!" | |
exit 0; | |
fi | |
BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,') | |
OS_KAFKA_CONNECTOR_IMAGE_ID=$NAMESPACE/$OS_KAFKA_CONNECTOR_SERVICE_NAME | |
# Change all uppercase to lowercase | |
OS_KAFKA_CONNECTOR_IMAGE_ID=$(echo $OS_KAFKA_CONNECTOR_IMAGE_ID | tr '[A-Z]' '[a-z]') | |
OS_KAFKA_CONNECTOR_VERSION=$BRANCH_NAME | |
if [[ $BRANCH_NAME == master || $BRANCH_NAME == main ]]; then | |
OS_KAFKA_CONNECTOR_VERSION=develop | |
fi | |
echo OS_KAFKA_CONNECTOR_IMAGE_ID=$OS_KAFKA_CONNECTOR_IMAGE_ID | |
echo OS_KAFKA_CONNECTOR_VERSION=$OS_KAFKA_CONNECTOR_VERSION | |
echo OS_KAFKA_CONNECTOR_IMAGE_ID=$OS_KAFKA_CONNECTOR_IMAGE_ID >> $GITHUB_ENV | |
echo OS_KAFKA_CONNECTOR_VERSION=$OS_KAFKA_CONNECTOR_VERSION >> $GITHUB_ENV | |
cd opensearch-kafka-connector | |
docker build . \ | |
--file Dockerfile \ | |
--tag $OS_KAFKA_CONNECTOR_IMAGE_ID:$OS_KAFKA_CONNECTOR_VERSION | |
if [[ '${{ secrets.docker_hub_token }}' != '' && '${{ secrets.docker_hub_actor }}' != '' ]]; then | |
export OS_KAFKA_CONNECTOR_DOCKER_PUSH="true" | |
echo OS_KAFKA_CONNECTOR_DOCKER_PUSH=$OS_KAFKA_CONNECTOR_DOCKER_PUSH >> $GITHUB_ENV | |
fi | |
- name: Docker push OS Kafka Connector | |
if: env.OS_KAFKA_CONNECTOR_DOCKER_PUSH == 'true' | |
run: | | |
echo "${{ secrets.docker_hub_token }}" | docker login -u ${{ secrets.docker_hub_actor }} --password-stdin | |
docker push ${{ env.OS_KAFKA_CONNECTOR_IMAGE_ID }}:${{ env.OS_KAFKA_CONNECTOR_VERSION }} | |
- name: Docker build Reporting Init | |
run: | | |
REPORTING_INIT_DOCKER_BUILD="false" | |
for changed_file in ${{ steps.files.outputs.all }}; do | |
if [[ ${changed_file} =~ ^reporting-init-docker ]]; then | |
REPORTING_INIT_DOCKER_BUILD="true" | |
break | |
fi | |
done | |
if [ "$REPORTING_INIT_DOCKER_BUILD" != "true" ]; then | |
echo "Nothing to build!" | |
exit 0; | |
fi | |
BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,') | |
REPORTING_INIT_IMAGE_ID=$NAMESPACE/$REPORTING_INIT_SERVICE_NAME | |
# Change all uppercase to lowercase | |
REPORTING_INIT_IMAGE_ID=$(echo $REPORTING_INIT_IMAGE_ID | tr '[A-Z]' '[a-z]') | |
REPORTING_INIT_VERSION=$BRANCH_NAME | |
if [[ $BRANCH_NAME == master || $BRANCH_NAME == main ]]; then | |
REPORTING_INIT_VERSION=develop | |
fi | |
echo REPORTING_INIT_IMAGE_ID=$REPORTING_INIT_IMAGE_ID | |
echo REPORTING_INIT_VERSION=$REPORTING_INIT_VERSION | |
echo REPORTING_INIT_IMAGE_ID=$REPORTING_INIT_IMAGE_ID >> $GITHUB_ENV | |
echo REPORTING_INIT_VERSION=$REPORTING_INIT_VERSION >> $GITHUB_ENV | |
cd reporting-init-docker | |
docker build . \ | |
--file Dockerfile \ | |
--tag $REPORTING_INIT_IMAGE_ID:$REPORTING_INIT_VERSION | |
if [[ '${{ secrets.docker_hub_token }}' != '' && '${{ secrets.docker_hub_actor }}' != '' ]]; then | |
export REPORTING_INIT_DOCKER_PUSH="true" | |
echo REPORTING_INIT_DOCKER_PUSH=$REPORTING_INIT_DOCKER_PUSH >> $GITHUB_ENV | |
fi | |
- name: Docker push Reporting Init | |
if: env.REPORTING_INIT_DOCKER_PUSH == 'true' | |
run: | | |
echo "${{ secrets.docker_hub_token }}" | docker login -u ${{ secrets.docker_hub_actor }} --password-stdin | |
docker push ${{ env.REPORTING_INIT_IMAGE_ID }}:${{ env.REPORTING_INIT_VERSION }} |