Skip to content

Commit

Permalink
fix docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelchin committed Jan 26, 2024
1 parent d834080 commit ad8f178
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-and-push-docker.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and push docker
name: build and push docker

on:
push:
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
name: Create cross-platform images
run: |
docker buildx imagetools create -t gplates/postgis:${{github.ref_name}} gplates/postgis:amd64-${{github.ref_name}} gplates/postgis:arm64-${{github.ref_name}}
docker buildx imagetools create -t gplates/postgis:latest gplates/postgis:amd64-${{github.ref_name}} gplates/postgis:arm64-${{github.ref_name}}
docker buildx imagetools create -t gplates/gws:latest gplates/gws:amd64-${{github.ref_name}} gplates/gws:arm64-${{github.ref_name}}
docker buildx imagetools create -t gplates/gws:${{github.ref_name}} gplates/gws:amd64-${{github.ref_name}} gplates/gws:arm64-${{github.ref_name}}
#docker buildx imagetools create -t gplates/postgis:latest gplates/postgis:amd64-${{github.ref_name}} gplates/postgis:arm64-${{github.ref_name}}
#docker buildx imagetools create -t gplates/gws:latest gplates/gws:amd64-${{github.ref_name}} gplates/gws:arm64-${{github.ref_name}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Push Docker latest and test Docker Compose
name: release test

on:
release:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit Test
name: unittest

on:
pull_request:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# GPlates Web Service

![Test](https://github.com/gplates/gplates-web-service/actions/workflows/test.yml/badge.svg)
![Build Docker](https://github.com/gplates/gplates-web-service/actions/workflows/build-and-push-docker.yml/badge.svg)
![Release Test](https://github.com/gplates/gplates-web-service/actions/workflows/release-test.yml/badge.svg)

The **🔥GPlates Web Service🔥** is a part of the on-going GPlates project funded by [AuScope](https://www.auscope.org.au/).
The web service is built upon [pygplates](https://www.gplates.org/docs/pygplates/index.html).
Expand Down
70 changes: 56 additions & 14 deletions django/GWS/GWS/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import logging
import os
import queue
import random
Expand All @@ -18,15 +19,54 @@

from dotenv import load_dotenv

logger = logging.getLogger("default")

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(
os.path.dirname(os.path.abspath(__file__))
) # call dirname() twice to get "../"

sys.path.append(f"{BASE_DIR}/lib")

DEBUG = os.getenv("DEBUG")
SECRET_KEY = os.getenv("SECRET_KEY")
DB_NAME = os.getenv("DB_NAME")
DB_USER = os.getenv("DB_USER")
DB_HOST = os.getenv("DB_HOST")
DB_PORT = os.getenv("DB_PORT")
DB_PASSWORD = os.getenv("DB_PASSWORD")
THROTTLE = os.getenv("THROTTLE")
DEFAULT_THROTTLE_ANON_RATE = os.getenv("DEFAULT_THROTTLE_ANON_RATE")
DEFAULT_THROTTLE_USER_RATE = os.getenv("DEFAULT_THROTTLE_USER_RATE")
BING_KEY = os.getenv("BING_KEY")
CACHE_NAME = os.getenv("CACHE_NAME")

load_dotenv(f"{BASE_DIR}/.env") # take environment variables from .env.

DEBUG = os.getenv("DEBUG") if DEBUG is None else DEBUG
SECRET_KEY = os.getenv("SECRET_KEY") if SECRET_KEY is None else SECRET_KEY
DB_NAME = os.getenv("DB_NAME") if DB_NAME is None else DB_NAME
DB_USER = os.getenv("DB_USER") if DB_USER is None else DB_USER
DB_HOST = os.getenv("DB_HOST") if DB_HOST is None else DB_HOST
DB_PORT = os.getenv("DB_PORT") if DB_PORT is None else DB_PORT
DB_PASSWORD = os.getenv("DB_PASSWORD") if DB_PASSWORD is None else DB_PASSWORD
THROTTLE = os.getenv("THROTTLE") if THROTTLE is None else THROTTLE
DEFAULT_THROTTLE_ANON_RATE = (
os.getenv("DEFAULT_THROTTLE_ANON_RATE")
if DEFAULT_THROTTLE_ANON_RATE is None
else DEFAULT_THROTTLE_ANON_RATE
)
DEFAULT_THROTTLE_USER_RATE = (
os.getenv("DEFAULT_THROTTLE_USER_RATE")
if DEFAULT_THROTTLE_USER_RATE is None
else DEFAULT_THROTTLE_USER_RATE
)
BING_KEY = os.getenv("BING_KEY") if BING_KEY is None else BING_KEY
CACHE_NAME = os.getenv("CACHE_NAME") if CACHE_NAME is None else CACHE_NAME

if not CACHE_NAME:
CACHE_NAME = "default"

EARTH_STORE_DIR = f"{BASE_DIR}/data/earth/"
PALEO_STORE_DIR = f"{BASE_DIR}/data/paleo/"
MODEL_REPO_DIR = f"{BASE_DIR}/data/model-repo/"
Expand All @@ -43,7 +83,6 @@
# ************
# SEE HERE!!! best to put the SECRET_KEY in your .env file
# ************
SECRET_KEY = os.getenv("SECRET_KEY")
# alternatively, put SECRET_KEY here, but do not submit the SECRET_KEY to code repository
# SECRET_KEY = 'put your secret key here' # better not do this!!!
if not SECRET_KEY:
Expand All @@ -57,7 +96,7 @@


# SECURITY WARNING: don't run with debug turned on in production!
if os.getenv("DEBUG") and os.getenv("DEBUG").lower() == "true":
if isinstance(DEBUG, str) and (DEBUG.strip().lower() == "true" or DEBUG.strip() == "1"):
DEBUG = True
else:
DEBUG = False
Expand Down Expand Up @@ -128,15 +167,13 @@
"default": {
# 'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
"ENGINE": "django.contrib.gis.db.backends.postgis",
"NAME": os.getenv(
"DB_NAME"
), # Database name. Or path to database file if using sqlite3.
"NAME": DB_NAME, # Database name. Or path to database file if using sqlite3.
# Database username. Not used with sqlite3.
"USER": os.getenv("DB_USER"),
"HOST": os.getenv("DB_HOST"), # Database hostname
"PASSWORD": os.getenv("DB_PASSWORD"), # Database password for USER
"USER": DB_USER,
"HOST": DB_HOST, # Database hostname
"PASSWORD": DB_PASSWORD, # Database password for USER
# Set to empty string for default. Not used with sqlite3.
"PORT": os.getenv("DB_PORT"),
"PORT": DB_PORT,
}
}

Expand Down Expand Up @@ -181,9 +218,11 @@
STATIC_ROOT = "/var/www/html/static/"
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)

DEFAULT_THROTTLE_ANON_RATE = os.getenv("DEFAULT_THROTTLE_ANON_RATE") or "10000/second"
if DEFAULT_THROTTLE_ANON_RATE is None:
DEFAULT_THROTTLE_ANON_RATE = "10000/second"

DEFAULT_THROTTLE_USER_RATE = os.getenv("DEFAULT_THROTTLE_USER_RATE") or "10000/second"
if DEFAULT_THROTTLE_USER_RATE is None:
DEFAULT_THROTTLE_USER_RATE = "10000/second"

REST_FRAMEWORK = {
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
Expand All @@ -199,7 +238,12 @@
}

# flag to indicate if the traffic should be throttled.
THROTTLE = os.getenv("THROTTLE") and os.getenv("THROTTLE").lower() == "true"
if isinstance(THROTTLE, str) and (
THROTTLE.strip().lower() == "true" or THROTTLE.strip() == "1"
):
THROTTLE = True
else:
THROTTLE = False

if DEBUG:
logger_level = "DEBUG"
Expand Down Expand Up @@ -275,5 +319,3 @@
"LOCATION": "redis://gws-redis:6379",
},
}

CACHE_NAME = os.getenv("CACHE") if os.getenv("CACHE") else "default"
12 changes: 7 additions & 5 deletions docker/docker-compose-mc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ services:
gws-postgis:
image: gplates/postgis
networks:
- gws-net
- gplates-net
hostname: gws-postgis
volumes:
- gws-db-data:/var/lib/postgresql/15/main
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD="this is not a real password! go away!"
- POSTGRES_PASSWORD=gplates
restart: on-failure
healthcheck:
test: pg_isready -U gplates -d gplates
Expand All @@ -31,7 +31,7 @@ services:
gws:
image: gplates/gws
networks:
- gws-net
- gplates-net
hostname: gws
depends_on:
- gws-postgis
Expand All @@ -40,6 +40,8 @@ services:
- gws-code:/gws
ports:
- 18000:80
environment:
- DB_PASSWORD=zaq12wsx
restart: on-failure
healthcheck:
test: curl --fail -s "http://localhost:80/raster/query?lon=128.86&lat=-12.42&raster_name=crustal_thickness" || exit 1
Expand All @@ -50,7 +52,7 @@ services:
gws-redis:
image: redis
networks:
- gws-net
- gplates-net
hostname: gws-redis
restart: on-failure
healthcheck:
Expand All @@ -61,5 +63,5 @@ services:


networks:
gws-net:
gplates-net:
external: true
2 changes: 1 addition & 1 deletion docker/start-gws-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
BASEDIR=$(dirname "$0")
echo "$BASEDIR"
cd $BASEDIR
docker-compose run -f docker-compose-mc.yml --rm --service-ports gws /bin/bash -c "cd /gws/django/GWS && python3 manage.py runserver 0.0.0.0:80"
docker-compose -f docker-compose-mc.yml run --rm --service-ports gws /bin/bash -c "cd /gws/django/GWS && python3 manage.py runserver 0.0.0.0:80"
2 changes: 1 addition & 1 deletion docker/start-postgis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
BASEDIR=$(dirname "$0")
echo "$BASEDIR"
cd $BASEDIR
docker-compose run -f docker-compose-mc.yml --rm --service-ports gws-postgis
docker-compose -f docker-compose-mc.yml run --rm --service-ports gws-postgis
2 changes: 1 addition & 1 deletion docker/start-redis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
BASEDIR=$(dirname "$0")
echo "$BASEDIR"
cd $BASEDIR
docker-compose run -f docker-compose-mc.yml --rm --service-ports gws-redis
docker-compose -f docker-compose-mc.yml run --rm --service-ports gws-redis

0 comments on commit ad8f178

Please sign in to comment.