Skip to content

Commit

Permalink
Build on tag push (Yelp#249)
Browse files Browse the repository at this point in the history
* Support build for tag

* Fix docker image naming

* Publish for master and dss

* YAML format

* Update docker tag in doc

* Reword based on comment
  • Loading branch information
XIANJUN ZHU authored and justineyster committed Jun 24, 2020
1 parent 325bbb6 commit cfa7c20
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
48 changes: 33 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,34 @@ env:
- TOXENV=py27
- DOCKER_REGISTRY=us.icr.io
- DOCKER_USER=iamapikey
- DOCKER_LOCAL_IMAGE=git-defenders/dsl
- DOCKER_IMAGE=us.icr.io/git-defenders/dsl
- DOCKER_IMAGES="dsl detect-secrets detect-secrets-hook"
- DOCKER_LOCAL_DOMAIN=git-defenders
- DOCKER_REMOTE_DOMAIN=us.icr.io/git-defenders
- DOCKER_IMAGE_TAG="$TRAVIS_BUILD_NUMBER-id-$TRAVIS_BUILD_ID-time-$(date +%s)"
- DOCKER_IMAGE_TAG_DSS="$TRAVIS_BRANCH-$TRAVIS_BUILD_NUMBER-id-$TRAVIS_BUILD_ID-time-$(date +%s)"
deploy:
- provider: script
script: echo ${IBM_CLOUD_API_KEY} | docker login -u $DOCKER_USER --password-stdin $DOCKER_REGISTRY
&& docker tag $DOCKER_LOCAL_IMAGE $DOCKER_IMAGE:$DOCKER_IMAGE_TAG
&& docker push $DOCKER_IMAGE:$DOCKER_IMAGE_TAG
&& docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG $DOCKER_IMAGE:latest
&& docker push $DOCKER_IMAGE:latest
script: |
echo ${IBM_CLOUD_API_KEY} | docker login -u $DOCKER_USER --password-stdin $DOCKER_REGISTRY
for image_name in $DOCKER_IMAGES
do
./tag-and-publish.sh $DOCKER_LOCAL_DOMAIN/$image_name $DOCKER_REMOTE_DOMAIN/$image_name:$DOCKER_IMAGE_TAG
./tag-and-publish.sh $DOCKER_LOCAL_DOMAIN/$image_name $DOCKER_REMOTE_DOMAIN/$image_name:latest
done
on:
branch: master
branch: master
- provider: script
script: echo ${IBM_CLOUD_API_KEY} | docker login -u $DOCKER_USER --password-stdin $DOCKER_REGISTRY
&& docker tag $DOCKER_LOCAL_IMAGE $DOCKER_IMAGE:$DOCKER_IMAGE_TAG_DSS
&& docker push $DOCKER_IMAGE:$DOCKER_IMAGE_TAG_DSS
&& docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG_DSS $DOCKER_IMAGE:dss-latest
&& docker push $DOCKER_IMAGE:dss-latest
script: |
echo ${IBM_CLOUD_API_KEY} | docker login -u $DOCKER_USER --password-stdin $DOCKER_REGISTRY
for image_name in $DOCKER_IMAGES
do
./tag-and-publish.sh $DOCKER_LOCAL_DOMAIN/$image_name $DOCKER_REMOTE_DOMAIN/$image_name:$DOCKER_IMAGE_TAG_DSS
./tag-and-publish.sh $DOCKER_LOCAL_DOMAIN/$image_name $DOCKER_REMOTE_DOMAIN/$image_name:dss-latest
done
on:
branch: dss
branch: dss
matrix:
include:
- env: TOXENV=py27
Expand All @@ -41,7 +48,18 @@ matrix:
# python: pypy
install:
- pip install tox
script: make test && ./build-dockerfiles.sh
script: |
make test
./build-dockerfiles.sh
# Publish image and labled with tag when a git tag is pushed
if [ -n "$TRAVIS_TAG" ]; then
echo ${IBM_CLOUD_API_KEY} | docker login -u $DOCKER_USER --password-stdin $DOCKER_REGISTRY
for image_name in $DOCKER_IMAGES
do
./tag-and-publish.sh $DOCKER_LOCAL_DOMAIN/$image_name $DOCKER_REMOTE_DOMAIN/$image_name:$TRAVIS_TAG
done
fi
cache:
directories:
- $HOME/.cache/pre-commit
Expand Down
14 changes: 14 additions & 0 deletions tag-and-publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash -e

script_name=$(basename $0)

if [ $# -lt 2 ]; then
echo "Usage: $script_name local_image_with_tag remote_image_with_tag"
exit 1
fi

LOCAL_IMAGE=$1
REMOTE_IAMGE=$2

docker tag $LOCAL_IMAGE $REMOTE_IAMGE
docker push $REMOTE_IAMGE
8 changes: 4 additions & 4 deletions update.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Versioning and update
---------------------
# Versioning and update

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
Expand All @@ -8,7 +8,6 @@ Versioning and update
- [How do we version this repo](#how-do-we-version-this-repo)
- [How do we make release](#how-do-we-make-release)


## How do we keep update to date with upstream

> Rule of thumb: We keep all IBM related commits on top of the upstream code using rebase and/or cherry-pick.
Expand Down Expand Up @@ -64,7 +63,8 @@ Format: `<upstream-version>-ibm.<minor>.<fix>`, for example `0.12.0-ibm.3`
Release should be made when we bump to a new version.
1. Use [`hub` tool](https://github.com/github/hub) to create new release. You can view the released version at https://github.ibm.com/Whitewater/whitewater-detect-secrets/releases
1. Use [`hub` tool](https://github.com/github/hub) to create new release. You can view the released version at <https://github.ibm.com/Whitewater/whitewater-detect-secrets/releases>.
This process also creates a tag, which triggers Traivs tag build to generate a new version of the docker image labeled with the newly created tag.
```sh
# <branch-name>: the latest commit from the branch would be used to create tag.
Expand Down

0 comments on commit cfa7c20

Please sign in to comment.