forked from dotandev/hintents
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_docker_build.sh
More file actions
executable file
·146 lines (124 loc) · 4.62 KB
/
test_docker_build.sh
File metadata and controls
executable file
·146 lines (124 loc) · 4.62 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# Copyright 2026 Erst Users
# SPDX-License-Identifier: Apache-2.0
# Test script for Docker multi-architecture builds
# Verifies that Docker images build correctly for both amd64 and arm64
set -e
echo "=== Docker Multi-Architecture Build Test ==="
echo ""
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if Docker is installed
if ! command -v docker &> /dev/null; then
echo -e "${RED}Error: Docker is not installed${NC}"
exit 1
fi
# Check if buildx is available
if ! docker buildx version &> /dev/null; then
echo -e "${RED}Error: Docker buildx is not available${NC}"
echo "Install with: docker buildx install"
exit 1
fi
echo -e "${YELLOW}1. Setting up Docker buildx...${NC}"
# Create builder if it doesn't exist
if ! docker buildx ls | grep -q multiarch; then
docker buildx create --name multiarch --use
echo -e "${GREEN}✓ Created multiarch builder${NC}"
else
docker buildx use multiarch
echo -e "${GREEN}✓ Using existing multiarch builder${NC}"
fi
# Bootstrap the builder
docker buildx inspect --bootstrap
echo ""
echo -e "${YELLOW}2. Building for current platform...${NC}"
docker build -t erst:test .
echo -e "${GREEN}✓ Single-platform build successful${NC}"
echo ""
echo -e "${YELLOW}3. Testing single-platform image...${NC}"
# Test version command
if docker run --rm erst:test --version; then
echo -e "${GREEN}✓ Version command works${NC}"
else
echo -e "${RED}✗ Version command failed${NC}"
exit 1
fi
# Test help command
if docker run --rm erst:test --help > /dev/null 2>&1; then
echo -e "${GREEN}✓ Help command works${NC}"
else
echo -e "${RED}✗ Help command failed${NC}"
exit 1
fi
# Check simulator binary exists
if docker run --rm erst:test sh -c "test -f /app/simulator/target/release/erst-sim"; then
echo -e "${GREEN}✓ Simulator binary exists${NC}"
else
echo -e "${RED}✗ Simulator binary not found${NC}"
exit 1
fi
echo ""
echo -e "${YELLOW}4. Building multi-architecture images...${NC}"
echo "This may take several minutes..."
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag erst:multiarch \
--build-arg VERSION=test \
--build-arg COMMIT_SHA=$(git rev-parse HEAD 2>/dev/null || echo "unknown") \
--build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
--load \
. 2>&1 | grep -E "(Building|exporting|writing|naming)" || true
echo -e "${GREEN}✓ Multi-architecture build successful${NC}"
echo ""
echo -e "${YELLOW}5. Inspecting image...${NC}"
docker image inspect erst:test | grep -E "(Architecture|Os)" | head -2
echo ""
echo -e "${YELLOW}6. Checking binary architecture...${NC}"
docker run --rm --entrypoint file erst:test /app/erst
docker run --rm --entrypoint file erst:test /app/simulator/target/release/erst-sim
echo ""
echo -e "${YELLOW}7. Verifying static linking...${NC}"
if docker run --rm --entrypoint ldd erst:test /app/erst 2>&1 | grep -q "not a dynamic executable"; then
echo -e "${GREEN}✓ Go binary is statically linked${NC}"
else
echo -e "${YELLOW}⚠ Go binary has dynamic dependencies${NC}"
docker run --rm --entrypoint ldd erst:test /app/erst
fi
if docker run --rm --entrypoint ldd erst:test /app/simulator/target/release/erst-sim 2>&1 | grep -q "not a dynamic executable"; then
echo -e "${GREEN}✓ Rust binary is statically linked${NC}"
else
echo -e "${YELLOW}⚠ Rust binary has dynamic dependencies${NC}"
docker run --rm --entrypoint ldd erst:test /app/simulator/target/release/erst-sim
fi
echo ""
echo -e "${YELLOW}8. Testing with docker-compose...${NC}"
if command -v docker-compose &> /dev/null || docker compose version &> /dev/null; then
# Try docker compose (newer) or docker-compose (older)
COMPOSE_CMD="docker compose"
if ! docker compose version &> /dev/null; then
COMPOSE_CMD="docker-compose"
fi
$COMPOSE_CMD build erst
echo -e "${GREEN}✓ Docker Compose build successful${NC}"
else
echo -e "${YELLOW}⚠ Docker Compose not available, skipping${NC}"
fi
echo ""
echo -e "${YELLOW}9. Checking image size...${NC}"
SIZE=$(docker image inspect erst:test --format='{{.Size}}' | awk '{print $1/1024/1024}')
echo "Image size: ${SIZE} MB"
if (( $(echo "$SIZE < 200" | bc -l) )); then
echo -e "${GREEN}✓ Image size is reasonable${NC}"
else
echo -e "${YELLOW}⚠ Image size is larger than expected${NC}"
fi
echo ""
echo -e "${GREEN}=== All Docker tests passed! ===${NC}"
echo ""
echo "Next steps:"
echo " - Push to registry: docker push erst:multiarch"
echo " - Test on different platform: docker run --platform linux/arm64 erst:test --version"
echo " - Run CI workflow: git push origin <branch>"