Skip to content

Instantly share code, notes, and snippets.

@edwintye
Last active January 27, 2020 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwintye/87ebe8f84fc3eb59f337915c27b9cf1e to your computer and use it in GitHub Desktop.
Save edwintye/87ebe8f84fc3eb59f337915c27b9cf1e to your computer and use it in GitHub Desktop.
Docker bash script
#!/usr/bin/env bash
IMAGE_VERSION=${1:-rc}
CONTAINER_ID=$(docker run -p 6379 --rm -d "redis:${IMAGE_VERSION}")
PORT=$(docker port "${CONTAINER_ID}" | cut -d ":" -f 2)
echo "go test using port ${PORT} from ${IMAGE_VERSION}"
REDIS_PORT=$PORT go test -v .
docker stop "${CONTAINER_ID}"
@edwintye
Copy link
Author

To use the script here in production, further error capturing and propagating is also necessary. To start, an if [ !? -eq 0 ] after the go test needs to be in place to ensure that the container is stopped with exit error raised. An early bail out should also be in place for the two docker commands in case the container fail to start or there are issues with obtaining the port.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment