Skip to content

Commit

Permalink
Add micka for dev & test, test CSW Transaction Insert
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Dec 23, 2019
1 parent 1b8dcff commit 8db5f19
Show file tree
Hide file tree
Showing 25 changed files with 589 additions and 33 deletions.
8 changes: 8 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ OAUTH2_LIFERAY_INTROSPECTION_URL=http://liferay:8080/o/oauth2/introspect
OAUTH2_LIFERAY_USER_PROFILE_URL=http://liferay:8080/api/jsonws/user/get-current-user


##############################################################################
# Micka settings #############################################################
##############################################################################
CSW_URL=http://micka:80/csw
CSW_BASIC_AUTHN=editor:editor
CSW_RECORD_URL=http://localhost:3080/record/basic/{identifier}


##############################################################################
# Flask settings #############################################################
##############################################################################
Expand Down
8 changes: 8 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ OAUTH2_LIFERAY_CLIENT1_ID=test-id-for-client-with-pkce-flow
OAUTH2_LIFERAY_AUTH_URL=http://localhost:8082/o/oauth2/authorize


##############################################################################
# Micka settings #############################################################
##############################################################################
CSW_URL=http://micka:80/csw
CSW_BASIC_AUTHN=editor:editor
CSW_RECORD_URL=http://localhost:3080/record/basic/{identifier}


##############################################################################
# Flask settings #############################################################
##############################################################################
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ make start-dev
- all workspaces accessible namely by [LAYMAN_GS_ROLE](doc/env-settings.md#LAYMAN_GS_ROLE)!
- all keys in Redis logical database identified by [LAYMAN_REDIS_URL](doc/env-settings.md#LAYMAN_REDIS_URL)!
- all keys in Redis logical database identified by [LTC_REDIS_URL](doc/env-settings.md#LTC_REDIS_URL)!
- all metadata records from CSW identified by [CSW_URL](doc/env-settings.md#CSW_URL)!

Default values are defined in [.env.test](.env.test)
```bash
Expand Down
9 changes: 9 additions & 0 deletions deps/micka/docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# connection parameters to PostgreSQL database
PG_HOST=postgresql
PG_PORT=5432
PG_DBNAME=hsrs_micka6
PG_USER=docker
PG_PASSWORD=docker
PG_TEMPLATE_DBNAME=template_postgis

INIT_SQL_FILE_PATHS=/var/www/html/Micka/php/install/2_create_table.sql,/var/www/html/Micka/php/install/3_insert_data_basic.sql,/var/www/html/Micka/php/install/4_insert_standard_schema.sql,/var/www/html/Micka/php/install/5_insert_profiles.sql,/var/www/html/Micka/php/install/6_00_label_eng.sql,/var/www/html/Micka/php/install/6_01_label_cze.sql
92 changes: 92 additions & 0 deletions deps/micka/docker/code/src/wait_for_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import os
import sys
import time

ATTEMPT_INTERVAL = 2
MAX_ATTEMPTS = 60


PG_HOST = os.environ['PG_HOST']
PG_PORT = os.environ['PG_PORT']
PG_DBNAME = os.environ['PG_DBNAME']
PG_USER = os.environ['PG_USER']
PG_PASSWORD = os.environ['PG_PASSWORD']
PG_CONN = {
'host': PG_HOST,
'port': PG_PORT,
'dbname': PG_DBNAME,
'user': PG_USER,
'password': PG_PASSWORD,
}
PG_TEMPLATE_DBNAME = os.environ['PG_TEMPLATE_DBNAME']
INIT_SQL_FILE_PATHS = os.environ['INIT_SQL_FILE_PATHS'].split(',')



def main():

attempt = 1

# PostgreSQL (try to connect to default 'postgres' database
pg_conn_dict = PG_CONN.copy()
pg_conn_dict['dbname'] = 'postgres'
secret_conn_dict = {k: v for k, v in pg_conn_dict.items() if k != 'password'}
wait_for_msg = f"PostgreSQL database, {secret_conn_dict}"
print(f"Waiting for {wait_for_msg}")
while True:
import psycopg2
try:
with psycopg2.connect(**pg_conn_dict) as conn:
pass
print(f"Attempt {attempt}/{MAX_ATTEMPTS} successful.")
break
except psycopg2.OperationalError as e:
handle_exception(e, attempt, wait_for_msg)
attempt += 1
print()



micka_conn_dict = PG_CONN.copy()
dbname = micka_conn_dict['dbname']
print(f"Checking existence of {dbname} database")

try:
with psycopg2.connect(**micka_conn_dict):
pass
print(f"Database {dbname} exists.")
except psycopg2.OperationalError as e:
print(f"Database {dbname} does not exist, creating")
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
with psycopg2.connect(**pg_conn_dict) as pg_conn:
pg_conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
cur = pg_conn.cursor()
cur.execute(f"CREATE DATABASE {dbname} WITH TEMPLATE={PG_TEMPLATE_DBNAME} ENCODING='UTF8' CONNECTION LIMIT=-1;")
cur.close()
print(f"Database {dbname} created")
with psycopg2.connect(**micka_conn_dict) as micka_conn:
cur = micka_conn.cursor()
for init_sql_file_path in INIT_SQL_FILE_PATHS:
print(f"Running SQL file {init_sql_file_path}")
cur.execute(open(init_sql_file_path, "r", encoding="utf-8").read())
cur.close()


def handle_exception(e, attempt, wait_for_msg=None):
if attempt < MAX_ATTEMPTS:
msg_end = f"Waiting {ATTEMPT_INTERVAL} seconds before next attempt."
else:
msg_end = "Max attempts reached!"
# print(f"Attempt {attempt}/{MAX_ATTEMPTS} failed:")
# print(e)
# print(msg_end)
# traceback.print_exc()
if attempt >= MAX_ATTEMPTS:
print(f"Reaching max attempts when waiting for {wait_for_msg}")
sys.exit(1)
# raise e
time.sleep(ATTEMPT_INTERVAL)


if __name__ == "__main__":
main()
86 changes: 86 additions & 0 deletions deps/micka/sample/confs/config.local.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
parameters:
app:
# UI theme
layoutTheme = default
# UI langauges (must have translation files)
langs = 'eng,cze'
# dafult profile used
startProfil = 5
#records per page
maxRecords = 10
#max number of records per page
limitMaxRecords = 100
#default sort
sortBy = 'title,ASC'
importReport = FALSE
#switch the validator
validator = TRUE
directSummary = TRUE
directDetail = TRUE
directXml = TRUE
formSign = FALSE
defaultEditGroup = editor
defaultViewGroup = reader
# record indication for access from csw etc.
mdDataType = "-1=>'semifinished',0=>'private',1=>'public',2=>'portal'"
# admin IP list
adminIP = '127.0.0.1'
# web proxy address
proxy =
map:
# initial map extent
hs_initext = 12.0 48.5 18.9 51
# address of the connected WMS viewer web app
viewerURL = "https://geoportal.gov.cz/web/guest/map"
contact:
#contact info used in Capabilities document etc.
title:
cze = "Katalog prostorových metadat."
eng = "Spatial Metadata Catalogue."
abstract:
eng = "Catalogue based on OGC Catalogue service 2.0.2 ISO AP 1.0"
cze = "Katalog prostorových metadat podle OGC CSW 2.0.2 ISO AP 1.0"
org:
eng = "Your company name"
cze = "Název vaší organizace"
person = "Your name"
position:
eng = "Responsible preson"
cze = "Zodpovědná osoba"
email = ""
delivery = "your delivery point"
city = ""
postcode = ""
phone = ""
www = ""
langCodes:
cs: cze
da: dan
de: ger
en: eng
es: spa
fi: fin
fr: fre
hu: hun
it: ita
lv: lav
no: nor
pl: pol
pt: por
sk: slo
sl: slv
sv: swe

database:
dsn: 'pgsql:host=postgresql;dbname=hsrs_micka6;port=5432'
user: 'docker'
password: 'docker'
debugger: false
options:
lazy: yes

translation:
default: en
fallback: [cs]
resolvers:
header: off
105 changes: 105 additions & 0 deletions deps/micka/sample/confs/default
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html/Micka;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

#location / {
# # First attempt to serve request as file, then
# # as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
#}

location / {
try_files $uri /index.php$is_args$args;

location ~ /(.*\.php)(/.*)?$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php5.6-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

location ~ /\.ht {
deny all;
}
}

# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
9 changes: 9 additions & 0 deletions doc/env-settings.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Environment Settings

## CSW_BASIC_AUTHN
HTTP Basic Authentication credentials for communication with [CSW](#CSW_URL) encoded as `user:password`.

## CSW_RECORD_URL
URL of [CSW](#CSW_URL) metadata record accessible by web browser, probably with some editing capabilities. Must contain `{identifier}` string that will be replaced with record ID.

## CSW_URL
URL of [OGC Catalogue Service v2.0.2](https://www.opengeospatial.org/standards/cat) endpoint. Tested with [Micka](http://micka.bnhelp.cz/).

## FLASK_APP
See [Flask documentation](https://flask.palletsprojects.com/en/1.1.x/cli/#application-discovery).

Expand Down
16 changes: 16 additions & 0 deletions docker-compose.deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,19 @@ services:
# https://github.com/docker/compose/issues/3270#issuecomment-206214034
# ./deps/liferay/tmp must be owned by non-root
- ./deps/liferay/sample/hypersonic:/etc/liferay/mount/files/data/hypersonic

micka:
container_name: micka
image: jirikcz/micka:micka-e6f083b-v1.0.0
command: bash -c "cd /code/src && python3 wait_for_deps.py && /etc/init.d/php5.6-fpm start && nginx -g 'daemon off;'"
env_file:
- deps/micka/docker/.env
ports:
- 3080:80
volumes:
- ./deps/micka/data:/var/lib/postgresql/data
- ./deps/micka/docker/code/src:/code/src
- ./deps/micka/sample/confs/config.local.neon:/var/www/html/Micka/php/app/config/config.local.neon
- ./deps/micka/sample/confs/default:/etc/nginx/sites-available/default
depends_on:
- postgresql
1 change: 1 addition & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
- postgresql
- geoserver
- layman_client
- micka

celery_worker_dev:
image: layman_dev:latest
Expand Down
1 change: 1 addition & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
- redis
- postgresql
- geoserver
- micka

hslayers:
container_name: hslayers
Expand Down
Loading

0 comments on commit 8db5f19

Please sign in to comment.