|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # |
3 | | -# Copyright 2016-2020, Intel Corporation |
| 3 | +# Copyright 2016-2021, Intel Corporation |
4 | 4 | # |
5 | 5 | # Redistribution and use in source and binary forms, with or without |
6 | 6 | # modification, are permitted provided that the following conditions |
|
34 | 34 | # pull-or-rebuild-image.sh - rebuilds the Docker image used in the |
35 | 35 | # current Travis build if necessary. |
36 | 36 | # |
37 | | -# The script rebuilds the Docker image if the Dockerfile for the current |
38 | | -# OS version (Dockerfile.${OS}-${OS_VER}) or any .sh script from the directory |
39 | | -# with Dockerfiles were modified and committed. |
| 37 | +# The script rebuilds the Docker image if: |
| 38 | +# 1. the Dockerfile for the current OS version (Dockerfile.${OS}-${OS_VER}) |
| 39 | +# or any .sh script in the Dockerfiles directory were modified and committed, or |
| 40 | +# 2. "rebuild" param was passed as a first argument to this script. |
40 | 41 | # |
41 | 42 | # If the Travis build is not of the "pull_request" type (i.e. in case of |
42 | 43 | # merge after pull_request) and it succeed, the Docker image should be pushed |
43 | 44 | # to the Docker Hub repository. An empty file is created to signal that to |
44 | 45 | # further scripts. |
45 | 46 | # |
46 | 47 | # If the Docker image does not have to be rebuilt, it will be pulled from |
47 | | -# Docker Hub. |
| 48 | +# the Docker Hub. |
48 | 49 | # |
49 | 50 |
|
50 | 51 | set -e |
@@ -75,9 +76,21 @@ if [[ -z "$HOST_WORKDIR" ]]; then |
75 | 76 | exit 1 |
76 | 77 | fi |
77 | 78 |
|
| 79 | +# Path to directory with Dockerfiles and image building scripts |
| 80 | +images_dir_name=images |
| 81 | +base_dir=utils/docker/$images_dir_name |
| 82 | + |
| 83 | +# If "rebuild" param is passed to the script, force rebuild |
| 84 | +if [[ "${1}" == "rebuild" ]]; then |
| 85 | + pushd ${images_dir_name} |
| 86 | + ./build-image.sh ${DOCKERHUB_REPO} ${OS}-${OS_VER} |
| 87 | + popd |
| 88 | + exit 0 |
| 89 | +fi |
| 90 | + |
78 | 91 | # TRAVIS_COMMIT_RANGE is usually invalid for force pushes - fix it when used |
79 | 92 | # with non-upstream repository |
80 | | -if [ -n "$TRAVIS_COMMIT_RANGE" -a "$TRAVIS_REPO_SLUG" != "$GITHUB_REPO" ]; then |
| 93 | +if [ -n "$TRAVIS_COMMIT_RANGE" -a "$TRAVIS_REPO_SLUG" != "${GITHUB_REPO}" ]; then |
81 | 94 | if ! git rev-list $TRAVIS_COMMIT_RANGE; then |
82 | 95 | # get commit id of the last merge |
83 | 96 | LAST_MERGE=$(git log --merges --pretty=%H -1) |
@@ -113,10 +126,6 @@ files=$(for commit in $commits; do git diff-tree --no-commit-id --name-only \ |
113 | 126 | echo "Files modified within the commit range:" |
114 | 127 | for file in $files; do echo $file; done |
115 | 128 |
|
116 | | -# Path to directory with Dockerfiles and image building scripts |
117 | | -images_dir_name=images |
118 | | -base_dir=utils/docker/$images_dir_name |
119 | | - |
120 | 129 | # Check if committed file modifications require the Docker image to be rebuilt |
121 | 130 | for file in $files; do |
122 | 131 | # Check if modified files are relevant to the current build |
|
0 commit comments