Test WebUI on RH based OS #812
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: Test WebUI on RH based OS | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| git-ref: | |
| description: Git Ref Branch | |
| default: master | |
| required: true | |
| schedule: | |
| - cron: "05 15 * * *" | |
| jobs: | |
| test_ui: | |
| name: Test on RH based (fedora container) | |
| runs-on: ubuntu-latest | |
| env: | |
| GITHUB_DEF_BR: ${{ github.event.repository.default_branch }} | |
| strategy: | |
| matrix: | |
| python-version: [python3.12] | |
| req-version: [py312] | |
| container: | |
| image: fedora:41 | |
| options: --privileged | |
| steps: | |
| - name: Clone Repository (Master) | |
| 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: Set up Python ${{ matrix.python-version }} and install OQ | |
| run: | | |
| set -x | |
| if [ -z ${{ github.event.inputs.git-ref }} ]; | |
| then | |
| BRANCH=master | |
| else | |
| BRANCH=${{ github.event.inputs.git-ref }} | |
| fi | |
| # Add openquake user | |
| useradd -m -u 1000 -s /bin/bash openquake | |
| # update system and install utilities | |
| dnf update -y | |
| dnf install -y ${{ matrix.python-version }} | |
| dnf install -y git git-lfs nc procps | |
| # define it | |
| mypython=${{ matrix.python-version }} | |
| reqpython=${{ matrix.req-version }} | |
| #run it | |
| eval '$mypython -c "import sys; print(sys.version)"' | |
| # | |
| # Add PIP to $mypython | |
| eval '$mypython -m ensurepip --upgrade' | |
| export PIP_DEFAULT_TIMEOUT=100 | |
| # | |
| echo "branch to test: ${BRANCH}" | |
| cd /__w/oq-engine/oq-engine/ | |
| eval '$mypython -m pip install -U pip setuptools wheel' | |
| eval '$mypython -m venv /opt/openquake/venv ' | |
| source /opt/openquake/venv/bin/activate | |
| eval '$mypython -m pip install -r "requirements-$reqpython-linux64.txt"' | |
| eval '$mypython -m pip install -e . ' | |
| ## Standalone apps | |
| echo "Downloading standalone apps" | |
| for app in oq-platform-standalone oq-platform-ipt oq-platform-taxonomy; do | |
| # do not fail on exit code 2 if the branch | |
| # does not exist in the app repository | |
| set +e | |
| git ls-remote --exit-code --heads https://github.com/gem/${app}.git $BRANCH >/dev/null 2>&1 | |
| EXIT_CODE=$? | |
| # set again to fail on exit code not 0 | |
| set -e | |
| if [[ $EXIT_CODE == '0' ]]; then | |
| echo "Git branch '$BRANCH' exists in the remote repository" | |
| TOOLS_BRANCH=$BRANCH | |
| elif [[ $EXIT_CODE == '2' ]]; then | |
| echo "Git branch '$BRANCH' does not exist in the remote repository" | |
| TOOLS_BRANCH=master | |
| fi | |
| echo "We need to use the branch $TOOLS_BRANCH for the standalone apps" | |
| git clone -b ${TOOLS_BRANCH} --depth=1 https://github.com/gem/${app}.git | |
| eval '$mypython -m pip install -e ./${app}' | |
| done | |
| deactivate | |
| - name: Actualize 'default' templates for email notifications | |
| run: | | |
| cd /__w/oq-engine/oq-engine/ | |
| for file in openquake/server/templates/registration/*.default.tmpl; do | |
| cp -- "$file" "${file%.default.tmpl}" | |
| done | |
| - name: WebUI and calculation with Auth | |
| run: | | |
| set -o pipefail | |
| source /opt/openquake/venv/bin/activate | |
| pip freeze | |
| mkdir -p /var/log/oq-engine/ | |
| chown -R openquake /var/log/oq-engine/ | |
| runuser -l openquake -c '/opt/openquake/venv/bin/oq engine --upgrade-db' | |
| oq --version | |
| # | |
| echo "Add settings for login and logging on webui before to start" | |
| cd /__w/oq-engine/oq-engine/ | |
| cd openquake/server | |
| cat > local_settings.py << EOF | |
| APPLICATION_MODE = "RESTRICTED" | |
| EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' | |
| EMAIL_HOST = 'smtp.gmail.com' | |
| EMAIL_PORT = 587 | |
| EMAIL_USE_TLS = True | |
| EMAIL_HOST_USER = '[email protected]' | |
| EMAIL_HOST_PASSWORD = 'polhjuih@' | |
| EMAIL_SUPPORT = '[email protected]' | |
| WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine' | |
| EOF | |
| echo "DISPLAY content of local_settings" | |
| cat local_settings.py | |
| # Perform migration after setup local_settings | |
| cd /__w/oq-engine/oq-engine/openquake/engine/ | |
| runuser -l openquake -c 'cd /__w/oq-engine/oq-engine/openquake/server/; /opt/openquake/venv/bin/python3 manage.py migrate' | |
| runuser -l openquake -c 'cd /__w/oq-engine/oq-engine/openquake/server/; /opt/openquake/venv/bin/python3 manage.py createuser openquake [email protected] --level 1 --password level_1_password --no-email' | |
| # Run help on manage.py | |
| runuser -l openquake -c 'cd /__w/oq-engine/oq-engine/openquake/server/; /opt/openquake/venv/bin/python3 manage.py help' | |
| # START WEBUI | |
| runuser -l openquake -c '/opt/openquake/venv/bin/oq webui start 127.0.0.1:8800 -s &' | |
| echo "Waiting WEBUI up on port 8800...." | |
| echo "Test WebUI with curl before to test django" | |
| 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 | |
| echo -n "TEST DJANGO LOGIN " | |
| LOGIN_URL=http://127.0.0.1:8800/accounts/login/ | |
| YOUR_USER='openquake' | |
| YOUR_PASS='level_1_password' | |
| COOKIES=cookies.txt | |
| CURL_BIN="curl -s -c $COOKIES -b $COOKIES -e $LOGIN_URL" | |
| echo -n "Django Auth: get csrftoken ..." | |
| $CURL_BIN $LOGIN_URL -o /dev/null | |
| DJANGO_TOKEN="csrfmiddlewaretoken=$(grep csrftoken $COOKIES | sed 's/^.*csrftoken\s*//')" | |
| echo " perform login ..." | |
| status_code=$($CURL_BIN -w "%{http_code}"\ | |
| -d "$DJANGO_TOKEN&username=$YOUR_USER&password=$YOUR_PASS" \ | |
| -X POST $LOGIN_URL -o /dev/null) | |
| if [ $status_code != "302" ]; then | |
| echo "Unable to login" | |
| exit 1 | |
| fi | |
| echo "--------------------" | |
| echo "display log of webui" | |
| echo "--------------------" | |
| cat /var/log/oq-engine/webui-access.log | |
| if [ -s /var/log/oq-engine/webui-access.log ]; then | |
| # The file is not-empty. | |
| cat /var/log/oq-engine/webui-access.log | |
| else | |
| echo "/var/log/oq-engine/webui-access.log is empty. Something did not work as expected" | |
| exit 1 | |
| fi | |
| echo " Run a calc using https" | |
| runuser -l openquake -c '/opt/openquake/venv/bin/oq engine --run https://downloads.openquake.org/jobs/M4_Exercise.zip' | |
| sleep 5 | |
| status_code=$($CURL_BIN -w "%{http_code}"\ | |
| -d "$DJANGO_TOKEN&username=$YOUR_USER&password=$YOUR_PASS" \ | |
| -G http://127.0.0.1:8800/engine/1/outputs -o /dev/null) | |
| if [ $status_code != "200" ]; then | |
| echo "Unable to visualize outputs" | |
| exit 1 | |
| fi | |
| - name: WebUI on PUBLIC | |
| run: | | |
| set -o pipefail | |
| source /opt/openquake/venv/bin/activate | |
| echo "Restart WebUI without authentication" | |
| runuser -l openquake -c 'pkill oq-webui' | |
| sleep 5 | |
| runuser -l openquake -c 'OQ_APPLICATION_MODE=PUBLIC /opt/openquake/venv/bin/oq webui start 127.0.0.1:8800 -s &' | |
| echo "Waiting WEBUI up on port 8800...." | |
| while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://127.0.0.1:8800/engine/)" != "200" ]]; do | |
| echo "Still waiting WEBUI on port 8800...." | |
| sleep 5 # wait for 5 seconds before check again | |
| done | |
| echo -n "Test Standalone Tools pages (without authentication)" | |
| read status_code redirect_url <<<"$( | |
| curl -s -o /dev/null -w "%{http_code} %{redirect_url}" http://127.0.0.1:8800/ | |
| )" | |
| if [ "$status_code" != "301" ] || [ "$redirect_url" != "http://127.0.0.1:8800/engine/" ]; then | |
| echo "Unexpected redirect: status=$status_code redirect=$redirect_url" | |
| echo "Should redirect to http://127.0.0.1:8800/engine/" | |
| exit 1 | |
| fi | |
| status_code=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8800/taxonomy/) | |
| if [ $status_code != "200" ]; then | |
| echo "Unable access the taxonomy standalone app" | |
| exit 1 | |
| fi | |
| status_code=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8800/ipt/) | |
| if [ $status_code != "200" ]; then | |
| echo "Unable to access the ipt standalone app" | |
| exit 1 | |
| fi | |
| echo " Run a calc using https" | |
| runuser -l openquake -c '/opt/openquake/venv/bin/oq engine --run https://downloads.openquake.org/jobs/eb_risk_demo.zip' |