Skip to content

Commit

Permalink
Make develop.sh and test.sh compatible with compose v2
Browse files Browse the repository at this point in the history
  • Loading branch information
amCap1712 committed Nov 29, 2023
1 parent 6f0a362 commit 4142620
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
11 changes: 9 additions & 2 deletions develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ if [[ ! -d "docker" ]]; then
exit -1
fi

echo "Checking docker compose version"
if docker compose version &> /dev/null; then
DOCKER_COMPOSE_CMD="docker compose"
else
DOCKER_COMPOSE_CMD="docker-compose"
fi

function invoke_docker_compose {
exec docker-compose -f docker/docker-compose.dev.yml \
exec $DOCKER_COMPOSE_CMD -f docker/docker-compose.dev.yml \
-p critiquebrainz \
"$@"
}

function invoke_docker_compose_test {
exec docker-compose -f docker/docker-compose.test.yml \
exec $DOCKER_COMPOSE_CMD -f docker/docker-compose.test.yml \
-p critiquebrainz_test \
"$@"
}
Expand Down
66 changes: 34 additions & 32 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,47 @@ if [[ ! -d "docker" ]]; then
exit -1
fi

echo "Checking docker compose version"
if docker compose version &> /dev/null; then
DOCKER_COMPOSE_CMD="docker compose"
else
DOCKER_COMPOSE_CMD="docker-compose"
fi

function invoke_docker_compose_cmd {
$DOCKER_COMPOSE_CMD \
-f ${COMPOSE_FILE_LOC} \
-p ${COMPOSE_PROJECT_NAME} \
"$@"
}

function build_containers {
docker-compose -f ${COMPOSE_FILE_LOC} \
-p ${COMPOSE_PROJECT_NAME} \
build critiquebrainz
invoke_docker_compose_cmd build critiquebrainz
}

function bring_up_db {
docker-compose -f ${COMPOSE_FILE_LOC} \
-p ${COMPOSE_PROJECT_NAME} \
up -d db musicbrainz_db critiquebrainz_redis
invoke_docker_compose_cmd up -d db musicbrainz_db critiquebrainz_redis
}

function setup {
echo "Running setup"
# PostgreSQL Database initialization
docker-compose -f ${COMPOSE_FILE_LOC} \
-p ${COMPOSE_PROJECT_NAME} \
run --rm critiquebrainz dockerize \
-wait tcp://db:5432 -timeout 60s \
bash -c "python3 manage.py init_db"
invoke_docker_compose_cmd \
run --rm critiquebrainz dockerize \
-wait tcp://db:5432 -timeout 60s \
bash -c "python3 manage.py init_db"

docker-compose -f ${COMPOSE_FILE_LOC} \
-p ${COMPOSE_PROJECT_NAME} \
run --rm critiquebrainz bash scripts/download-import-bookbrainz-dump.sh
invoke_docker_compose_cmd \
run --rm critiquebrainz bash scripts/download-import-bookbrainz-dump.sh

docker-compose -f ${COMPOSE_FILE_LOC} \
-p ${COMPOSE_PROJECT_NAME} \
run --rm critiquebrainz bash scripts/add-test-bookbrainz-data.sh
invoke_docker_compose_cmd \
run --rm critiquebrainz bash scripts/add-test-bookbrainz-data.sh

}

function is_db_running {
# Check if the database container is running
containername="${COMPOSE_PROJECT_NAME}_db_1"
containername="${COMPOSE_PROJECT_NAME}-db-1"
res=`docker ps --filter "name=$containername" --filter "status=running" -q`
if [[ -n "$res" ]]; then
return 0
Expand All @@ -60,7 +67,7 @@ function is_db_running {
}

function is_db_exists {
containername="${COMPOSE_PROJECT_NAME}_db_1"
containername="${COMPOSE_PROJECT_NAME}-db-1"
res=`docker ps --filter "name=$containername" --filter "status=exited" -q`
if [[ -n "$res" ]]; then
return 0
Expand All @@ -71,26 +78,21 @@ function is_db_exists {

function dc_stop {
# Stopping all unit test containers associated with this project
docker-compose -f ${COMPOSE_FILE_LOC} \
-p ${COMPOSE_PROJECT_NAME} \
stop
invoke_docker_compose_cmd stop
}

function dc_down {
# Shutting down all unit test containers associated with this project
docker-compose -f ${COMPOSE_FILE_LOC} \
-p ${COMPOSE_PROJECT_NAME} \
down
invoke_docker_compose_cmd down
}

function run_tests {
echo "Running tests"
docker-compose -f ${COMPOSE_FILE_LOC} \
-p ${COMPOSE_PROJECT_NAME} \
run --rm critiquebrainz \
dockerize -wait tcp://db:5432 -timeout 60s \
dockerize -wait tcp://musicbrainz_db:5432 -timeout 600s \
pytest --junitxml=reports/tests.xml "$@"
invoke_docker_compose_cmd \
run --rm critiquebrainz \
dockerize -wait tcp://db:5432 -timeout 60s \
dockerize -wait tcp://musicbrainz_db:5432 -timeout 600s \
pytest --junitxml=reports/tests.xml "$@"
}


Expand All @@ -102,7 +104,7 @@ if [[ "$1" == "-s" ]]; then
fi

if [[ "$1" == "-d" ]]; then
echo "Running docker-compose down"
echo "Running $DOCKER_COMPOSE_CMD down"
dc_down
exit 0
fi
Expand Down

0 comments on commit 4142620

Please sign in to comment.