Skip to content

Commit

Permalink
Testing reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahadik, Mukul Chandrakant authored and Mahadik, Mukul Chandrakant committed Sep 27, 2024
1 parent c3389a2 commit 0a1ba9d
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 20 deletions.
57 changes: 37 additions & 20 deletions .github/workflows/image_build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,44 @@ jobs:
git push origin
fi
dispatch:
needs: build
runs-on: ubuntu-latest

# dispatch:
# needs: build
# runs-on: ubuntu-latest

# strategy:
# matrix:
# include:
# - repo: e-mission/op-admin-dashboard
# branch: master
# - repo: e-mission/em-public-dashboard
# branch: main

# steps:
# - uses: actions/checkout@v4

# - name: Trigger workflow in admin-dash, public-dash
# run: |
# curl -L \
# -X POST \
# -H "Accept: application/vnd.github+json" \
# -H "Authorization: Bearer ${{ secrets.GH_FG_PAT_TAGS }}" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# https://api.github.com/repos/${{ matrix.repo }}/actions/workflows/image_build_push.yml/dispatches \
# -d '{"ref":"${{ matrix.branch }}"}'


cascade-image-build:
strategy:
matrix:
include:
- repo: MukuFlash03/op-admin-dashboard
- repo: MukuFlash03/nrel-openpath-join-page
branch: cleanup-cicd
- repo: MukuFlash03/em-public-dashboard
branch: cleanup-cicd

steps:
- uses: actions/checkout@v4

- name: Trigger workflow in admin-dash, public-dash
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GH_FG_PAT_TAGS }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ matrix.repo }}/actions/workflows/image_build_push.yml/dispatches \
-d '{"ref":"${{ matrix.branch }}"}'
# - repo: MukuFlash03/op-admin-dashboard
# branch: cleanup-cicd
# - repo: MukuFlash03/em-public-dashboard
# branch: cleanup-cicd
uses: MukuFlash03/e-mission-server/.github/workflows/reusable_image_build_push.yml@cleanup-cicd
with:
repo: ${{ matrix.repo }}
branch: ${{ matrix.branch }}
secrets: inherit
86 changes: 86 additions & 0 deletions .github/workflows/reusable_image_build_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Reusable Docker Image Build and Push

on:
workflow_call:
inputs:
repo:
required: true
type: string
branch:
required: true
type: string

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ inputs.repo }}
ref: ${{ inputs.branch }}

- name: Set docker image tags
id: set-tags
run: |
ls -al
set -a; source .env; set +a
if [ "${{ inputs.repo }}" = MukuFlash03/nrel-openpath-join-page" ]; then
echo "JOIN_IMAGE_TAG=${JOIN_IMAGE_TAG}" >> "$GITHUB_OUTPUT"
echo "Current join-page image tag (push): ${JOIN_IMAGE_TAG}"
fi
- name: docker login
run: |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- name: Get current date # get the date of the build
id: date
run: echo "date=$(date +'%Y-%m-%d--%M-%S')" >> "$GITHUB_OUTPUT"

- name: Run a one-line script
run: echo running in repo ${GITHUB_REPOSITORY#*/} branch ${GITHUB_REF##*/} on ${{ steps.date.outputs.date }}

- name: build docker image
run: |
docker build -t $DOCKER_USER/${GITHUB_REPOSITORY#*/}:${GITHUB_REF##*/}_${{ steps.date.outputs.date }} ./frontend
docker images
- name: push docker image
run: |
docker push $DOCKER_USER/${GITHUB_REPOSITORY#*/}:${GITHUB_REF##*/}_${{ steps.date.outputs.date }}
- name: Update .env file
run: |
if [ "${{ inputs.repo }}" = MukuFlash03/nrel-openpath-join-page" ]; then
echo "JOIN_IMAGE_TAG=${GITHUB_REF##*/}_${{ steps.date.outputs.date }}" > .env
# elif [ "${{ inputs.repo }}" = "MukuFlash03/op-admin-dashboard" ]; then
# echo "SERVER_IMAGE_TAG=${{ steps.get-server-tag.outputs.SERVER_IMAGE_TAG }}" >> .env
# echo "ADMIN_DASH_IMAGE_TAG=${GITHUB_REF##*/}_${{ steps.date.outputs.date }}" > .env
# elif [ "${{ inputs.repo }}" = "MukuFlash03/em-public-dashboard" ]; then
# echo "PUBLIC_DASH_NOTEBOOK_IMAGE_TAG=${GITHUB_REF##*/}_${{ steps.date.outputs.date }}" > .env
# if [ "${{ github.event_name }}" == "workflow_call" ]; then
# echo "Workflow_call: Reuse existing frontend image tag"
# echo "PUBLIC_DASH_FRONTEND_IMAGE_TAG=${{ steps.set-tags.outputs.PUBLIC_DASH_FRONTEND_IMAGE_TAG }}" >> .env
# else
# echo "Push event: Update frontend image tag"
# echo "PUBLIC_DASH_FRONTEND_IMAGE_TAG=${GITHUB_REF##*/}_${{ steps.date.outputs.date }}" >> .env
# fi
# echo "SERVER_IMAGE_TAG=${{ steps.get-server-tag.outputs.SERVER_IMAGE_TAG }}" >> .env
# echo "PUBLIC_DASHBOARD_IMAGE_TAG=${GITHUB_REF##*/}_${{ steps.date.outputs.date }}" > .env
fi
cat .env
- name: Add, Commit, Push changes to .env file
run: |
git config --local user.email "[email protected]"
git config --local user.name "Github Actions bot to update .env with latest tags"
if git diff --quiet; then
echo "Latest timestamp already present in .env file, no changes to commit"
else
git add .env
git commit -m "Updated docker image tags in .env file to the latest timestamp"
git push origin
fi
cat .env

0 comments on commit 0a1ba9d

Please sign in to comment.