Last active
January 27, 2020 10:00
-
-
Save edwintye/87ebe8f84fc3eb59f337915c27b9cf1e to your computer and use it in GitHub Desktop.
Docker bash script
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
#!/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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.