Skip to content

Commit

Permalink
server config
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielXia committed May 31, 2017
1 parent eb92646 commit b4b887d
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 18 deletions.
20 changes: 16 additions & 4 deletions docker/iglu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
FROM postgres:9.6

MAINTAINER Gabriel Xia <ga.xiajin@gmail.com>

ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD postgres

RUN mkdir -p /etc/iglu/ && \
mkdir -p /opt/iglu/

WORKDIR /opt/iglu/

RUN apt-get update \
&& apt-get install default-jre -y
&& apt-get install default-jre -y \
&& apt-get install curl -y

COPY ./iglu-server-0.2.0.jar /opt/iglu/iglu-server-0.2.0.jar
COPY ./config/ /etc/iglu/config/
COPY ./script/iglu-upload.sh /opt/iglu/iglu-upload.sh
COPY ./iglu-terasology/ /etc/iglu/iglu-terasology/

COPY ./script/iglu-start.sh /docker-entrypoint-initdb.d/iglu-start.sh

COPY ./iglu-server-0.2.0.jar ./iglu-server-0.2.0.jar
COPY ./config/application.conf ./config/application.conf
COPY ./iglu-start.sh ./docker-entrypoint-initdb.d/iglu-start.sh
RUN chmod +x /opt/iglu/iglu-upload.sh

EXPOSE 8080
2 changes: 1 addition & 1 deletion docker/iglu/config/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# 'repo-server' contains configuration options for the repo-server.
repo-server {
interface = "localhost"
interface = "iglu"
port = 8080
}

Expand Down
13 changes: 0 additions & 13 deletions docker/iglu/iglu-start.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://localhost:8000/api/schemas/org.terasology/os/jsonschema/1-0-0#",
"description": "Schema for os information of a player",
"self": {
"vendor": "org.terasology",
"name": "os",
"format": "jsonschema",
"version": "1-0-0"
},
"type": "object",
"properties": {
"osName": {
"type": "string"
},
"osVersion": {
"type": "string"
},
"osArchitecture": {
"type": "string"
}
},
"required": [
"osName",
"osVersion",
"osArchitecture"
],
"additionalProperties": true
}
23 changes: 23 additions & 0 deletions docker/iglu/script/iglu-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE USER snowplow PASSWORD 'snowplow';
CREATE DATABASE iglu;
GRANT ALL PRIVILEGES ON DATABASE iglu TO snowplow;
EOSQL

echo "Initialising postgres data base"
java -Dconfig.file=/etc/iglu/config/application.conf -jar /opt/iglu/iglu-server-0.2.0.jar com.snowplowanalytics.iglu.server.Boot &

sleep 60

VALUE=$(PGPASSWORD=snowplow psql -v ON_ERROR_STOP=1 --username=snowplow --dbname=iglu <<-EOSQL
INSERT INTO apikeys (uid, vendor_prefix, permission, createdat) VALUES ('980ae3ab-3aba-4ffe-a3c2-3b2e24e2ffce','*','super',current_timestamp);
EOSQL)
echo $VALUE
echo "uploading terasology event schemas"
/opt/iglu/iglu-upload.sh http://iglu:8080 980ae3ab-3aba-4ffe-a3c2-3b2e24e2ffce /etc/iglu/iglu-terasology/schemas
78 changes: 78 additions & 0 deletions docker/iglu/script/iglu-upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

# Copyright (c) 2016 Snowplow Analytics Ltd. All rights reserved.
#
# This program is licensed to you under the Apache License Version 2.0, and
# you may not use this file except in compliance with the Apache License
# Version 2.0. You may obtain a copy of the Apache License Version 2.0 at
# http://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License Version 2.0 is distributed on an "AS
# IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the Apache License Version 2.0 for the specific language
# governing permissions and limitations there under.

# Script to upload all schemas in a folder to the Iglu repo
# Takes three arguments: the target repo host, the Super API key, and the input schema directory
# Uses PUT rather than POST, so existing schemas are overwritten

echo "================================="
echo " Starting Iglu Server Uploader"
echo "---------------------------------"

if [ "$#" -ne 3 ]
then
echo "ERROR: 3 arguments required, $# provided"
exit 1
fi

host=$1;
apikey=$2;
schemafolder=$3;

echo ""
echo "Making all_vendor API Keys:"
api_keys="$(curl --silent ${host}/api/auth/keygen -X POST -H "apikey: ${apikey}" -d "vendor_prefix=*")"
write_api_key="$(echo ${api_keys} | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["write"]')"
read_api_key="$(echo ${api_keys} | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["read"]')"
echo "Keys: $(echo ${api_keys} | xargs)"

echo ""
echo "Uploading all Schemas found in ${schemafolder}:"

good_counter=0
bad_counter=0

for schemapath in $(find $schemafolder -type f | grep 'jsonschema'); do
destination="$host/api/schemas/$(
# Keep the last 4 slash-separated components of the filename
echo $schemapath | awk -F '/' '{print $(NF-3)"/"$(NF-2)"/"$(NF-1)"/"$(NF)}';
)";
echo "Uploading schema in file '$schemapath' to endpoint '$destination'";
result="$(curl --silent "${destination}?isPublic=true" -XPUT -d @$schemapath -H "apikey: $write_api_key")";
echo " - Result: $(echo ${result} | xargs)"

# Process result
status="$(echo ${result} | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["status"]')"
if [[ "${status}" -eq "200" ]] || [[ "${status}" -eq "201" ]]; then
let good_counter=good_counter+1
else
let bad_counter=bad_counter+1
fi
done;

echo ""
echo "Result Counts:"
echo " - 200/201: ${good_counter}"
echo " - 400/401/500: ${bad_counter}"

echo ""
echo "Remove created API Keys:"
echo " - Remove ${write_api_key}: $(curl --silent ${host}/api/auth/keygen -X DELETE -H "apikey: ${apikey}" -d "key=${write_api_key}" | xargs)"
echo " - Remove ${read_api_key}: $(curl --silent ${host}/api/auth/keygen -X DELETE -H "apikey: ${apikey}" -d "key=${read_api_key}" | xargs)"

echo ""
echo "--------"
echo " Done "
echo "========"
13 changes: 13 additions & 0 deletions docker/snowplow/config/resolver.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@
"uri": "http://iglucentral.com"
}
}
},
{
"name": "Iglu-terasology",
"priority": 0,
"vendorPrefixes": [
"org.terasology"
],
"connection": {
"http": {
"uri": "http://iglu:8080/api"
}
}
}

]
}
}

0 comments on commit b4b887d

Please sign in to comment.