From fb2b0969709098d6bb57e072995b10fa8a9d8cb1 Mon Sep 17 00:00:00 2001 From: "Mahadik, Mukul Chandrakant" Date: Fri, 20 Sep 2024 23:42:47 -0700 Subject: [PATCH 1/6] Task A-6: Switching to step outputs instead of GITHUB_ENV Refer to details in cleanup issue: Task A-6: https://github.com/e-mission/e-mission-docs/issues/1082#issuecomment-2364335425 --- .github/workflows/image_build_push.yml | 33 +++++++++++++++----------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/image_build_push.yml b/.github/workflows/image_build_push.yml index b8a2720..8f6448d 100644 --- a/.github/workflows/image_build_push.yml +++ b/.github/workflows/image_build_push.yml @@ -24,24 +24,25 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set docker image tag from .env file + - name: Set docker image tags + id: set-tags run: | set -a; source .env; set +a - echo "Restoring latest server image tag from .env" - echo "DOCKER_TAG_FROM_PUSH=${SERVER_IMAGE_TAG}" >> $GITHUB_ENV + echo "DOCKER_TAG_FROM_PUSH=${SERVER_IMAGE_TAG}" >> "$GITHUB_OUTPUT" + echo "DOCKER_TAG_FROM_WORKFLOW_DISPATCH=${{ github.event.inputs.docker_image_tag }}" >> "$GITHUB_OUTPUT" - name: Set docker image tag from .env.repoTags file + id: set-frontend-tag run: | set -a; source .env.repoTags; set +a - echo "Restoring latest frontend image tag from .env.repoTags" - echo "FRONTEND_IMAGE_TAG=${FRONTEND_IMAGE_TAG}" >> $GITHUB_ENV + echo "FRONTEND_IMAGE_TAG=${FRONTEND_IMAGE_TAG}" >> "$GITHUB_OUTPUT" - name: Print input docker image tag run: | echo "Event name: ${{ github.event_name }}" - echo "Latest docker image tag (push): ${{ env.DOCKER_TAG_FROM_PUSH }}" - echo "Latest docker image tag (workflow_dispatch): ${{ env.DOCKER_TAG_FROM_WORKFLOW_DISPATCH }}" - echo "Current frontend image tag (push): ${{ env.FRONTEND_IMAGE_TAG }}" + echo "Latest docker image tag (push): ${{ steps.set-tags.outputs.DOCKER_TAG_FROM_PUSH }}" + echo "Latest docker image tag (workflow_dispatch): ${{ steps.set-tags.outputs.DOCKER_TAG_FROM_WORKFLOW_DISPATCH }}" + echo "Current frontend image tag (push): ${{ steps.set-frontend-tag.outputs.FRONTEND_IMAGE_TAG }}" - name: docker login run: | # log into docker hub account @@ -49,7 +50,7 @@ jobs: - name: Get current date # get the date of the build id: date - run: echo "::set-output name=date::$(date +'%Y-%m-%d--%M-%S')" + 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 }} @@ -57,9 +58,9 @@ jobs: - name: build docker image run: | if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then - SERVER_IMAGE_TAG=$DOCKER_TAG_FROM_WORKFLOW_DISPATCH docker compose -f docker-compose.yml build + SERVER_IMAGE_TAG=${{ steps.set-tags.outputs.DOCKER_TAG_FROM_WORKFLOW_DISPATCH }} docker compose -f docker-compose.yml build else - SERVER_IMAGE_TAG=$DOCKER_TAG_FROM_PUSH docker compose -f docker-compose.yml build + SERVER_IMAGE_TAG=${{ steps.set-tags.outputs.DOCKER_TAG_FROM_PUSH }} docker compose -f docker-compose.yml build fi docker images @@ -83,7 +84,7 @@ jobs: run: | if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then echo "Workflow_dispatch: New server image built and pushed, Updating image tag in .env" - echo "SERVER_IMAGE_TAG=$DOCKER_TAG_FROM_WORKFLOW_DISPATCH" > .env + echo "SERVER_IMAGE_TAG=${{ steps.set-tags.outputs.DOCKER_TAG_FROM_WORKFLOW_DISPATCH }}" > .env else echo "Push event: New frontend image built and pushed, Updating image tag in .env.repoTags" echo "FRONTEND_IMAGE_TAG=${{ steps.date.outputs.date }}" > .env.repoTags @@ -103,8 +104,12 @@ jobs: - name: Create tag files run: | - echo ${{ env.FRONTEND_IMAGE_TAG }} > frontend_tag_file.txt - echo ${{ env.NOTEBOOK_IMAGE_TAG }} > notebook_tag_file.txt + if [ "${{ github.event_name }}" == "push" ]; then + echo ${{ steps.date.outputs.date }} > frontend_tag_file.txt + else + echo ${{ steps.set-frontend-tag.outputs.FRONTEND_IMAGE_TAG }} > frontend_tag_file.txt + fi + echo ${{ steps.date.outputs.date }} > notebook_tag_file.txt echo "Created tag text files" - name: Upload Frontend Tag Artifact From 1446a3afd0c4b2a62ab84e542d41a60d96f484d2 Mon Sep 17 00:00:00 2001 From: "Mahadik, Mukul Chandrakant" Date: Sat, 21 Sep 2024 00:20:11 -0700 Subject: [PATCH 2/6] Task A-2: Storing latest tag in .env file + Read raw .env file Refer to details in cleanup issue: Task A-2: https://github.com/e-mission/e-mission-docs/issues/1082#issuecomment-2364583414 Added .env file initialized with the current latest tag of admin-dash and server image. Internal script can read docker image tags directly from .env.tags using curl to fetch raw file contents. Storing server tag as well since admin-dash Dockerfile uses it. Removed workflow dispatch inputs No longer need inputs since reading from .env.tags in server repo directly ------ Read raw file contents directly instead of using REST API REST API endpoint returns base64 encoded data which then needs to be decoded. Can simply read the Raw file contents from the publicly available file. ------ Also changed tag name to match tag name in internal repository This way we can directly use the tag name without having extra fields like envVar in the internal script. ----- For now not removing artifacts until the internal script is updated to handle this change. --- .env | 2 + .env.repoTags | 1 - .github/workflows/image_build_push.yml | 57 +++++++++++--------------- 3 files changed, 27 insertions(+), 33 deletions(-) delete mode 100644 .env.repoTags diff --git a/.env b/.env index b290898..effd6e6 100644 --- a/.env +++ b/.env @@ -1 +1,3 @@ +PUBLIC_DASH_NOTEBOOK_IMAGE_TAG=2024-09-21--39-25 +PUBLIC_DASH_FRONTEND_IMAGE_TAG=2024-09-21--39-25 SERVER_IMAGE_TAG=2024-09-20--06-45 diff --git a/.env.repoTags b/.env.repoTags deleted file mode 100644 index 6e67954..0000000 --- a/.env.repoTags +++ /dev/null @@ -1 +0,0 @@ -FRONTEND_IMAGE_TAG=2024-09-15--09-41 diff --git a/.github/workflows/image_build_push.yml b/.github/workflows/image_build_push.yml index 8f6448d..52a40d8 100644 --- a/.github/workflows/image_build_push.yml +++ b/.github/workflows/image_build_push.yml @@ -5,10 +5,6 @@ on: branches: [ main ] workflow_dispatch: - inputs: - docker_image_tag: - description: "Latest Docker image tags passed from e-mission-server repository on image build and push" - required: true env: DOCKER_USER: ${{secrets.DOCKER_USER}} @@ -24,25 +20,26 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Fetch server image tag + id: get-server-tag + run: | + response=$(curl -s https://raw.githubusercontent.com/MukuFlash03/e-mission-server/refs/heads/cleanup-cicd/.env) + SERVER_IMAGE_TAG=$(echo "$response" | grep "SERVER_IMAGE_TAG=" | cut -d'=' -f2) + echo "SERVER_IMAGE_TAG=$SERVER_IMAGE_TAG" >> "$GITHUB_OUTPUT" + - name: Set docker image tags id: set-tags run: | set -a; source .env; set +a - echo "DOCKER_TAG_FROM_PUSH=${SERVER_IMAGE_TAG}" >> "$GITHUB_OUTPUT" - echo "DOCKER_TAG_FROM_WORKFLOW_DISPATCH=${{ github.event.inputs.docker_image_tag }}" >> "$GITHUB_OUTPUT" - - - name: Set docker image tag from .env.repoTags file - id: set-frontend-tag - run: | - set -a; source .env.repoTags; set +a - echo "FRONTEND_IMAGE_TAG=${FRONTEND_IMAGE_TAG}" >> "$GITHUB_OUTPUT" + echo "PUBLIC_DASH_NOTEBOOK_IMAGE_TAG=${PUBLIC_DASH_NOTEBOOK_IMAGE_TAG}" >> "$GITHUB_OUTPUT" + echo "PUBLIC_DASH_FRONTEND_IMAGE_TAG=${PUBLIC_DASH_FRONTEND_IMAGE_TAG}" >> "$GITHUB_OUTPUT" - - name: Print input docker image tag + - name: Print input docker image tags run: | echo "Event name: ${{ github.event_name }}" - echo "Latest docker image tag (push): ${{ steps.set-tags.outputs.DOCKER_TAG_FROM_PUSH }}" - echo "Latest docker image tag (workflow_dispatch): ${{ steps.set-tags.outputs.DOCKER_TAG_FROM_WORKFLOW_DISPATCH }}" - echo "Current frontend image tag (push): ${{ steps.set-frontend-tag.outputs.FRONTEND_IMAGE_TAG }}" + echo "Current notebook image tag (push): ${{ steps.set-tags.outputs.PUBLIC_DASH_NOTEBOOK_IMAGE_TAG }}" + echo "Current frontend image tag (push): ${{ steps.set-tags.outputs.PUBLIC_DASH_FRONTEND_IMAGE_TAG }}" + echo "Latest server image tag (${{ github.event_name }}): ${{ steps.get-server-tag.outputs.SERVER_IMAGE_TAG }}" - name: docker login run: | # log into docker hub account @@ -57,21 +54,15 @@ jobs: - name: build docker image run: | - if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then - SERVER_IMAGE_TAG=${{ steps.set-tags.outputs.DOCKER_TAG_FROM_WORKFLOW_DISPATCH }} docker compose -f docker-compose.yml build - else - SERVER_IMAGE_TAG=${{ steps.set-tags.outputs.DOCKER_TAG_FROM_PUSH }} docker compose -f docker-compose.yml build - fi + SERVER_IMAGE_TAG=${{ steps.get-server-tag.outputs.SERVER_IMAGE_TAG }} docker compose -f docker-compose.yml build docker images - name: rename docker images run: | if [ "${{ github.event_name }}" == "push" ]; then docker image tag em-pub-dash-prod/frontend:latest $DOCKER_USER/${GITHUB_REPOSITORY#*/}_frontend:${GITHUB_REF##*/}_${{ steps.date.outputs.date }} - echo "FRONTEND_IMAGE_TAG=${{ steps.date.outputs.date }}" >> $GITHUB_ENV fi docker image tag em-pub-dash-prod/viz-scripts:latest $DOCKER_USER/${GITHUB_REPOSITORY#*/}_notebook:${GITHUB_REF##*/}_${{ steps.date.outputs.date }} - echo "NOTEBOOK_IMAGE_TAG=${{ steps.date.outputs.date }}" >> $GITHUB_ENV - name: push docker images run: | @@ -82,32 +73,34 @@ jobs: - name: Update .env file run: | + echo "PUBLIC_DASH_NOTEBOOK_IMAGE_TAG=${{ steps.date.outputs.date }}" > .env if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then - echo "Workflow_dispatch: New server image built and pushed, Updating image tag in .env" - echo "SERVER_IMAGE_TAG=${{ steps.set-tags.outputs.DOCKER_TAG_FROM_WORKFLOW_DISPATCH }}" > .env + echo "Workflow_dispatch: 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: New frontend image built and pushed, Updating image tag in .env.repoTags" - echo "FRONTEND_IMAGE_TAG=${{ steps.date.outputs.date }}" > .env.repoTags + echo "Push event: Update frontend image tag" + echo "PUBLIC_DASH_FRONTEND_IMAGE_TAG=${{ steps.date.outputs.date }}" >> .env fi + echo "SERVER_IMAGE_TAG=${{ steps.get-server-tag.outputs.SERVER_IMAGE_TAG }}" >> .env - name: Add, Commit, Push changes to .env file run: | git config --local user.email "action@github.com" git config --local user.name "Github Actions bot to update .env with latest tags" if git diff --quiet; then - echo "Latest timestamps already present in .env files, no changes to commit" + echo "Latest timestamp already present in .env file, no changes to commit" else - git add .env .env.repoTags - git commit -m "Updated docker image tags in .env files to the latest timestamps" + git add .env + git commit -m "Updated docker image tags in .env file to the latest timestamp" git push origin fi - - name: Create tag files + - name: Create artifact text files run: | if [ "${{ github.event_name }}" == "push" ]; then echo ${{ steps.date.outputs.date }} > frontend_tag_file.txt else - echo ${{ steps.set-frontend-tag.outputs.FRONTEND_IMAGE_TAG }} > frontend_tag_file.txt + echo ${{ steps.set-tags.outputs.PUBLIC_DASH_FRONTEND_IMAGE_TAG }} > frontend_tag_file.txt fi echo ${{ steps.date.outputs.date }} > notebook_tag_file.txt echo "Created tag text files" From 2c7460e55c8ead23322d6f68104538125faab79a Mon Sep 17 00:00:00 2001 From: "Mahadik, Mukul Chandrakant" Date: Sat, 21 Sep 2024 01:15:04 -0700 Subject: [PATCH 3/6] Task A-8: Prefix branch name + Task A-7: Removed certificates from external Task A-8: Prefixing branch name to the docker tag along with the date. In the internal script we will not need to maintain the different branch lists as the images will be completely tagged in the external workflows themselves. We can simply use the tags without modifications then. For now, not prefixing the tag to the artifact since we will be removing the artifact anyways. And current internal script works with artifacts. Once I update the internal script, will come back and remove artifacts. Also removing prefixed branch name from frontend image artifact in case of workflow dispatch event since it uses the existing frontend image tag generated during push event which already has prefixed branch name In Dockerfile, removing hardcoded branch name, since in this change, we are already included the branch name in image tag. ---------- Task A-7: Certifcates added to internal Dockerfiles. Refer to issue comment for details: Task A-7: https://github.com/e-mission/e-mission-docs/issues/1082#issuecomment-2364315699 The certificates are relevant to our internal AWS configuration and not needed externally. They can be present externally too without having any major effect. But removing them helps keeping the base image clean. Additionally, anyone working with the code can customize with their own certificates if needed or adopt an approach which doesn't even need certificates in the first place. --- .github/workflows/image_build_push.yml | 9 +++------ viz_scripts/Dockerfile | 4 +--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/image_build_push.yml b/.github/workflows/image_build_push.yml index 52a40d8..f028e14 100644 --- a/.github/workflows/image_build_push.yml +++ b/.github/workflows/image_build_push.yml @@ -13,9 +13,6 @@ env: jobs: build: runs-on: ubuntu-latest - - env: - DOCKER_TAG_FROM_WORKFLOW_DISPATCH: ${{ github.event.inputs.docker_image_tag }} steps: - uses: actions/checkout@v4 @@ -73,13 +70,13 @@ jobs: - name: Update .env file run: | - echo "PUBLIC_DASH_NOTEBOOK_IMAGE_TAG=${{ steps.date.outputs.date }}" > .env + echo "PUBLIC_DASH_NOTEBOOK_IMAGE_TAG=${GITHUB_REF##*/}_${{ steps.date.outputs.date }}" > .env if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then echo "Workflow_dispatch: 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=${{ steps.date.outputs.date }}" >> .env + 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 @@ -100,7 +97,7 @@ jobs: if [ "${{ github.event_name }}" == "push" ]; then echo ${{ steps.date.outputs.date }} > frontend_tag_file.txt else - echo ${{ steps.set-tags.outputs.PUBLIC_DASH_FRONTEND_IMAGE_TAG }} > frontend_tag_file.txt + echo ${{ steps.set-tags.outputs.PUBLIC_DASH_FRONTEND_IMAGE_TAG }} | cut -d'_' -f2 > frontend_tag_file.txt fi echo ${{ steps.date.outputs.date }} > notebook_tag_file.txt echo "Created tag text files" diff --git a/viz_scripts/Dockerfile b/viz_scripts/Dockerfile index 52c5aa5..5d1978b 100644 --- a/viz_scripts/Dockerfile +++ b/viz_scripts/Dockerfile @@ -1,8 +1,6 @@ # python 3 ARG SERVER_IMAGE_TAG -FROM shankari/e-mission-server:master_${SERVER_IMAGE_TAG} - -ADD https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem /etc/ssl/certs/ +FROM shankari/e-mission-server:${SERVER_IMAGE_TAG} VOLUME /plots From d799254fe3af991b6eb088316d64f8dbcfbec7bd Mon Sep 17 00:00:00 2001 From: "Mahadik, Mukul Chandrakant" Date: Mon, 23 Sep 2024 14:42:10 -0700 Subject: [PATCH 4/6] Task A-2: Removed artifact upload ; internal script updated Internal script updated as well. Internal PR must be merged as well once these external PR changes merged. --- .github/workflows/image_build_push.yml | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/.github/workflows/image_build_push.yml b/.github/workflows/image_build_push.yml index f028e14..93e8ba8 100644 --- a/.github/workflows/image_build_push.yml +++ b/.github/workflows/image_build_push.yml @@ -91,27 +91,3 @@ jobs: git commit -m "Updated docker image tags in .env file to the latest timestamp" git push origin fi - - - name: Create artifact text files - run: | - if [ "${{ github.event_name }}" == "push" ]; then - echo ${{ steps.date.outputs.date }} > frontend_tag_file.txt - else - echo ${{ steps.set-tags.outputs.PUBLIC_DASH_FRONTEND_IMAGE_TAG }} | cut -d'_' -f2 > frontend_tag_file.txt - fi - echo ${{ steps.date.outputs.date }} > notebook_tag_file.txt - echo "Created tag text files" - - - name: Upload Frontend Tag Artifact - uses: actions/upload-artifact@v4 - with: - name: frontend-image-tag - path: frontend_tag_file.txt - overwrite: true - - - name: Upload Notebook Tag Artifact - uses: actions/upload-artifact@v4 - with: - name: notebook-image-tag - path: notebook_tag_file.txt - overwrite: true From da5feec59ddfc7afb5d557c1d0aa70b4da53ee3a Mon Sep 17 00:00:00 2001 From: "Mahadik, Mukul Chandrakant" Date: Sun, 29 Sep 2024 11:46:26 -0700 Subject: [PATCH 5/6] Task A-2: Read raw .env file -> Corrected repo owner in URL --- .github/workflows/image_build_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/image_build_push.yml b/.github/workflows/image_build_push.yml index 93e8ba8..41697f0 100644 --- a/.github/workflows/image_build_push.yml +++ b/.github/workflows/image_build_push.yml @@ -20,7 +20,7 @@ jobs: - name: Fetch server image tag id: get-server-tag run: | - response=$(curl -s https://raw.githubusercontent.com/MukuFlash03/e-mission-server/refs/heads/cleanup-cicd/.env) + response=$(curl -s https://raw.githubusercontent.com/e-mission/e-mission-server/refs/heads/cleanup-cicd/.env) SERVER_IMAGE_TAG=$(echo "$response" | grep "SERVER_IMAGE_TAG=" | cut -d'=' -f2) echo "SERVER_IMAGE_TAG=$SERVER_IMAGE_TAG" >> "$GITHUB_OUTPUT" From 0d16640c3d5c1cfa6b52939604a92725e93b1206 Mon Sep 17 00:00:00 2001 From: "Mahadik, Mukul Chandrakant" Date: Sun, 29 Sep 2024 12:12:34 -0700 Subject: [PATCH 6/6] Task A-5: Added reusable workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Storing a reusable workflow in the e-mission-server repo. Can decide where to place it in a central location. https://docs.github.com/en/actions/sharing-automations/reusing-workflows It essentially works like a function call in normal programming. The advantage is that we have no repeated code the image build process. All the other repos (join, admin-dash, public-dash) reuse the same workflow file. Additionally, on for future GitHub actions, workflow file related changes, will no longer need to have 3 additional PRs for each repo (join, admin-dash, public-dash). Can simply modify the reusable workflow file as this is the core “function” workflow that is being called. I have added conditional checks that check for the repo name in the reusable workflow file that determine which statements to execute depending on for which repo the workflow is running. This is used for both push events specific to a repo as well as for the workflow dispatch events triggered on pushes to server repo. --- .github/workflows/image_build_push.yml | 91 ++------------------------ 1 file changed, 7 insertions(+), 84 deletions(-) diff --git a/.github/workflows/image_build_push.yml b/.github/workflows/image_build_push.yml index 41697f0..717eb57 100644 --- a/.github/workflows/image_build_push.yml +++ b/.github/workflows/image_build_push.yml @@ -6,88 +6,11 @@ on: workflow_dispatch: -env: - DOCKER_USER: ${{secrets.DOCKER_USER}} - DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}} - jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Fetch server image tag - id: get-server-tag - run: | - response=$(curl -s https://raw.githubusercontent.com/e-mission/e-mission-server/refs/heads/cleanup-cicd/.env) - SERVER_IMAGE_TAG=$(echo "$response" | grep "SERVER_IMAGE_TAG=" | cut -d'=' -f2) - echo "SERVER_IMAGE_TAG=$SERVER_IMAGE_TAG" >> "$GITHUB_OUTPUT" - - - name: Set docker image tags - id: set-tags - run: | - set -a; source .env; set +a - echo "PUBLIC_DASH_NOTEBOOK_IMAGE_TAG=${PUBLIC_DASH_NOTEBOOK_IMAGE_TAG}" >> "$GITHUB_OUTPUT" - echo "PUBLIC_DASH_FRONTEND_IMAGE_TAG=${PUBLIC_DASH_FRONTEND_IMAGE_TAG}" >> "$GITHUB_OUTPUT" - - - name: Print input docker image tags - run: | - echo "Event name: ${{ github.event_name }}" - echo "Current notebook image tag (push): ${{ steps.set-tags.outputs.PUBLIC_DASH_NOTEBOOK_IMAGE_TAG }}" - echo "Current frontend image tag (push): ${{ steps.set-tags.outputs.PUBLIC_DASH_FRONTEND_IMAGE_TAG }}" - echo "Latest server image tag (${{ github.event_name }}): ${{ steps.get-server-tag.outputs.SERVER_IMAGE_TAG }}" - - - name: docker login - run: | # log into docker hub account - 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: | - SERVER_IMAGE_TAG=${{ steps.get-server-tag.outputs.SERVER_IMAGE_TAG }} docker compose -f docker-compose.yml build - docker images - - - name: rename docker images - run: | - if [ "${{ github.event_name }}" == "push" ]; then - docker image tag em-pub-dash-prod/frontend:latest $DOCKER_USER/${GITHUB_REPOSITORY#*/}_frontend:${GITHUB_REF##*/}_${{ steps.date.outputs.date }} - fi - docker image tag em-pub-dash-prod/viz-scripts:latest $DOCKER_USER/${GITHUB_REPOSITORY#*/}_notebook:${GITHUB_REF##*/}_${{ steps.date.outputs.date }} - - - name: push docker images - run: | - if [ "${{ github.event_name }}" == "push" ]; then - docker push $DOCKER_USER/${GITHUB_REPOSITORY#*/}_frontend:${GITHUB_REF##*/}_${{ steps.date.outputs.date }} - fi - docker push $DOCKER_USER/${GITHUB_REPOSITORY#*/}_notebook:${GITHUB_REF##*/}_${{ steps.date.outputs.date }} - - - name: Update .env file - run: | - echo "PUBLIC_DASH_NOTEBOOK_IMAGE_TAG=${GITHUB_REF##*/}_${{ steps.date.outputs.date }}" > .env - if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then - echo "Workflow_dispatch: 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 - - - name: Add, Commit, Push changes to .env file - run: | - git config --local user.email "action@github.com" - 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 + build: + if: ${{ !contains(github.event.head_commit.author.name, 'Github Actions bot to update .env with latest tags') }} + uses: e-mission/e-mission-server/.github/workflows/reusable_image_build_push.yml@master + with: + repo: ${{ github.event.repository.name }} + branch: ${{ github.ref_name }} + secrets: inherit