Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dynamic Exposure
OpenBuildingMap
database-obmbuildings
Commits
75859490
Commit
75859490
authored
Sep 02, 2021
by
Marius Kriegerowski
Browse files
Added dockerized database and deploy stage
parent
86bde927
Pipeline
#27197
failed with stage
in 34 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
75859490
image
:
python:3-buster
image
:
debian:bullseye-slim
stages
:
-
test
-
deploy
test
:
before_script
:
-
apt-get update -y -qq
-
apt-get install postgresql -y -qq
services
:
-
name
:
$CI_REGISTRY/dynamicexposure/server-components/containers/docker-obm-database:master
-
name
:
$
{
CI_REGISTRY
}
/dynamicexposure/server-components/containers/docker-obm-database:master
alias
:
postgres
variables
:
POSTGRES_USER
:
"
postgres"
...
...
@@ -14,9 +18,21 @@ test:
interruptible
:
true
script
:
-
|
for file in `ls migrations/*`
do
echo "importing $file"
psql -v ON_ERROR_STOP=1 -h postgres -U postgres -f $file
done
-
./run-migrations.sh -u postgres -h postgres
deploy
:
image
:
docker:19.03.12
services
:
-
docker:19.03.12-dind
variables
:
IMAGE_TAG
:
$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
before_script
:
-
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
tags
:
-
dind
script
:
-
docker build --pull -t $IMAGE_TAG .
-
docker push $IMAGE_TAG
# only:
# refs:
# - master
Dockerfile
0 → 100644
View file @
75859490
FROM
${CI_REGISTRY}/dynamicexposure/server-components/containers/docker-obm-database:master
COPY
. .
RUN
run-migrations.sh
-u
postgres
-h
postgres
Makefile
0 → 100644
View file @
75859490
SOURCES
=
./run-migrations.sh
check
:
$(SOURCES)
shellcheck
--external-sources
$^
shfmt
-i
2
-d
$^
format
:
$(SOURCES)
shfmt
-i
2
-w
$^
run-migrations.sh
0 → 100755
View file @
75859490
#!/bin/bash
#
# Deletes current `obm_tiles` database and sets it up anew by running
# all SQL scripts in the migrations folder in ascending order.
# Run: script_name [db_user]
# May provide the database user as an argument (default: postgres).
# Copyright (C) 2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
set
-o
errexit
sql_scripts_dir
=
'migrations'
db_name
=
'obm_buildings'
db_user
=
'postgres'
db_hostname
=
'localhost'
# Test for argument from the command line (now only one argument: database user)
while
getopts
d:u:h: flag
do
case
"
${
flag
}
"
in
d
)
db_name
=
${
OPTARG
}
;;
u
)
db_user
=
${
OPTARG
}
;;
h
)
db_hostname
=
${
OPTARG
}
;;
esac
done
printf
'Running %s with database user %s on %s table %s \n'
"
$(
basename
"
$0
"
)
"
"
${
db_user
}
"
"
${
db_hostname
}
"
"
${
db_name
}
"
if
psql
-lqt
|
cut
-d
\|
-f
1 |
grep
-qw
"
${
db_name
}
"
;
then
# Database exists
printf
'Database %s exists, deleting.\n'
"
${
db_name
}
"
dropdb
"
${
db_name
}
"
printf
'Creating %s\n'
"
${
db_name
}
"
createdb
"
${
db_name
}
"
else
createdb
"
${
db_name
}
"
fi
# Run the SQL scripts in the migrations folder in ascending order
for
file
in
"
${
sql_scripts_dir
}
"
/
*
.sql
;
do
f_base
=
$(
basename
"
${
file
}
"
.sql
)
printf
'Running script %s\n'
"
${
f_base
}
"
psql
-v
ON_ERROR_STOP
=
1
\
--username
"
${
db_user
}
"
\
--dbname
"
${
db_name
}
"
\
--host
"
${
db_hostname
}
"
\
--echo-all
--file
"
${
file
}
"
done
printf
'Done.\n'
exit
0
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment