- Notifications
You must be signed in to change notification settings - Fork 182
Add docker setup #256
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
Merged
Merged
Add docker setup #256
Changes from all commits
Commits
Show all changes
4 commits Select commit Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/bin/bash | ||
| ||
### Shell script to spin up a docker container for postgresql. | ||
| ||
## color codes | ||
RED='\033[1;31m' | ||
GREEN='\033[1;32m' | ||
YELLOW='\033[1;33m' | ||
CYAN='\033[1;36m' | ||
PLAIN='\033[0m' | ||
| ||
## variables | ||
POSTGRESQL_CONTAINER="postgresql_c" | ||
USER="root" | ||
PASSWORD="pass" | ||
PORT=5432 | ||
if [ "$1" ]; then | ||
USER=$1 | ||
fi | ||
if [ "$2" ]; then | ||
PASSWORD=$2 | ||
fi | ||
if [ "$3" ]; then | ||
PORT=$3 | ||
fi | ||
| ||
## check if docker exists | ||
printf "\n${RED}>> Checking for docker${PLAIN} ${GREEN}...${PLAIN}" | ||
docker -v > /dev/null 2>&1 | ||
DOCKER_EXISTS=$? | ||
if [ "$DOCKER_EXISTS" -ne 0 ]; then | ||
printf "\n${CYAN}Status: ${PLAIN}${RED}Docker not found. Terminating setup.${PLAIN}\n" | ||
exit 1 | ||
fi | ||
printf "\n${CYAN}Found docker. Moving on with the setup.${PLAIN}\n" | ||
| ||
| ||
## cleaning up previous builds | ||
printf "\n${RED}>> Finding old builds and cleaning up${PLAIN} ${GREEN}...${PLAIN}" | ||
docker rm -f $POSTGRESQL_CONTAINER > /dev/null 2>&1 | ||
printf "\n${CYAN}Clean up complete.${PLAIN}\n" | ||
| ||
## pull latest postgresql image | ||
printf "\n${RED}>> Pulling latest postgresql image${PLAIN} ${GREEN}...${PLAIN}" | ||
docker pull postgres:latest > /dev/null 2>&1 | ||
printf "\n${CYAN}Image successfully built.${PLAIN}\n" | ||
| ||
## run the postgresql container | ||
printf "\n${RED}>> Starting the postgresql container${PLAIN} ${GREEN}...${PLAIN}" | ||
CONTAINER_STATUS=$(docker run --name $POSTGRESQL_CONTAINER -e POSTGRES_USER=$USER -e POSTGRES_PASSWORD=$PASSWORD -p $PORT:5432 -d postgres:latest 2>&1) | ||
if [[ "$CONTAINER_STATUS" == *"Error"* ]]; then | ||
printf "\n${CYAN}Status: ${PLAIN}${RED}Error starting container. Terminating setup.${PLAIN}\n" | ||
exit 1 | ||
fi | ||
docker cp ./test/schema.sql $POSTGRESQL_CONTAINER:/home/ > /dev/null 2>&1 | ||
printf "\n${CYAN}Container is up and running.${PLAIN}\n" | ||
| ||
## export the schema to the postgresql database | ||
printf "\n${RED}>> Exporting schema to database${PLAIN} ${GREEN}...${PLAIN}\n" | ||
| ||
## command to export schema | ||
docker exec -it $POSTGRESQL_CONTAINER /bin/sh -c "psql -U $USER -f /home/schema.sql" > /dev/null 2>&1 | ||
| ||
## variables needed to health check export schema | ||
OUTPUT=$? | ||
TIMEOUT=120 | ||
TIME_PASSED=0 | ||
WAIT_STRING="." | ||
| ||
printf "\n${GREEN}Waiting for database to respond with updated schema $WAIT_STRING${PLAIN}" | ||
while [ "$OUTPUT" -ne 0 ] && [ "$TIMEOUT" -gt 0 ] | ||
do | ||
docker exec -it $POSTGRESQL_CONTAINER /bin/sh -c "psql -U $USER -f /home/schema.sql" > /dev/null 2>&1 | ||
OUTPUT=$? | ||
sleep 1s | ||
TIMEOUT=$((TIMEOUT - 1)) | ||
TIME_PASSED=$((TIME_PASSED + 1)) | ||
| ||
if [ "$TIME_PASSED" -eq 5 ]; then | ||
printf "${GREEN}.${PLAIN}" | ||
TIME_PASSED=0 | ||
fi | ||
done | ||
| ||
if [ "$TIMEOUT" -le 0 ]; then | ||
printf "\n\n${CYAN}Status: ${PLAIN}${RED}Failed to export schema. Terminating setup.${PLAIN}\n" | ||
exit 1 | ||
fi | ||
printf "\n${CYAN}Successfully exported schema to database.${PLAIN}\n" | ||
| ||
## set env variables for running test | ||
printf "\n${RED}>> Setting env variables to run test${PLAIN} ${GREEN}...${PLAIN}" | ||
export POSTGRESQL_HOST=0.0.0.0 | ||
export POSTGRESQL_PORT=$PORT | ||
export POSTGRESQL_USER=$USER | ||
export POSTGRESQL_PASSWORD=$PASSWORD | ||
printf "\n${CYAN}Env variables set.${PLAIN}\n" | ||
| ||
printf "\n${CYAN}Status: ${PLAIN}${GREEN}Set up completed successfully.${PLAIN}\n" | ||
printf "\n${CYAN}To run the test suite:${PLAIN} ${YELLOW}npm test${PLAIN}\n\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any reason we remove the info about how to run the tests locally without docker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI=true
pre seeds the database. We do not need to do any additional configuration.