-
Notifications
You must be signed in to change notification settings - Fork 362
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
add script to start docker container with db for unit tests #3434
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,14 @@ keep it up to date, documenting the purpose of the various types of tests. | |
|
||
By default `rspec` will randomly pick between postgres and mysql. | ||
|
||
#### Running the Units Tests in Docker | ||
|
||
If you don't want to set up a up a test DB locally, you can run | ||
`./scripts/start-db-in-docker.sh`. This script will start a docker container | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You run |
||
with a running postgres. Then you can run the tests from the docker container | ||
by running `rspec`. | ||
|
||
#### Running the Test DB Locally | ||
If postgres is not running on your OSX machine, you can start up a server by doing the following: | ||
``` | ||
brew services start postgresql | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
set -e -u | ||
|
||
ROOT_DIR_PATH="$(cd $(dirname $0)/.. && pwd)" | ||
cd "${ROOT_DIR_PATH}" | ||
|
||
# if DB not set, default to postgres because we usually use | ||
# postgres in our deployments | ||
db=${DB:-"postgres"} | ||
|
||
if [ "$db" = "mysql" ]; then | ||
docker_image=cloudfoundry/tas-runtime-mysql-5.7 | ||
elif [ "$db" = "mysql8" ]; then | ||
docker_image=cloudfoundry/tas-runtime-mysql-8.0 | ||
else | ||
docker_image=cloudfoundry/tas-runtime-postgres | ||
fi | ||
|
||
|
||
if [[ "${DB}" =~ mysql ]]; then | ||
db=mysql | ||
fi | ||
|
||
docker run \ | ||
--rm \ | ||
-it \ | ||
--privileged \ | ||
-v "${PWD}:/cloud_controller_ng" \ | ||
-e "DB=$db" \ | ||
--cap-add ALL \ | ||
-w /cloud_controller_ng \ | ||
$docker_image \ | ||
/cloud_controller_ng/scripts/start-db-in-docker.sh "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
set -e -u | ||
|
||
SCRIPT_PATH="$(cd "$(dirname "${0}")" && pwd)" | ||
|
||
function bootDB { | ||
db="$1" | ||
|
||
if [ "${db}" = "postgres" ]; then | ||
launchDB="(/postgres-entrypoint.sh postgres &> /var/log/postgres-boot.log) &" | ||
testConnection="psql -h localhost -U postgres -c '\conninfo'" | ||
elif [ "${db}" = "mysql" ] || [ "${db}" = "mysql-5.6" ] || [ "${db}" = "mysql8" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
launchDB="(MYSQL_ROOT_PASSWORD=password /mysql-entrypoint.sh mysqld &> /var/log/mysql-boot.log) &" | ||
testConnection="mysql -h localhost -u root -D mysql -e '\s;' --password='password'" | ||
else | ||
echo "skipping database" | ||
return 0 | ||
fi | ||
|
||
echo -n "booting ${db}" | ||
eval "$launchDB" | ||
for _ in $(seq 1 60); do | ||
if eval "${testConnection}" &> /dev/null; then | ||
echo "connection established to ${db}" | ||
return 0 | ||
fi | ||
echo -n "." | ||
sleep 1 | ||
done | ||
eval "${testConnection}" || true | ||
echo "unable to connect to ${db}" | ||
exit 1 | ||
} | ||
|
||
function moreSetup { | ||
apt-get update | ||
apt-get install -y libpq-dev default-libmysqlclient-dev | ||
bundle install | ||
rake db:create | ||
} | ||
|
||
cd /cloud_controller_ng | ||
export GOPATH=$PWD | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? We don't have Golang code... |
||
|
||
bootDB "${DB:-"notset"}" | ||
moreSetup | ||
|
||
set +e | ||
exec /bin/bash "$@" |
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.