From 368900b1a53c3cce5465361dcf8567bba6b7a8ce Mon Sep 17 00:00:00 2001 From: "Mahadik, Mukul Chandrakant" Date: Fri, 3 May 2024 02:59:03 -0700 Subject: [PATCH] Artifact + Matrix - 5 Adding .env file which stores only docker image timestamp for the latest dockerhub e-mission-server image already pushed. .env file overwritten in both types of trigger events - push and workflow_dispatch. Added commit and push github actions as well for pushing latest changes to the .env file made via the workflow. Lastly, docker-compose now also mentions the ENV variable name to be read from the .env file for the ARG value in the Dockerfile. No changes required in the Dockerfiles. Had to remove .env from the .gitignore file. --- .env | 1 + .github/workflows/image_build_push.yml | 18 ++++++++++++++++++ .gitignore | 1 - docker-compose.dev.yml | 2 +- docker-compose.yml | 2 +- 5 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..203f891 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +DOCKER_IMAGE_TAG=2024-05-02--16-40 \ No newline at end of file diff --git a/.github/workflows/image_build_push.yml b/.github/workflows/image_build_push.yml index 22e9cad..40f97ff 100644 --- a/.github/workflows/image_build_push.yml +++ b/.github/workflows/image_build_push.yml @@ -118,6 +118,24 @@ jobs: echo "Latest docker image tag (push): ${{ env.DOCKER_IMAGE_TAG_1 }}" echo "Latest docker image tag (workflow_dispatch): ${{ env.DOCKER_IMAGE_TAG_2 }}" + - name: Update .env file + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + echo "Workflow_dispatch: New server image built and pushed, Updating image tag in .env" + echo "DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG_2" > .env + else + echo "Push event: Restoring latest server image tag in .env" + echo "DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG_1" > .env + fi + + - name: Add, Commit, Push changes to .env file + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add .env + git commit -m "Updated docker image tag in .env to the latest timestamp: ${{ env.DOCKER_IMAGE_TAG_2 }}" + git push origin + - name: docker login run: | # log into docker hub account docker login -u $DOCKER_USER -p $DOCKER_PASSWORD diff --git a/.gitignore b/.gitignore index 6a0eab5..aa7a8ff 100644 --- a/.gitignore +++ b/.gitignore @@ -108,7 +108,6 @@ celerybeat.pid *.sage.py # Environments -.env .venv env/ venv/ diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 99f63f0..3eb68f9 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -21,7 +21,7 @@ services: context: viz_scripts dockerfile: docker/Dockerfile.dev args: - DOCKER_IMAGE_TAG: '' + DOCKER_IMAGE_TAG: ${DOCKER_IMAGE_TAG} depends_on: - db environment: diff --git a/docker-compose.yml b/docker-compose.yml index ff5953c..0e18ffa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,7 @@ services: context: viz_scripts dockerfile: Dockerfile args: - DOCKER_IMAGE_TAG: '' + DOCKER_IMAGE_TAG: ${DOCKER_IMAGE_TAG} depends_on: - db environment: