Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 3abab5a

Browse files
update dockerfiles for use of both CI - GHA and Travis
and do minor cleanup in docker scripts.
1 parent 3d44357 commit 3abab5a

10 files changed

Lines changed: 236 additions & 132 deletions

File tree

.github/workflows/gha.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ name: CPP
1111
on: [push, pull_request]
1212

1313
env:
14+
REPO: libpmemobj-cpp
1415
GITHUB_REPO: pmem/libpmemobj-cpp
1516
DOCKERHUB_REPO: pmem/libpmemobj-cpp
1617

@@ -19,6 +20,8 @@ jobs:
1920
name: Linux
2021
runs-on: ubuntu-latest
2122
env:
23+
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
24+
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
2225
HOST_WORKDIR: /home/runner/work/libpmemobj-cpp/libpmemobj-cpp
2326
WORKDIR: utils/docker
2427
strategy:
@@ -39,9 +42,6 @@ jobs:
3942
with:
4043
fetch-depth: 50
4144

42-
- name: Change ownership of the repo
43-
run: sudo chown -R 1000.1000 $HOST_WORKDIR
44-
4545
- name: Pull or rebuild the image
4646
run: cd $WORKDIR && ${{ matrix.CONFIG }} ./pull-or-rebuild-image.sh
4747

utils/docker/build.sh

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,44 +32,47 @@
3232

3333
#
3434
# build-local.sh - runs a Docker container from a Docker image with environment
35-
# prepared for running libpmemobj-cpp tests and run those tests.
35+
# prepared for running libpmemobj-cpp builds and tests.
3636
#
3737
#
3838
# Notes:
3939
# - run this script from its location or set the variable 'HOST_WORKDIR' to
4040
# where the root of this project is on the host machine,
4141
# - set variables 'OS' and 'OS_VER' properly to a system you want to build this
4242
# repo on (for proper values take a look on the list of Dockerfiles at the
43-
# utils/docker/images directory), e.g. OS=ubuntu, OS_VER=19.04.
43+
# utils/docker/images directory), e.g. OS=ubuntu, OS_VER=19.10.
4444
#
4545

4646
set -e
47+
48+
source $(dirname $0)/set-ci-vars.sh
49+
source $(dirname $0)/set-vars.sh
4750
source $(dirname $0)/valid-branches.sh
4851

49-
# Environment variables that can be customized (default values are after dash):
50-
export KEEP_CONTAINER=${KEEP_CONTAINER:-0}
52+
if [[ "$CI_EVENT_TYPE" != "cron" && "$CI_BRANCH" != "coverity_scan" \
53+
&& "$TYPE" == "coverity" ]]; then
54+
echo "INFO: Skip Coverity scan job if build is triggered neither by " \
55+
"'cron' nor by a push to 'coverity_scan' branch"
56+
exit 0
57+
fi
5158

59+
if [[ ( "$CI_EVENT_TYPE" == "cron" || "$CI_BRANCH" == "coverity_scan" )\
60+
&& "$TYPE" != "coverity" ]]; then
61+
echo "INFO: Skip regular jobs if build is triggered either by 'cron'" \
62+
" or by a push to 'coverity_scan' branch"
63+
exit 0
64+
fi
5265

5366
if [[ -z "$OS" || -z "$OS_VER" ]]; then
5467
echo "ERROR: The variables OS and OS_VER have to be set " \
55-
"(e.g. OS=ubuntu, OS_VER=19.04)."
68+
"(eg. OS=fedora, OS_VER=31)."
5669
exit 1
5770
fi
5871

5972
if [[ -z "$HOST_WORKDIR" ]]; then
60-
HOST_WORKDIR=$(readlink -f ../..)
61-
fi
62-
63-
if [[ "$TRAVIS_EVENT_TYPE" == "cron" || "$TRAVIS_BRANCH" == "coverity_scan" ]]; then
64-
if [[ "$TYPE" != "coverity" ]]; then
65-
echo "Skipping non-Coverity job for cron/Coverity build"
66-
exit 0
67-
fi
68-
else
69-
if [[ "$TYPE" == "coverity" ]]; then
70-
echo "Skipping Coverity job for non cron/Coverity build"
71-
exit 0
72-
fi
73+
echo "ERROR: The variable HOST_WORKDIR has to contain a path to " \
74+
"the root of this project on the host machine"
75+
exit 1
7376
fi
7477

7578
imageName=${DOCKERHUB_REPO}:1.9-${OS}-${OS_VER}
@@ -114,20 +117,20 @@ fi
114117
if [ -n "$DNS_SERVER" ]; then DNS_SETTING=" --dns=$DNS_SERVER "; fi
115118

116119
# Only run doc update on $GITHUB_REPO master or stable branch
117-
if [[ -z "${TRAVIS_BRANCH}" || -z "${TARGET_BRANCHES[${TRAVIS_BRANCH}]}" || "$TRAVIS_PULL_REQUEST" != "false" || "$TRAVIS_REPO_SLUG" != "${GITHUB_REPO}" ]]; then
120+
if [[ -z "${CI_BRANCH}" || -z "${TARGET_BRANCHES[${CI_BRANCH}]}" || "$CI_EVENT_TYPE" == "pull_request" || "$CI_REPO_SLUG" != "${GITHUB_REPO}" ]]; then
118121
AUTO_DOC_UPDATE=0
119122
fi
120123

121-
WORKDIR=/libpmemobj-cpp
122-
SCRIPTSDIR=$WORKDIR/utils/docker
123-
124-
# check if we are running on a CI (Travis or GitHub Actions)
124+
# Check if we are running on a CI (Travis or GitHub Actions)
125125
[ -n "$GITHUB_ACTIONS" -o -n "$TRAVIS" ] && CI_RUN="YES" || CI_RUN="NO"
126126

127127
# do not allocate a pseudo-TTY if we are running on GitHub Actions
128128
[ ! $GITHUB_ACTIONS ] && TTY='-t' || TTY=''
129129

130-
echo Building ${OS}-${OS_VER}
130+
WORKDIR=/libpmemobj-cpp
131+
SCRIPTSDIR=$WORKDIR/utils/docker
132+
133+
echo Building on ${OS}-${OS_VER}
131134

132135
# Run a container with
133136
# - environment variables set (--env)
@@ -138,21 +141,26 @@ docker run --privileged=true --name=$containerName -i $TTY \
138141
${docker_opts} \
139142
--env http_proxy=$http_proxy \
140143
--env https_proxy=$https_proxy \
141-
--env AUTO_DOC_UPDATE=$AUTO_DOC_UPDATE \
142-
--env GITHUB_TOKEN=$GITHUB_TOKEN \
143144
--env WORKDIR=$WORKDIR \
144145
--env SCRIPTSDIR=$SCRIPTSDIR \
145-
--env TRAVIS_REPO_SLUG=$TRAVIS_REPO_SLUG \
146-
--env TRAVIS_BRANCH=$TRAVIS_BRANCH \
147-
--env TRAVIS_EVENT_TYPE=$TRAVIS_EVENT_TYPE \
146+
--env COVERAGE=$COVERAGE \
147+
--env AUTO_DOC_UPDATE=$AUTO_DOC_UPDATE \
148+
--env CI_RUN=$CI_RUN \
149+
--env TRAVIS=$TRAVIS \
150+
--env GITHUB_REPO=$GITHUB_REPO \
151+
--env CI_COMMIT_RANGE=$CI_COMMIT_RANGE \
152+
--env CI_COMMIT=$CI_COMMIT \
153+
--env CI_REPO_SLUG=$CI_REPO_SLUG \
154+
--env CI_BRANCH=$CI_BRANCH \
155+
--env CI_EVENT_TYPE=$CI_EVENT_TYPE \
156+
--env GITHUB_TOKEN=$GITHUB_TOKEN \
148157
--env COVERITY_SCAN_TOKEN=$COVERITY_SCAN_TOKEN \
149158
--env COVERITY_SCAN_NOTIFICATION_EMAIL=$COVERITY_SCAN_NOTIFICATION_EMAIL \
150-
--env COVERAGE=$COVERAGE \
151159
--env CHECK_CPP_STYLE=${CHECK_CPP_STYLE:-ON} \
152160
--env TESTS_LONG=${TESTS_LONG:-OFF} \
153161
--env TESTS_TBB=${TESTS_TBB:-ON} \
154-
--env CI_RUN=$CI_RUN \
155162
--env TZ='Europe/Warsaw' \
163+
--shm-size=4G \
156164
-v $HOST_WORKDIR:$WORKDIR \
157165
-v /etc/localtime:/etc/localtime \
158166
-w $SCRIPTSDIR \

utils/docker/images/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ development process vehicles and part of continuous integration process.
55

66
Images built out of those recipes may by used with docker or podman as
77
development environment.
8-
Only those used on travis are fully tested on a daily basis.
9-
In case of any problem, patches and github issues are welcome.
8+
Only those used on Travis/Github Actions are fully tested on a daily basis.
9+
In case of any problem, patches and Github issues are welcome.
1010

1111
# How to build docker image
1212

1313
```sh
14-
docker build --build-arg https_proxy=https://proxy.com:port --build-arg http_proxy=http://proxy.com:port -t libpmemobj-cpp:debian-unstable -f ./Dockerfile.debian-unstable .
14+
docker build --build-arg https_proxy=http://proxy.com:port --build-arg http_proxy=http://proxy.com:port -t libpmemobj-cpp:debian-unstable -f ./Dockerfile.debian-unstable .
1515
```
1616

1717
# How to use docker image

utils/docker/images/build-image.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,32 @@
4141

4242
set -e
4343

44+
OS_VER=$1
45+
4446
function usage {
4547
echo "Usage:"
46-
echo " build-image.sh <DOCKERHUB_REPO> <OS-VER>"
47-
echo "where <OS-VER>, for example, can be 'ubuntu-19.04', provided " \
48-
"a Dockerfile named 'Dockerfile.ubuntu-19.04' exists in the " \
48+
echo " build-image.sh <OS-VER>"
49+
echo "where <OS-VER>, for example, can be 'fedora-31', provided " \
50+
"a Dockerfile named 'Dockerfile.fedora-31' exists in the " \
4951
"current directory."
5052
}
5153

52-
# Check if the first and second argument is nonempty
53-
if [[ -z "$1" || -z "$2" ]]; then
54+
# Check if the argument is not empty
55+
if [[ -z "$1" ]]; then
5456
usage
5557
exit 1
5658
fi
5759

5860
# Check if the file Dockerfile.OS-VER exists
59-
if [[ ! -f "Dockerfile.$2" ]]; then
60-
echo "ERROR: wrong argument."
61+
if [[ ! -f "Dockerfile.$OS_VER" ]]; then
62+
echo "Error: Dockerfile.$OS_VER does not exist."
63+
echo
6164
usage
6265
exit 1
6366
fi
6467

6568
# Build a Docker image tagged with ${DOCKERHUB_REPO}:1.9-OS-VER
66-
docker build -t $1:1.9-$2 \
69+
docker build -t ${DOCKERHUB_REPO}:1.9-${OS_VER} \
6770
--build-arg http_proxy=$http_proxy \
6871
--build-arg https_proxy=$https_proxy \
69-
-f Dockerfile.$2 .
72+
-f Dockerfile.${OS_VER} .

utils/docker/images/push-image.sh

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,41 +31,42 @@
3131
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232

3333
#
34-
# push-image.sh <OS-VER> - pushes the Docker image tagged with OS-VER
35-
# to the Docker Hub.
34+
# push-image.sh - pushes the Docker image tagged with OS-VER to the Docker Hub.
3635
#
37-
# The script utilizes $DOCKERHUB_USER and $DOCKERHUB_PASSWORD variables to log in to
38-
# Docker Hub. The variables can be set in the Travis project's configuration
36+
# The script utilizes $DOCKERHUB_USER and $DOCKERHUB_PASSWORD variables to
37+
# log in to the Docker Hub. The variables can be set in the CI's configuration
3938
# for automated builds.
4039
#
4140

4241
set -e
4342

44-
function usage {
45-
echo "Usage:"
46-
echo " push-image.sh <OS-VER>"
47-
echo "where <OS-VER>, for example, can be 'ubuntu-19.04', provided " \
48-
"a Docker image tagged with ${DOCKERHUB_REPO}:1.9-ubuntu-19.04 exists " \
49-
"locally."
50-
}
43+
if [[ -z "$OS" ]]; then
44+
echo "OS environment variable is not set"
45+
exit 1
46+
fi
47+
48+
if [[ -z "$OS_VER" ]]; then
49+
echo "OS_VER environment variable is not set"
50+
exit 1
51+
fi
5152

52-
# Check if the first argument is nonempty
53-
if [[ -z "$1" ]]; then
54-
usage
53+
if [[ -z "${DOCKERHUB_REPO}" ]]; then
54+
echo "DOCKERHUB_REPO environment variable is not set"
5555
exit 1
5656
fi
5757

58+
TAG="1.9-${OS}-${OS_VER}"
59+
5860
# Check if the image tagged with ${DOCKERHUB_REPO}:1.9-OS-VER exists locally
59-
if [[ ! $(docker images -a | awk -v pattern="^${DOCKERHUB_REPO}:1.9-$1\$" \
61+
if [[ ! $(docker images -a | awk -v pattern="^${DOCKERHUB_REPO}:${TAG}\$" \
6062
'$1":"$2 ~ pattern') ]]
6163
then
62-
echo "ERROR: wrong argument."
63-
usage
64+
echo "ERROR: Docker image tagged ${DOCKERHUB_REPO}:${TAG} does not exists locally."
6465
exit 1
6566
fi
6667

6768
# Log in to the Docker Hub
6869
docker login -u="$DOCKERHUB_USER" -p="$DOCKERHUB_PASSWORD"
6970

7071
# Push the image to the repository
71-
docker push ${DOCKERHUB_REPO}:1.9-$1
72+
docker push ${DOCKERHUB_REPO}:${TAG}

utils/docker/pull-or-rebuild-image.sh

Lines changed: 13 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -49,38 +49,17 @@
4949

5050
set -e
5151

52+
source $(dirname $0)/set-ci-vars.sh
5253
source $(dirname $0)/set-vars.sh
5354

54-
function get_commit_range_from_last_merge {
55-
# get commit id of the last merge
56-
LAST_MERGE=$(git log --merges --pretty=%H -1)
57-
LAST_COMMIT=$(git log --pretty=%H -1)
58-
if [ "$LAST_MERGE" == "$LAST_COMMIT" ]; then
59-
# GitHub Actions commits its own merge in case of pull requests
60-
# so the first merge commit has to be skipped.
61-
LAST_MERGE=$(git log --merges --pretty=%H -2 | tail -n1)
62-
fi
63-
if [ "$LAST_MERGE" == "" ]; then
64-
# possible in case of shallow clones
65-
COMMIT_RANGE=""
66-
else
67-
COMMIT_RANGE="$LAST_MERGE..HEAD"
68-
# make sure it works now
69-
if ! git rev-list $COMMIT_RANGE >/dev/null; then
70-
COMMIT_RANGE=""
71-
fi
72-
fi
73-
echo $COMMIT_RANGE
74-
}
75-
76-
if [[ "$TRAVIS_EVENT_TYPE" != "cron" && "$TRAVIS_BRANCH" != "coverity_scan" \
55+
if [[ "$CI_EVENT_TYPE" != "cron" && "$CI_BRANCH" != "coverity_scan" \
7756
&& "$TYPE" == "coverity" ]]; then
7857
echo "INFO: Skip Coverity scan job if build is triggered neither by " \
7958
"'cron' nor by a push to 'coverity_scan' branch"
8059
exit 0
8160
fi
8261

83-
if [[ ( "$TRAVIS_EVENT_TYPE" == "cron" || "$TRAVIS_BRANCH" == "coverity_scan" )\
62+
if [[ ( "$CI_EVENT_TYPE" == "cron" || "$CI_BRANCH" == "coverity_scan" )\
8463
&& "$TYPE" != "coverity" ]]; then
8564
echo "INFO: Skip regular jobs if build is triggered either by 'cron'" \
8665
" or by a push to 'coverity_scan' branch"
@@ -89,7 +68,7 @@ fi
8968

9069
if [[ -z "$OS" || -z "$OS_VER" ]]; then
9170
echo "ERROR: The variables OS and OS_VER have to be set properly " \
92-
"(e.g. OS=ubuntu, OS_VER=19.04)."
71+
"(eg. OS=fedora, OS_VER=31)."
9372
exit 1
9473
fi
9574

@@ -99,35 +78,11 @@ if [[ -z "$HOST_WORKDIR" ]]; then
9978
exit 1
10079
fi
10180

102-
# TRAVIS_COMMIT_RANGE is usually invalid for force pushes - fix it when used
103-
# with non-upstream repository
104-
if [ -n "$TRAVIS_COMMIT_RANGE" -a "$TRAVIS_REPO_SLUG" != "$GITHUB_REPO" ]; then
105-
if ! git rev-list $TRAVIS_COMMIT_RANGE; then
106-
TRAVIS_COMMIT_RANGE=$(get_commit_range_from_last_merge)
107-
fi
108-
fi
109-
110-
# Fix Travis commit range
111-
if [ -n "$TRAVIS_COMMIT_RANGE" ]; then
112-
# $TRAVIS_COMMIT_RANGE contains "..." instead of ".."
113-
# https://github.com/travis-ci/travis-ci/issues/4596
114-
PR_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE/.../..}"
115-
fi
116-
117-
# Set the commit range in case of GitHub Actions
118-
if [ -n "$GITHUB_ACTIONS" ]; then
119-
PR_COMMIT_RANGE=$(get_commit_range_from_last_merge)
120-
fi
121-
12281
# Find all the commits for the current build
123-
if [ -n "$PR_COMMIT_RANGE" ]; then
124-
commits=$(git rev-list $PR_COMMIT_RANGE)
125-
elif [ -n "$TRAVIS" ]; then
126-
commits=$TRAVIS_COMMIT
127-
elif [ -n "$GITHUB_ACTIONS" ]; then
128-
commits=$GITHUB_SHA
82+
if [ -n "$CI_COMMIT_RANGE" ]; then
83+
commits=$(git rev-list $CI_COMMIT_RANGE)
12984
else
130-
commits=$(git log --pretty=%H -1)
85+
commits=$CI_COMMIT
13186
fi
13287

13388
echo "Commits in the commit range:"
@@ -152,17 +107,17 @@ for file in $files; do
152107
# Rebuild Docker image for the current OS version
153108
echo "Rebuilding the Docker image for the Dockerfile.$OS-$OS_VER"
154109
pushd $images_dir_name
155-
./build-image.sh ${DOCKERHUB_REPO} ${OS}-${OS_VER}
110+
./build-image.sh ${OS}-${OS_VER}
156111
popd
157112

158113
# Check if the image has to be pushed to Docker Hub
159-
# (i.e. the build is triggered by commits to the ${GITHUB_REPO}
160-
# repository's master branch, and the Travis build is not
114+
# (i.e. the build is triggered by commits to the $GITHUB_REPO
115+
# repository's stable-* or master branch, and the CI build is not
161116
# of the "pull_request" type). In that case, create the empty
162117
# file.
163-
if [[ "${TRAVIS_REPO_SLUG}" == "${GITHUB_REPO}" \
164-
&& ($TRAVIS_BRANCH == stable-* || $TRAVIS_BRANCH == master) \
165-
&& $TRAVIS_EVENT_TYPE != "pull_request"
118+
if [[ "$CI_REPO_SLUG" == "$GITHUB_REPO" \
119+
&& ($CI_BRANCH == stable-* || $CI_BRANCH == master) \
120+
&& $CI_EVENT_TYPE != "pull_request" \
166121
&& $PUSH_IMAGE == "1" ]]
167122
then
168123
echo "The image will be pushed to Docker Hub"

0 commit comments

Comments
 (0)