diff --git a/.env b/.env new file mode 100644 index 00000000..93050391 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +SERVER_IMAGE_TAG=2024-08-12--15-15 \ No newline at end of file diff --git a/.github/workflows/image_build_push.yml b/.github/workflows/image_build_push.yml new file mode 100644 index 00000000..47e0203a --- /dev/null +++ b/.github/workflows/image_build_push.yml @@ -0,0 +1,103 @@ +name: docker-image-push-public-dash + +on: + push: + 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}} + DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}} + +jobs: + build: + runs-on: ubuntu-latest + + env: + DOCKER_TAG_FROM_WORKFLOW_DISPATCH: ${{ github.event.inputs.docker_image_tag }} + + steps: + - uses: actions/checkout@v4 + + - name: Set docker image tag from .env file + run: | + set -a; source .env; set +a + echo "DOCKER_TAG_FROM_PUSH=${SERVER_IMAGE_TAG}" >> $GITHUB_ENV + + - 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 }}" + + - 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 "SERVER_IMAGE_TAG=$DOCKER_TAG_FROM_WORKFLOW_DISPATCH" > .env + else + echo "Push event: Restoring latest server image tag from .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 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 tag in .env file to the latest timestamp" + git push origin + fi + + - 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 "::set-output name=date::$(date +'%Y-%m-%d--%M-%S')" + + - 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: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + SERVER_IMAGE_TAG=$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 + fi + docker images + + - name: rename docker images + run: | + if [ "${{ github.event_name }}" == "push" ]; then + docker image tag em-pub-dash/frontend:latest $DOCKER_USER/${GITHUB_REPOSITORY#*/}_frontend:${GITHUB_REF##*/}_${{ steps.date.outputs.date }} + fi + docker image tag em-pub-dash/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: Create a text file + run: | + echo ${{ steps.date.outputs.date }} > public_dash_tag_file.txt + echo "Created tag text file" + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: public-dash-image-tag + path: public_dash_tag_file.txt + overwrite: true diff --git a/.gitignore b/.gitignore index 6a0eab58..aa7a8ff4 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 fdbdbb8c..1906101e 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -18,8 +18,10 @@ services: notebook-server: image: em-pub-dash-dev/viz-scripts build: - context: viz_scripts - dockerfile: docker/Dockerfile.dev + context: viz_scripts + dockerfile: docker/Dockerfile.dev + args: + SERVER_IMAGE_TAG: ${SERVER_IMAGE_TAG} depends_on: - db environment: diff --git a/docker-compose.yml b/docker-compose.yml index 73a98752..38a975ae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,11 @@ services: - emission notebook-server: image: em-pub-dash-prod/viz-scripts - build: viz_scripts + build: + context: viz_scripts + dockerfile: Dockerfile + args: + SERVER_IMAGE_TAG: ${SERVER_IMAGE_TAG} depends_on: - db environment: diff --git a/viz_scripts/Dockerfile b/viz_scripts/Dockerfile index 305b0913..52c5aa55 100644 --- a/viz_scripts/Dockerfile +++ b/viz_scripts/Dockerfile @@ -1,5 +1,8 @@ # python 3 -FROM shankari/e-mission-server:master_2024-07-19--34-43 +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/ VOLUME /plots diff --git a/viz_scripts/docker/Dockerfile.dev b/viz_scripts/docker/Dockerfile.dev index 1f306da2..663f60d2 100644 --- a/viz_scripts/docker/Dockerfile.dev +++ b/viz_scripts/docker/Dockerfile.dev @@ -1,5 +1,6 @@ # python 3 -FROM shankari/e-mission-server:master_2024-07-19--34-43 +ARG SERVER_IMAGE_TAG +FROM shankari/e-mission-server:master_${SERVER_IMAGE_TAG} VOLUME /plots diff --git a/viz_scripts/docker/start_notebook.sh b/viz_scripts/docker/start_notebook.sh index 33ba7ee6..c6d1ad6d 100755 --- a/viz_scripts/docker/start_notebook.sh +++ b/viz_scripts/docker/start_notebook.sh @@ -1,14 +1,7 @@ #!/usr/bin/env bash #Configure web server -#set database URL using environment variable echo "DB host = "${DB_HOST} -if [ -z ${DB_HOST} ] ; then - local_host=`hostname -i` - sed "s-localhost-${local_host}_" conf/storage/db.conf.sample > conf/storage/db.conf -else - sed "s-localhost-${DB_HOST}-" conf/storage/db.conf.sample > conf/storage/db.conf -fi ### configure the saved-notebooks directory for persistent notebooks @@ -37,7 +30,7 @@ cd saved-notebooks # tail -f /dev/null if [ -z ${CRON_MODE} ] ; then echo "Running notebook in docker, change host:port to localhost:47962 in the URL below" - PYTHONPATH=/usr/src/app jupyter notebook --no-browser --ip=${WEB_SERVER_HOST} --allow-root + PYTHONPATH=/usr/src/app jupyter notebook --no-browser --ip=0.0.0.0 --allow-root else echo "Running crontab without user interaction, setting python path" export PYTHONPATH=/usr/src/app