-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.bash
More file actions
executable file
·85 lines (72 loc) · 2.49 KB
/
Copy pathbuild.bash
File metadata and controls
executable file
·85 lines (72 loc) · 2.49 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# <CREATE ENVIRONMENT> ================================================================================
if [ ! -f ./.env ]; then
echo "Creating .env file from template..."
cp ./.devcontainer/env.template ./.env
fi
# </CREATE ENVIRONMENT> ===============================================================================
# <GENERATE BUILD INFO> ===============================================================================
# Capture git information for the container
echo "Capturing git information..."
mkdir -p ./generated
git_info_file="./generated/build_info"
# Get git commit hash (fallback to "unknown" if git fails)
if git rev-parse HEAD >/dev/null 2>&1; then
git_commit=$(git rev-parse HEAD)
else
git_commit="unknown"
fi
# Get git repository URL (fallback to "unknown" if git fails)
if git config --get remote.origin.url >/dev/null 2>&1; then
git_remote=$(git config --get remote.origin.url)
else
git_remote="unknown"
fi
# Get current timestamp (cross-platform)
if command -v date >/dev/null 2>&1; then
# Unix/Linux/MacOS
build_timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ" 2>/dev/null || date +"%Y-%m-%dT%H:%M:%SZ")
else
# Fallback if date command is not available
build_timestamp="unknown"
fi
# Write build info to file
cat > "$git_info_file" << EOF
GIT_COMMIT=$git_commit
GIT_REMOTE=$git_remote
BUILD_TIMESTAMP=$build_timestamp
BUILD_FLAGS=$@
EOF
echo "Build info written to $git_info_file"
# </GENERATE BUILD INFO> ==============================================================================
# <DOCKER BUILD> ======================================================================================
# Add new flag to skip Docker build (for CI cache step)
for arg in "$@"; do
if [ "$arg" == "--skip-docker" ]; then
echo "Skipping Docker build (metadata step only)."
exit 0
fi
done
# Check if "--use-cache" flag is passed
cache_string="--no-cache"
buildx_cache=""
for arg in "$@"; do
if [ "$arg" == "--use-cache" ]; then
cache_string=""
echo "Using cached Docker image..."
break
fi
done
# Build the Docker image with BuildX (for better caching)
docker buildx build -f ./.devcontainer/Dockerfile \
--pull ${cache_string} \
"${buildx_cache_args[@]}" \
--load \
-t infinibot:latest \
./
# Check if the build was successful
if [ $? != 0 ]; then
echo "ERROR: Docker build failed."
exit 1
fi
# </DOCKER BUILD> =====================================================================================