-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.sh
38 lines (31 loc) · 799 Bytes
/
common.sh
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
#! /usr/bin/env bash
hadolint() {
docker run --rm -i hadolint/hadolint <"${1}"
}
getDockerfiles() {
relativePaths="$(find . -name Dockerfile)"
for path in $relativePaths; do
readlink -f "${path}"
done
}
getDirectoriesWithDockerfiles() {
DOCKERFILES="$(getDockerfiles)"
for dockerfile in $DOCKERFILES; do
dirname "$dockerfile"
done
}
getGitCommitHash() {
git rev-parse --short HEAD
}
buildDockerfile() {
contextDir="$1"
gitCommitHash="$2"
pwd="$(pwd)"
relativePath="${contextDir##$pwd\/}"
imageName="robertsmieja/$(echo $relativePath | awk '{ gsub("/", "-") ; print tolower($0) }')"
{
docker build $contextDir --tag "${imageName}:latest" --tag "${imageName}:${gitCommitHash}"
docker push "${imageName}:latest"
docker push "${imageName}:${gitCommitHash}"
} || true
}