Skip to content

Instantly share code, notes, and snippets.

@jimbaker
Created September 14, 2016 15:31
Show Gist options
  • Save jimbaker/0b944856bb23c32e9e1286e87e19b922 to your computer and use it in GitHub Desktop.
Save jimbaker/0b944856bb23c32e9e1286e87e19b922 to your computer and use it in GitHub Desktop.
Some initial commands to setup and run a test container fixture using Docker CLI - for real test code, this should be wrapped in a Python UnitTest class and use docker-py
docker build -t craton-inventory:latest .
# assign a random (ephemeral) port to our localhost's interface for
# the container's 8080; this ensures we are not tying up 8080 for
# testing!
docker run -p 127.0.0.1::8080 -d craton-inventory:latest
# get the container name/uuid along with the exposed port for 8080;
# in the case below, it's sick_lichterman and 32775 respectively
# for real usage, this should be done programmatically using docker-py
docker ps -a
# load the fixture data to complete initial setup
python tools/generate_fake_data.py --url http://127.0.0.1:32775/v1 --user demo --project 1 --key demo
# create a new image based on this running container (sick_lichterman)
# we cannot simply run with the same command since it has some initial setup such as creating
# the mysql database and some initial user data - that's already been created in the container,
# so we will simply have something to startup mysql, wait for it; then start the api service
docker commit --change='CMD ["tools/docker_test.sh"]' sick_lichterman craton/functional_test:v1
# now run this new image
docker run -p 127.0.0.1::8080 -d craton/functional_test:v1
# get port mappings, names - again, this should be done programmatically
docker ps -a
#!/bin/bash
# subset of container command startup to just ensure mysql + api service is running
# put this in tools/docker_test.sh and chmod a+x on it
/usr/bin/mysqld_safe > /dev/null 2>&1 &
RET=1
while [[ RET -ne 0 ]]; do
echo "=> Waiting for confirmation of MySQL service startup"
sleep 5
mysql -uroot -e "status" > /dev/null 2>&1
RET=$?
done
/craton/bin/python3.5 /craton/craton/cmd/inventory-api.py --config-file=/craton/etc/inventory-api-conf.sample
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment