Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate JSONB elements and staging deployment #26

Merged
merged 25 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
96d3b6b
Update aggregation queries to use JSON columns
mojodna Jun 10, 2019
20e4b33
refreshments schema
mojodna Jun 17, 2019
efecee2
Generate JSONB tables
mojodna Jun 17, 2019
df239a3
Drop unnecessary tables
mojodna Jun 17, 2019
6ed90fd
Allow password to be omitted
mojodna Jun 17, 2019
a9cd26d
Misc: see full message
mojodna Jun 17, 2019
72c18b9
Tiles should always be gzipped
mojodna Jun 17, 2019
2505e0a
Use edit counts for ranking country users and hashtags
mojodna Aug 7, 2019
610a6c6
Use edit counts for ranking hashtag users
mojodna Aug 7, 2019
131a88c
Use edit counts for ranking user countries, editors, and hashtags
mojodna Aug 7, 2019
5f88fa3
Merge branch 'develop' into jsonb-stats
mojodna Aug 7, 2019
7cb2556
Statistics by user and hashtag
mojodna Sep 7, 2019
a4891e8
Refresh hashtag/user stats
mojodna Sep 7, 2019
fded5ab
Merge pull request #20 from mojodna/jsonb-stats
mojodna Sep 11, 2019
3c9983c
Start reorganization of deployment scripts
jpolchlo Aug 21, 2019
38e4263
Fix container build procedure
jpolchlo Aug 21, 2019
d43d6dd
Improvements to task management; stat server now deploys properly
jpolchlo Aug 21, 2019
0bec1a1
Complete deployment scripts (tested in staging environment)
jpolchlo Aug 23, 2019
5e96985
Bring SQL queries in line with deployed DB schema
jpolchlo Aug 23, 2019
f3a30a9
Name hashtag_user_statistics correctly
mojodna Sep 14, 2019
c844a42
Surface edit count
mojodna Sep 14, 2019
a16728d
Hashtag user stats endpoint
mojodna Sep 14, 2019
5156a5b
Provide a default JDBC driver
mojodna Sep 15, 2019
7d65999
Improve naming
mojodna Sep 15, 2019
0aa5400
Merge pull request #24 from jpolchlo/feature/staging-deployment-w-cam…
jpolchlo Sep 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions deployment/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
config-aws.mk
docker-compose.deploy.yml
config-*.mk
102 changes: 48 additions & 54 deletions deployment/Makefile
Original file line number Diff line number Diff line change
@@ -1,71 +1,65 @@
include config-aws.mk # Variables for AWS options
include config-deployment.mk

# The osmesa container
LOCAL_IMG := quay.io/geotrellis/osm-stat-server:latest
# If the user is on master branch, see if we should deploy to production
VERSION_TAG=$(shell ./scripts/get-tag.sh)
ifeq ($(VERSION_TAG), production)
DATABASE=${PRODUCTION_DB}
ECS_CLUSTER=${CLUSTER_NAME_DEPLOYMENT}
TASK_SUFFIX=
else
DATABASE=${STAGING_DB}
ECS_CLUSTER=${CLUSTER_NAME_STAGING}
TASK_SUFFIX=-staging
endif
DB_URI=${DB_BASE_URI}/${DATABASE}

.EXPORT_ALL_VARIABLES:

#########
# AWS #
#########
#############################
# Docker image management #
#############################

.PHONY: login-aws-registry tag-image push-image

build-container:
./build-container.sh

login-aws-registry:
eval `aws ecr get-login --no-include-email --region ${AWS_REGION}`

tag-image:
docker tag ${LOCAL_IMG} ${ECR_REPO}
tag-image: build-container
docker tag osm_stat_server:${VERSION_TAG} ${ECR_IMAGE}:${VERSION_TAG}

push-image: login-aws-registry tag-image
docker push ${ECR_REPO}

.PHONY: docker-compose.deploy.yml

docker-compose.deploy.yml:
./expand.sh docker-compose.deploy.yml.tpl > docker-compose.deploy.yml

configure-cluster:
ecs-cli configure \
--cluster ${CLUSTER_NAME} \
--region ${AWS_REGION} \
--config-name ${CONFIG_NAME}

cluster-up:
ecs-cli up \
--keypair ${KEYPAIR} \
--instance-role ${INSTANCE_ROLE} \
--size 1 \
--instance-type ${INSTANCE_TYPE} \
--cluster-config ${CONFIG_NAME} \
--subnets ${SUBNETS} \
--vpc ${VPC} \
--force \
--verbose

cluster-down:
ecs-cli down --cluster-config ${CONFIG_NAME}
docker push ${ECR_IMAGE}:${VERSION_TAG}

.PHONY: create-service
#######################
# Streaming AWS Tasks #
#######################

create-service: docker-compose.deploy.yml configure-cluster
ecs-cli compose \
--file $< create \
--cluster ${CLUSTER_NAME}
.PHONY: create-log-groups define-production-tasks define-staging-tasks stop-stat-server deploy-stat-server

start-service: docker-compose.deploy.yml configure-cluster create-service
ecs-cli compose --file $< service up \
--deployment-min-healthy-percent 0 \
--create-log-groups \
--cluster ${CLUSTER_NAME}
create-log-groups:
./scripts/create-log-groups.sh

stop-service:
ecs-cli compose down
define-staging-tasks:
./scripts/define-staging-tasks.sh

define-production-tasks:
./scripts/define-production-tasks.sh

#########
# ALL #
#########
build-image:
make -C .. build
stop-stat-server:
./scripts/stop-stat-server.sh

clean:
rm -f docker-compose.deploy.yml
deploy-stat-server: stop-stat-server
aws ecs create-service \
--cluster "${ECS_CLUSTER}" \
--service-name "osmesa-stats-server" \
--task-definition "osmesa-stat-server${TASK_SUFFIX}" \
--desired-count 1 \
--launch-type FARGATE \
--scheduling-strategy REPLICA \
--network-configuration ${NETWORK_CONFIGURATION}

deploy-stats-refresher:
./scripts/deploy-stats-refresher.sh
22 changes: 22 additions & 0 deletions deployment/build-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

if [ -z ${VERSION_TAG+x} ]; then
echo "No version tag has been set. Do not run this script directly; instead, issue"
echo " make build-container"
echo "from the 'streaming' directory."
exit 1
else
echo "Version tag is set to '${VERSION_TAG}'"
fi

set -xe
SBT_DIR=$(pwd)/..
JAR_DIR=${SBT_DIR}/target/scala-2.11/
DOCKER_DIR=$(pwd)/docker

cd ${SBT_DIR}
./sbt clean assembly
cp ${JAR_DIR}/osm-stat-server.jar ${DOCKER_DIR}/osm-stat-server.jar

cd ${DOCKER_DIR}
docker build -f Dockerfile --tag osm_stat_server:${VERSION_TAG} .
28 changes: 0 additions & 28 deletions deployment/config-aws.mk.example

This file was deleted.

23 changes: 23 additions & 0 deletions deployment/config-deployment.mk.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
################################################################################
# AWS properties
################################################################################
export KEYPAIR :=
export SUBNET :=
export AWS_REGION := us-east-1
export IAM_ACCOUNT :=

################################################################################
# Streaming resource definitions
################################################################################
export STREAMING_INSTANCE_TYPE := m4.xlarge
export ECR_IMAGE :=
export AWS_LOG_GROUP := osmesa-stats-server
export ECS_SUBNET := ${SUBNET}
export ECS_SECURITY_GROUP :=

export CLUSTER_NAME_DEPLOYMENT :=
export CLUSTER_NAME_STAGING :=

export DB_BASE_URI :=
export PRODUCTION_DB :=
export STAGING_DB :=
24 changes: 0 additions & 24 deletions deployment/docker-compose.deploy.yml.tpl

This file was deleted.

1 change: 1 addition & 0 deletions deployment/docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.jar
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ RUN \
COPY osm-stat-server.jar /opt/osm-stat-server.jar
COPY refresh-views.sh /usr/local/bin/refresh-views.sh

WORKDIR /opt
WORKDIR /opt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/usr/bin/env bash

echo "$(date --iso-8601=seconds): Starting view refreshment"

if [ "$(psql -Aqtc "select count(pid) from pg_stat_activity where query ilike 'refresh materialized view concurrently user_statistics%' and state='active'" $DATABASE_URL 2> /dev/null)" == "0" ]; then
echo "$(date --iso-8601=seconds): Refreshing user statistics"
# refresh in the background to return immediately
psql -Aqt \
-c "REFRESH MATERIALIZED VIEW CONCURRENTLY user_statistics" \
-c "UPDATE refreshments SET updated_at=now() where mat_view='user_statistics'" \
$DATABASE_URL &
else
echo "$(date --iso-8601=seconds): User stats table already refreshing"
fi

if [ "$(psql -Aqtc "select count(pid) from pg_stat_activity where query ilike 'refresh materialized view concurrently hashtag_statistics%' and state='active'" $DATABASE_URL 2> /dev/null)" == "0" ]; then
Expand All @@ -16,6 +20,8 @@ if [ "$(psql -Aqtc "select count(pid) from pg_stat_activity where query ilike 'r
-c "REFRESH MATERIALIZED VIEW CONCURRENTLY hashtag_statistics" \
-c "UPDATE refreshments SET updated_at=now() where mat_view='hashtag_statistics'" \
$DATABASE_URL &
else
echo "$(date --iso-8601=seconds): Hashtag stats table already refreshing"
fi

if [ "$(psql -Aqtc "select count(pid) from pg_stat_activity where query ilike 'refresh materialized view concurrently country_statistics%' and state='active'" $DATABASE_URL 2> /dev/null)" == "0" ]; then
Expand All @@ -25,6 +31,17 @@ if [ "$(psql -Aqtc "select count(pid) from pg_stat_activity where query ilike 'r
-c "REFRESH MATERIALIZED VIEW CONCURRENTLY country_statistics" \
-c "UPDATE refreshments SET updated_at=now() where mat_view='country_statistics'" \
$DATABASE_URL &
else
echo "$(date --iso-8601=seconds): Country stats table already refreshing"
fi

if [ "$(psql -Aqtc "select count(pid) from pg_stat_activity where query ilike 'refresh materialized view concurrently hashtag_user_statistics%' and state='active'" $DATABASE_URL 2> /dev/null)" == "0" ]; then
# refresh in the background to return immediately
echo "$(date --iso-8601=seconds): Refreshing hashtag/user statistics"
psql -Aqt \
-c "REFRESH MATERIALIZED VIEW CONCURRENTLY hashtag_user_statistics" \
-c "UPDATE refreshments SET updated_at=now() where mat_view='hashtag_user_statistics'" \
$DATABASE_URL &
fi

wait
Expand Down
8 changes: 0 additions & 8 deletions deployment/ecs-params.yml

This file was deleted.

21 changes: 0 additions & 21 deletions deployment/expand.sh

This file was deleted.

18 changes: 18 additions & 0 deletions deployment/scripts/create-log-groups.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

if [ -z ${VERSION_TAG+x} ]; then
echo "Do not run this script directly. Use the Makefile in the parent directory."
exit 1
fi

DEFINED_GROUPS=$(aws logs describe-log-groups | jq '.logGroups[].logGroupName' | sed -e 's/"//g')

if [[ $DEFINED_GROUPS != *"/ecs/${AWS_LOG_GROUP}"* ]]; then
aws logs create-log-group \
--log-group-name /ecs/${AWS_LOG_GROUP}
fi

if [[ $DEFINED_GROUPS != *"/ecs/${AWS_LOG_GROUP}-staging"* ]]; then
aws logs create-log-group \
--log-group-name /ecs/${AWS_LOG_GROUP}-staging
fi
Loading