forked from e-mission/e-mission-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mahadik, Mukul Chandrakant
authored and
Mahadik, Mukul Chandrakant
committed
Sep 27, 2024
1 parent
c3389a2
commit 0a1ba9d
Showing
2 changed files
with
123 additions
and
20 deletions.
There are no files selected for viewing
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
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
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 |