Container db-migration-worker need no volumes

You can simply run `docker-compose exec db-migration-worker migrate` and
that's it. Of course you have to provide all the environment variables.
This commit is contained in:
Robert Schäfer 2019-02-04 15:43:21 +01:00
parent cdf92cc6ea
commit 01a145be29
13 changed files with 17 additions and 9 deletions

View File

@ -11,7 +11,6 @@ docker-compose*.yml
./*.png
./*.log
kubernetes/
node_modules/
scripts/
dist/

View File

@ -1,4 +1,3 @@
FROM neo4j:3.5.0 as neo4j
FROM mongo:4
RUN apt-get update
@ -9,5 +8,5 @@ RUN apt-get update
RUN apt-get -y install --no-install-recommends openjdk-8-jre openssh-client neo4j rsync \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY neo4j/ mongo/ ./
COPY migration ./migration
COPY migrate.sh /usr/local/bin/migrate

4
db-migration-worker/migrate.sh Normal file → Executable file
View File

@ -1,2 +1,4 @@
#!/usr/bin/env bash
/mongo/import.sh && /neo4j/import.sh
set -e
/migration/mongo/import.sh
/migration/neo4j/import.sh

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e
for var in "SSH_USERNAME" "SSH_HOST" "MONGODB_USERNAME" "MONGODB_PASSWORD" "MONGODB_DATABASE" "MONGODB_AUTH_DB" "UPLOADS_DIRECTORY"
for var in "SSH_USERNAME" "SSH_HOST" "MONGODB_USERNAME" "MONGODB_PASSWORD" "MONGODB_DATABASE" "MONGODB_AUTH_DB"
do
if [[ -z "${!var}" ]]; then
echo "${var} is undefined"
@ -15,7 +15,6 @@ echo "MONGODB_USERNAME ${MONGODB_USERNAME}"
echo "MONGODB_PASSWORD ${MONGODB_PASSWORD}"
echo "MONGODB_DATABASE ${MONGODB_DATABASE}"
echo "MONGODB_AUTH_DB ${MONGODB_AUTH_DB}"
echo "UPLOADS_DIRECTORY ${UPLOADS_DIRECTORY}"
echo "-------------------------------------------------"
mongo ${MONGODB_DATABASE} --eval "db.dropDatabase();"

View File

@ -1,9 +1,17 @@
#!/usr/bin/env bash
set -e
for var in "NEO4J_URI"
do
if [[ -z "${!var}" ]]; then
echo "${var} is undefined"
exit 1
fi
done
SCRIPT_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
echo "MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r;" | cypher-shell
echo "MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r;" | cypher-shell -a $NEO4J_URI
for collection in "badges" "categories" "users" "follows" "contributions" "shouts" "comments"
do
echo "Import ${collection}..." && cypher-shell < $SCRIPT_DIRECTORY/$collection.cql
echo "Import ${collection}..." && cypher-shell -a $NEO4J_URI < $SCRIPT_DIRECTORY/$collection.cql
done

View File

@ -27,6 +27,8 @@ services:
- ./db-migration-worker/.ssh/:/root/.ssh/
networks:
- hc-network
depends_on:
- backend
environment:
- NEO4J_URI=bolt://neo4j:7687
- "SSH_USERNAME=${SSH_USERNAME}"
@ -35,7 +37,6 @@ services:
- "MONGODB_PASSWORD=${MONGODB_PASSWORD}"
- "MONGODB_AUTH_DB=${MONGODB_AUTH_DB}"
- "MONGODB_DATABASE=${MONGODB_DATABASE}"
- "UPLOADS_DIRECTORY=${UPLOADS_DIRECTORY}"
command: "--smallfiles --logpath=/dev/null"
volumes: