Skip to content

Commit

Permalink
Fix deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Feb 9, 2017
1 parent 9d1bb19 commit b007ce5
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/apache/mapcache.xml
/deploy/deploy.cfg
/deploy/hooks/pre-restore-database
/deploy/hooks/post-restore
/alembic.ini
/alembic_static.ini
/development.ini
Expand Down
6 changes: 4 additions & 2 deletions CONST_Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ EGGS_DEPENDENCIES += .build/venv.timestamp-noclean setup.py \
$(CONST_REQUIREMENT)
REQUIREMENTS ?= c2cgeoportal==2.2.0.dev4
REQUIREMENTS += -r $(CONST_REQUIREMENT)
DEV_REQUIREMENTS += -r CONST_fixversions.txt
DEV_REQUIREMENTS += -r CONST_dev-requirements.txt
ifeq ($(TILECLOUD_CHAIN), TRUE)
DEV_REQUIREMENTS += $(TILECLOUD_VERSION) $(TILECLOUDCHAIN_VERSION)
Expand Down Expand Up @@ -1305,7 +1306,8 @@ $(WMTSCAPABILITIES_FILE): tilegeneration/config.yaml .build/dev-requirements.tim
$(VENV_BIN)/generate_controller --capabilities

# Version
.PHONY: $(PACKAGE)/version.py
$(PACKAGE)/version.py:
$(VENV_BIN)/version.py$(PYTHON_BIN_POSTFIX): .build/requirements.timestamp

$(PACKAGE)/version.py: $(VENV_BIN)/gen-version$(PYTHON_BIN_POSTFIX)
@echo "# Auto-generated file. Do not Edit!" > $@
@$(VENV_BIN)/gen-version >> $@
3 changes: 0 additions & 3 deletions deploy/hooks/post-restore-code
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@

PROJECT_NAME=$1
CODE_DIR=$2

cd $CODE_DIR
make -f $TARGET.mk template-clean
2 changes: 1 addition & 1 deletion deploy/hooks/post-restore.mako
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh -ex

cd ${deploy["code_destination"]}
make -f $TARGET.mk build
make -f $TARGET.mk build -j2
8 changes: 8 additions & 0 deletions deploy/hooks/pre-restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh -ex
#
# variables set here:
# $TARGET: name of the symbolic remote host key (see remote_hosts
# section in config file)
#

echo "Deploy '$TARGET' at `date`" > /tmp/np
51 changes: 28 additions & 23 deletions deploy/hooks/pre-restore-database.mako
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh -e
#!/bin/sh -ex
#
# variables set here:
# $TARGET: name of the symbolic remote host key (see remote_hosts
Expand All @@ -7,31 +7,36 @@

DATABASES=$@

cd "${directory}"
make -f $TARGET.mk cleanall

# Apache must be stopped to prevent database connection during
# databases / tables restore.
sudo apache2ctl stop

if psql --list --tuples-only | cut --delimiter='|' --fields=1 | grep --quiet --fixed-strings $DATABASES; then

# The following line works only with Postgres 9.3 and upper.
# otherwise the schema should be create manually
psql -c 'CREATE SCHEMA IF NOT EXISTS ${schema}_static;' ${db}

psql -c 'CREATE TABLE IF NOT EXISTS ${schema}_static.shorturl (
id serial PRIMARY KEY,
url character varying(1000),
ref character varying(20) NOT NULL UNIQUE,
creator_email character varying(200),
creation timestamp without time zone,
last_hit timestamp without time zone,
nb_hits integer
);' ${db}

psql -c 'GRANT USAGE ON SCHEMA "${schema}_static" TO "${dbuser}";' ${db}
psql -c 'GRANT SELECT ON ALL TABLES IN SCHEMA "${schema}_static" TO "${dbuser}";' ${db}

cd "${directory}"
make -f $TARGET.mk alembic_static.ini
.build/venv/bin/alembic -c alembic_static.ini upgrade head

printf ""
else
sudo -u postgres createdb $DATABASES --template template_postgis
fi

# The following line works only with Postgres 9.3 and upper.
# otherwise the schema should be create manually
psql -c 'CREATE SCHEMA IF NOT EXISTS ${schema}_static;' ${db}

psql -c 'CREATE TABLE IF NOT EXISTS ${schema}_static.shorturl (
id serial PRIMARY KEY,
url character varying(1000),
ref character varying(20) NOT NULL UNIQUE,
creator_email character varying(200),
creation timestamp without time zone,
last_hit timestamp without time zone,
nb_hits integer
);' ${db}

psql -c 'GRANT ALL ON SCHEMA "${schema}_static" TO "${dbuser}";' ${db}
psql -c 'GRANT ALL ON ALL TABLES IN SCHEMA "${schema}_static" TO "${dbuser}";' ${db}
psql -c 'ALTER TABLE main_static.shorturl OWNER TO "www-data";' ${db}

make -f $TARGET.mk .build/venv/bin/alembic alembic_static.ini -j2
.build/venv/bin/alembic -c alembic_static.ini upgrade head
3 changes: 3 additions & 0 deletions vars_demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ vars:
layers: []
legend: {}

# The deploy directory
directory: /var/www/vhosts/geomapfish-demo/private/2.2/

update_paths:
- shortener
- authtkt
Expand Down

0 comments on commit b007ce5

Please sign in to comment.