-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-build.sh
More file actions
executable file
·60 lines (51 loc) · 1.72 KB
/
Copy pathdocker-build.sh
File metadata and controls
executable file
·60 lines (51 loc) · 1.72 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
57
58
59
60
#!/bin/bash
# Helper script to build Docker image with proper version information
set -e
# Show usage if no parameters provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <image-name> [version]"
echo ""
echo "Arguments:"
echo " image-name Docker image name (e.g., requestbite/requestbite-proxy)"
echo " version Optional version tag (default: auto-detect from git)"
echo ""
echo "Examples:"
echo " $0 requestbite/requestbite-proxy"
echo " $0 requestbite/requestbite-proxy 0.4.1"
exit 1
fi
IMAGE_NAME="$1"
# Extract version information
if [ -n "$2" ]; then
# Use explicitly provided version
VERSION="$2"
elif git describe --tags --exact-match 2>/dev/null >/dev/null; then
# We're exactly on a tag
VERSION=$(git describe --tags --exact-match | sed 's/^v//')
else
# Get the latest tag without commit info
VERSION=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "dev")
fi
BUILD_TIME=$(date -u '+%Y-%m-%d %H:%M:%S UTC')
GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
IMAGE_TAG="latest"
echo "Building Docker image with version information:"
echo " VERSION: $VERSION"
echo " BUILD_TIME: $BUILD_TIME"
echo " GIT_COMMIT: $GIT_COMMIT"
echo " IMAGE: $IMAGE_NAME:$IMAGE_TAG"
echo ""
# Build the Docker image with build arguments
docker build \
--build-arg VERSION="$VERSION" \
--build-arg BUILD_TIME="$BUILD_TIME" \
--build-arg GIT_COMMIT="$GIT_COMMIT" \
-t "$IMAGE_NAME:$IMAGE_TAG" \
-t "$IMAGE_NAME:$VERSION" \
.
echo ""
echo "✓ Build complete!"
echo " Tagged as: $IMAGE_NAME:$IMAGE_TAG"
echo " Tagged as: $IMAGE_NAME:$VERSION"
echo ""
echo "Run with: docker run -d -p 7331:7331 $IMAGE_NAME:$IMAGE_TAG"