Tags Docker image with branch, commit, and Travis build number. Prints out git repo and commit when container starts.

This commit is contained in:
Aaron Louie 2020-05-06 16:57:08 -04:00
parent 6f8a5a3b0e
commit b97e0d7d42
2 changed files with 14 additions and 3 deletions

View File

@ -3,6 +3,10 @@ language: bash
services:
- docker
env:
global:
- COMMIT=${TRAVIS_COMMIT::8}
before_install:
- sudo pip install --upgrade pip
- pip install --user awscli
@ -10,9 +14,13 @@ before_install:
- echo $DOCKER_TOKEN | docker login -u "$DOCKER_USERNAME" --password-stdin
install:
docker build --no-cache -t sartography/cr-connect-db:latest . || exit 1;
docker push sartography/cr-connect-db:latest || exit 1;
aws sqs send-message --region 'us-east-1' --queue-url 'https://queue.amazonaws.com/474683445819/dcos-refresh' --message-body 'crconnect/db' || exit 1;
- export REPO=sartography/cr-connect-db
- export TAG=`if ["$TRAVIS_BRANCH == "master"]; then echo "latest"; else echo $TRAVIS_BRANCH ; fi`
- docker build --build-arg $GIT_COMMIT="$REPO:$COMMIT" -f Dockerfile -t $REPO:$COMMIT .
- docker tag $REPO:$COMMIT $REPO:$TAG
- docker tag $REPO:$COMMIT $REPO:travis-$TRAVIS_BUILD_NUMBER
- docker push $REPO
- aws sqs send-message --region '$AWS_DEFAULT_REGION' --queue-url '$AWS_SQS_URL' --message-body 'crconnect/$TRAVIS_BRANCH/db'
notifications:
email:

View File

@ -1,3 +1,6 @@
FROM postgres
ARG GIT_COMMIT=unspecified
LABEL git_commit=$GIT_COMMIT
COPY ./initdb.sh /docker-entrypoint-initdb.d/initdb.sh
CMD echo 'echo "git commit = $GIT_COMMIT"' >> /docker-entrypoint-initdb.d/initdb.sh
EXPOSE 5432