forked from zavolanlab/Dockerfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.travis.yml
55 lines (51 loc) · 1.79 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
os:
- linux
dist: bionic
language: minimal
services:
- docker
stages:
# Execute upon PR or push to open PR
- name: build_image
if: type = pull_request
# Execute only upon merge into master
- name: push_image
if: type = push AND branch = master
jobs:
include:
- stage: build_image
name: Build Docker image
script:
- |
git diff --name-only "$TRAVIS_COMMIT_RANGE" | \
grep ".*\/Dockerfile$" | \
while read -r file ; do
if git diff --compact-summary "$TRAVIS_COMMIT_RANGE" | grep "$file" | grep "(gone)"; then
echo "Dockerfile '$file' was deleted. Not building."
continue
fi
echo "Building image for Dockerfile '$file'..."
travis_wait 60 docker build $(dirname "$file")
done
- stage: push_image
name: Build image and push to Docker Hub
script:
- |
git diff --name-only "$TRAVIS_COMMIT_RANGE" | \
grep ".*\/Dockerfile$" | \
while read -r file ; do
# Skip if file was deleted
if git diff --compact-summary "$TRAVIS_COMMIT_RANGE" | grep "$file" | grep "(gone)"; then
echo "Dockerfile '$file' was deleted. Not building."
continue
fi
# Extract tool name and version and sanitize according to Docker rules
tool_name=$(dirname $(dirname "$file") | tr A-Z a-z | sed 's/[^a-z\-\_]//g')
version=$(basename $(dirname "$file") | sed -e 's/[^a-zA-Z0-9\_\.\-]//g' -e 's/^[\.\-]//')
remote="${DOCKER_ORGANIZATION}/${tool_name}:${version}"
echo "Building image for Dockerfile '$file'..."
travis_wait 60 docker build -t "$remote" $(dirname $file)
echo "Pushing image to '$remote'..."
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker push "$remote"
done