-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompose.sh
More file actions
executable file
·56 lines (45 loc) · 1.83 KB
/
Copy pathcompose.sh
File metadata and controls
executable file
·56 lines (45 loc) · 1.83 KB
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
55
56
#!/usr/bin/env bash
# Wrapper for docker-compose commands to initialize some environment variables
set -euo pipefail
# Get the directory this script is in
BIN_DIR=$(dirname "$(readlink -f "$0")")
cd "$BIN_DIR"
TOP=$(git rev-parse --show-toplevel)
# Check for uncommitted changes
IS_DIRTY=$(git -C "$TOP" status --porcelain)
if [ -n "$IS_DIRTY" ]; then
SHA_SUFFIX="+dirty"
DESCRIPTION_SUFFIX=" (with uncommitted changes)"
echo "Warning: Uncommitted changes detected in the repository."
else
SHA_SUFFIX=""
DESCRIPTION_SUFFIX=""
fi
GITHUB_SHA="${GITHUB_SHA:-$(git -C "$TOP" rev-parse HEAD)}"
GITHUB_REPOSITORY="${GITHUB_REPOSITORY:-aperture-data/workflows}"
# if VERSION is set use it, or build from githash
if [ -n "${VERSION:-}" ]; then
echo "Using version: $VERSION"
else
echo "Building version from git hash: $GITHUB_SHA"
echo "This can cause lot of tags being created while developing."
echo "Consider using the VERSION environment variable to set the version."
SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c1-12)
VERSION="local-$SHORT_SHA"
if [ -n "${IS_DIRTY}" ]; then
echo "Repository is dirty, appending dirty hash to version."
DIRTY_HASH=$( { git diff --cached --no-ext-diff ; git diff --no-ext-diff ; } | sha1sum | cut -c1-12)
VERSION="${VERSION}-${DIRTY_HASH}"
fi
echo "Computed version: $VERSION"
fi
export VERSION
export GITHUB_SHA_FULL="${GITHUB_SHA}${SHA_SUFFIX}"
export BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
SOURCE_PATH_REL=$(realpath --relative-to="$TOP" "$BIN_DIR")
export SOURCE_URL="https://github.com/${GITHUB_REPOSITORY}/tree/${GITHUB_SHA}"
DOCKERFILE_URL="${SOURCE_URL}/${SOURCE_PATH_REL}/Dockerfile"
export DESCRIPTION="Built from ${DOCKERFILE_URL} on ${BUILD_DATE}, version ${VERSION}${DESCRIPTION_SUFFIX}"
echo "Description: ${DESCRIPTION}"
# Forward all args to docker compose
exec docker compose "$@"