Skip to content

Commit 49cff68

Browse files
authored
Add docker_builder.sh for building PiGallery2 Docker image
This script builds a Docker image for PiGallery2, checking for necessary dependencies and running diagnostics post-build.
1 parent 0f899a3 commit 49cff68

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

docker/docker_builder.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
# PiGallery2: Build -> Release -> Docker (Debian Trixie) -> Diagnostics
3+
# This is a helper script for building docker locally. Its a best effort file ans provided as it is, do not expect significant support for this if it gets our of sync from the project.
4+
5+
set -e # Stop on any error
6+
7+
# Configuration
8+
REPO_URL="https://github.com/bpatrik/pigallery2.git"
9+
BUILD_DIR="pigallery2_local_build"
10+
IMAGE_NAME="pigallery2-custom:local"
11+
12+
echo "--- 1. Pre-flight Environment Check ---"
13+
14+
# Check for Node.js
15+
if ! command -v node &> /dev/null; then
16+
echo "Error: node is not installed. Please install Node.js (v22 recommended)."
17+
exit 1
18+
else
19+
NODE_VER=$(node -v)
20+
echo "Found Node.js: $NODE_VER"
21+
fi
22+
23+
# Check for npm
24+
if ! command -v npm &> /dev/null; then
25+
echo "Error: npm is not installed."
26+
exit 1
27+
else
28+
NPM_VER=$(npm -v)
29+
echo "Found npm: $NPM_VER"
30+
fi
31+
32+
# Check for Docker (required for the build-docker step)
33+
if ! command -v docker &> /dev/null; then
34+
echo "Error: docker is not installed. Required for building the container."
35+
exit 1
36+
fi
37+
38+
# Check for Git
39+
if ! command -v git &> /dev/null; then
40+
echo "Error: git is not installed."
41+
exit 1
42+
fi
43+
44+
echo "--- 2. Preparing Repository ---"
45+
if [ -d "$BUILD_DIR" ]; then
46+
echo "Cleaning up old build directory..."
47+
rm -rf "$BUILD_DIR"
48+
fi
49+
git clone --depth 1 $REPO_URL $BUILD_DIR
50+
cd $BUILD_DIR
51+
52+
echo "--- 3. Installing Build Dependencies ---"
53+
# --unsafe-perm handles permission issues during lifecycle scripts (like sharp/libvips)
54+
npm install --unsafe-perm
55+
56+
echo "--- 4. Creating Production Release ---"
57+
# This mirrors the GitHub Action workflow you provided
58+
npm run create-release -- --skip-opt-packages=ffmpeg-static,ffprobe-static --force-opt-packages
59+
60+
echo "--- 5. Building Docker Image (Debian Trixie) ---"
61+
# Match the Dockerfile expectation: rename 'release' to 'pigallery2-release'
62+
if [ -d "release" ]; then
63+
mv release pigallery2-release
64+
else
65+
echo "Error: Release folder was not created by gulp."
66+
exit 1
67+
fi
68+
69+
# You might need to run this with sudo
70+
docker build -t $IMAGE_NAME \
71+
-f docker/debian-trixie/Dockerfile.build .
72+
73+
echo "--- 6. Running Post-Build Diagnostics ---"
74+
# The Dockerfile runs diagnostics during build, but this verifies the final image layer
75+
# You might need to run this with sudo
76+
docker run --rm $IMAGE_NAME node ./src/backend/index --run-diagnostics --Server-Log-level=silly
77+
78+
echo "------------------------------------------------"
79+
echo "SUCCESS: $IMAGE_NAME is ready."
80+
echo "------------------------------------------------"

0 commit comments

Comments
 (0)