Build Image Nightly for Docker #53
This file contains hidden or 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
| --- | |
| name: Build Image Nightly for Docker | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: Image Tag | |
| default: nightly | |
| required: true | |
| git-ref: | |
| description: Git Ref | |
| default: master | |
| required: true | |
| schedule: | |
| - cron: "30 23 * * *" | |
| #push: | |
| #branches: [ ci ] | |
| jobs: | |
| docker: | |
| name: Build image and push after successfull calculation | |
| runs-on: ubuntu-latest | |
| env: | |
| DOCKER_USERNAME: ${{ secrets.docker_username }} | |
| DOCKER_PASSWORD: ${{ secrets.docker_password }} | |
| DOCKER_TAG: ${{ github.event.inputs.version }} | |
| REPO_REF: ${{ github.event.inputs.git-ref }} | |
| steps: | |
| # This Checkout is necessary when using a context in docker/build-push-action | |
| - name: Clone Repository (Latest) | |
| uses: actions/checkout@v4 | |
| if: github.event.inputs.git-ref == '' | |
| - name: Clone Repository (Custom Ref) | |
| uses: actions/checkout@v4 | |
| if: github.event.inputs.git-ref != '' | |
| with: | |
| ref: ${{ github.event.inputs.git-ref }} | |
| - name: Build image engine | |
| id: docker_engine_manual | |
| run: | | |
| if [ ${{ github.event.inputs.version }} != '' ]; then | |
| echo "Is manual run" | |
| else | |
| echo "Is scheduled run" | |
| DOCKER_TAG=nightly | |
| REPO_REF=master | |
| fi | |
| docker build --build-arg oq_branch=$REPO_REF -t openquake/engine:$DOCKER_TAG -f docker/Dockerfile.dev docker | |
| echo "List Image" | |
| docker image ls | |
| # Test authentication on WebUI headless | |
| echo "Test WEBUI HEADLESS" | |
| cat > ./.env << EOF | |
| OQ_APPLICATION_MODE=RESTRICTED | |
| OQ_ADMIN_USERNAME=user | |
| OQ_ADMIN_PASSWORD=login | |
| [email protected] | |
| EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend' | |
| EMAIL_HOST=smtp.gmail.com | |
| EMAIL_PORT=587 | |
| EMAIL_USE_TLS=True | |
| [email protected] | |
| EMAIL_HOST_PASSWORD=polhjuih@ | |
| [email protected] | |
| DJANGO_SETTINGS_MODULE=openquake.server.settings | |
| EOF | |
| echo "docker run --name openquake -d --env-file=./.env -p 127.0.0.1:8800:8800 openquake/engine:$DOCKER_TAG " | |
| echo "Starting docker at: `date +"%Y-%m-%dT%H:%M:%S"`" | |
| docker run --name openquake -d --env-file=./.env -p 127.0.0.1:8800:8800 openquake/engine:$DOCKER_TAG | |
| sleep 180 | |
| docker logs openquake -t | |
| echo "Waiting WEBUI up on port 8800...." | |
| while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://127.0.0.1:8800/accounts/login/)" != "200" ]]; do | |
| echo "Still waiting WEBUI account login up on port 8800...." | |
| sleep 5 # wait for 5 seconds before check again | |
| done | |
| sleep 1 | |
| echo -n "TEST DJANGO LOGIN " | |
| LOGIN_URL=http://127.0.0.1:8800/accounts/login/ | |
| YOUR_USER='user' | |
| YOUR_PASS='login' | |
| COOKIES=cookies.txt | |
| CURL_BIN="curl -s -c $COOKIES -b $COOKIES -e $LOGIN_URL" | |
| echo -n "Django Auth: get csrftoken ..." | |
| $CURL_BIN $LOGIN_URL > /dev/null | |
| DJANGO_TOKEN="csrfmiddlewaretoken=$(grep csrftoken $COOKIES | sed 's/^.*csrftoken\s*//')" | |
| echo " perform login ..." | |
| $CURL_BIN \ | |
| -d "$DJANGO_TOKEN&username=$YOUR_USER&password=$YOUR_PASS" \ | |
| -X POST $LOGIN_URL > /dev/null | |
| docker logs -t -n 5 openquake | |
| echo "test run of calc on running container " | |
| time docker exec -t openquake oq engine --run /usr/src/oq-engine/demos/risk/ScenarioDamage/job_hazard.ini /usr/src/oq-engine/demos/risk/ScenarioDamage/job_risk.ini | |
| sleep 3 | |
| time docker exec -t openquake oq engine --run "https://github.com/gem/oq-engine/blob/master/openquake/server/tests/data/classical.zip?raw=true" | |
| echo "test run of a calcs on new created container" | |
| time docker run openquake/engine:$DOCKER_TAG oq engine --run "https://github.com/gem/oq-engine/blob/master/openquake/server/tests/data/classical.zip?raw=true" | |
| - name: push Openquake engine image on dockerhub | |
| run: | | |
| if [ ${{ github.event.inputs.version }} != '' ]; then | |
| echo "Is manual run" | |
| else | |
| echo "Is scheduled run" | |
| DOCKER_TAG=nightly | |
| REPO_REF=master | |
| fi | |
| docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" | |
| echo " push image engine with tag :$DOCKER_TAG on docker hub " | |
| docker push openquake/engine:$DOCKER_TAG |