Skip to content

Commit 9bfba06

Browse files
committed
Add Docker-based package testing script
1 parent b049a8f commit 9bfba06

File tree

1 file changed

+243
-0
lines changed

1 file changed

+243
-0
lines changed

scripts/test-packages-docker.sh

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
6+
7+
RED='\033[0;31m'
8+
GREEN='\033[0;32m'
9+
YELLOW='\033[1;33m'
10+
BLUE='\033[0;34m'
11+
NC='\033[0m'
12+
13+
log_info() {
14+
echo -e "${GREEN}[INFO]${NC} $1"
15+
}
16+
17+
log_warn() {
18+
echo -e "${YELLOW}[WARN]${NC} $1"
19+
}
20+
21+
log_error() {
22+
echo -e "${RED}[ERROR]${NC} $1"
23+
}
24+
25+
log_section() {
26+
echo -e "\n${BLUE}===================================================${NC}"
27+
echo -e "${BLUE} $1${NC}"
28+
echo -e "${BLUE}===================================================${NC}\n"
29+
}
30+
31+
test_deb_build() {
32+
local distro=$1
33+
local container=$2
34+
35+
log_section "Testing DEB build on $distro"
36+
37+
docker run --rm \
38+
-v "$PROJECT_ROOT:/build" \
39+
-w /build \
40+
"$container" \
41+
bash -c "
42+
set -ex
43+
apt-get update
44+
DEBIAN_FRONTEND=noninteractive apt-get install -y \
45+
debhelper \
46+
dpkg-dev \
47+
build-essential \
48+
libssl-dev \
49+
pkg-config \
50+
unixodbc-dev \
51+
freetds-dev \
52+
curl \
53+
lintian
54+
55+
# Install Rust
56+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
57+
. \$HOME/.cargo/env
58+
59+
# Build package
60+
dpkg-buildpackage -us -uc -b -d
61+
62+
# List created packages
63+
ls -lh ../*.deb
64+
65+
# Run lintian
66+
lintian --no-tag-display-limit ../*.deb || true
67+
"
68+
69+
if [ $? -eq 0 ]; then
70+
log_info "✓ DEB build succeeded on $distro"
71+
else
72+
log_error "✗ DEB build failed on $distro"
73+
return 1
74+
fi
75+
}
76+
77+
test_deb_install() {
78+
local distro=$1
79+
local container=$2
80+
local deb_file=$3
81+
82+
log_section "Testing DEB installation on $distro"
83+
84+
docker run --rm \
85+
-v "$deb_file:/package.deb" \
86+
"$container" \
87+
bash -c "
88+
set -ex
89+
apt-get update
90+
apt-get install -y /package.deb
91+
92+
# Verify installation
93+
sqlpage --version
94+
test -f /usr/bin/sqlpage
95+
test -d /etc/sqlpage
96+
test -f /etc/sqlpage/sqlpage.json
97+
test -d /etc/sqlpage/templates
98+
test -d /var/www/sqlpage
99+
test -f /lib/systemd/system/sqlpage.service
100+
101+
# Check user creation
102+
id sqlpage
103+
104+
# Test SQLPage functionality
105+
echo \"SELECT 'json' as component; SELECT 1 as test;\" > /var/www/sqlpage/index.sql
106+
cd /var/www/sqlpage
107+
timeout 5 sqlpage & sleep 2
108+
curl -sf http://localhost:8080/ | grep -q test
109+
pkill sqlpage || true
110+
"
111+
112+
if [ $? -eq 0 ]; then
113+
log_info "✓ DEB installation test passed on $distro"
114+
else
115+
log_error "✗ DEB installation test failed on $distro"
116+
return 1
117+
fi
118+
}
119+
120+
test_rpm_build() {
121+
local distro=$1
122+
local container=$2
123+
124+
log_section "Testing RPM build on $distro"
125+
126+
docker run --rm \
127+
-v "$PROJECT_ROOT:/build" \
128+
-w /build \
129+
"$container" \
130+
bash -c "
131+
set -ex
132+
133+
# Install build dependencies
134+
if command -v dnf &> /dev/null; then
135+
dnf install -y rpm-build rpmdevtools openssl-devel systemd \
136+
unixODBC-devel freetds-devel git curl gcc
137+
else
138+
yum install -y rpm-build rpmdevtools openssl-devel systemd \
139+
unixODBC-devel freetds-devel git curl gcc
140+
fi
141+
142+
# Install Rust
143+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
144+
. \$HOME/.cargo/env
145+
146+
# Setup RPM build tree
147+
rpmdev-setuptree
148+
149+
# Get version
150+
VERSION=\$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = \"\\(.*\\)\"/\\1/')
151+
RPM_VERSION=\$(echo \"\$VERSION\" | sed 's/-/~/')
152+
153+
# Update spec file
154+
sed -i \"s/^Version:.*/Version: \${RPM_VERSION}/\" rpm/sqlpage.spec
155+
cp rpm/sqlpage.spec ~/rpmbuild/SPECS/
156+
157+
# Create tarball
158+
git archive --format=tar.gz --prefix=\"SQLPage-\${RPM_VERSION}/\" \
159+
-o ~/rpmbuild/SOURCES/v\${RPM_VERSION}.tar.gz HEAD
160+
161+
# Build RPM
162+
rpmbuild -ba --nodeps ~/rpmbuild/SPECS/sqlpage.spec
163+
164+
# List created packages
165+
ls -lh ~/rpmbuild/RPMS/*/*.rpm
166+
167+
# Run rpmlint
168+
if command -v rpmlint &> /dev/null; then
169+
rpmlint ~/rpmbuild/RPMS/*/sqlpage*.rpm || true
170+
fi
171+
"
172+
173+
if [ $? -eq 0 ]; then
174+
log_info "✓ RPM build succeeded on $distro"
175+
else
176+
log_error "✗ RPM build failed on $distro"
177+
return 1
178+
fi
179+
}
180+
181+
test_rpm_install() {
182+
local distro=$1
183+
local container=$2
184+
local rpm_file=$3
185+
186+
log_section "Testing RPM installation on $distro"
187+
188+
docker run --rm \
189+
-v "$rpm_file:/package.rpm" \
190+
"$container" \
191+
bash -c "
192+
set -ex
193+
194+
if command -v dnf &> /dev/null; then
195+
dnf install -y curl /package.rpm
196+
else
197+
yum install -y curl /package.rpm
198+
fi
199+
200+
# Verify installation
201+
sqlpage --version
202+
test -f /usr/bin/sqlpage
203+
test -d /etc/sqlpage
204+
test -f /etc/sqlpage/sqlpage.json
205+
test -d /etc/sqlpage/templates
206+
test -d /var/www/sqlpage
207+
test -f /usr/lib/systemd/system/sqlpage.service
208+
209+
# Check user creation
210+
id sqlpage
211+
212+
# Test SQLPage functionality
213+
echo \"SELECT 'json' as component; SELECT 1 as test;\" > /var/www/sqlpage/index.sql
214+
cd /var/www/sqlpage
215+
timeout 5 sqlpage & sleep 2
216+
curl -sf http://localhost:8080/ | grep -q test
217+
pkill sqlpage || true
218+
"
219+
220+
if [ $? -eq 0 ]; then
221+
log_info "✓ RPM installation test passed on $distro"
222+
else
223+
log_error "✗ RPM installation test failed on $distro"
224+
return 1
225+
fi
226+
}
227+
228+
# Main execution
229+
cd "$PROJECT_ROOT"
230+
231+
log_section "Starting Package Tests"
232+
233+
# Test DEB builds
234+
log_info "Testing DEB builds..."
235+
test_deb_build "Debian Bookworm" "debian:bookworm"
236+
test_deb_build "Ubuntu 24.04" "ubuntu:24.04"
237+
238+
# Test RPM builds
239+
log_info "Testing RPM builds..."
240+
test_rpm_build "Fedora Latest" "fedora:latest"
241+
test_rpm_build "Rocky Linux 8" "rockylinux:8"
242+
243+
log_section "All tests completed!"

0 commit comments

Comments
 (0)