-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-build.sh
More file actions
executable file
·168 lines (147 loc) · 5.56 KB
/
Copy pathdocker-build.sh
File metadata and controls
executable file
·168 lines (147 loc) · 5.56 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}╔════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ LibriSync Docker Build System ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════╝${NC}"
echo ""
# Function to display help
show_help() {
echo -e "${GREEN}Usage:${NC} $0 [OPTION]"
echo ""
echo -e "${YELLOW}Options:${NC}"
echo " build Build the Docker image and compile the app"
echo " dev Start a development container with shell access"
echo " clean Remove all build artifacts and Docker images"
echo " rebuild Clean and rebuild everything from scratch"
echo " help Display this help message"
echo ""
echo -e "${YELLOW}Environment Variables:${NC}"
echo " GIT_REPO Git repository URL to clone (required)"
echo " GIT_BRANCH Git branch to checkout (default: main)"
echo " BUILD_TYPE Build type: 'debug' or 'release' (default: debug)"
echo " BUNDLE_TYPE Bundle type: 'apk' or 'aab' (default: apk)"
echo ""
echo -e "${YELLOW}Examples:${NC}"
echo " # Build debug APK from git repository"
echo " GIT_REPO=https://github.com/user/repo.git $0 build"
echo ""
echo " # Build release APK"
echo " GIT_REPO=https://github.com/user/repo.git BUILD_TYPE=release $0 build"
echo ""
echo " # Build from specific branch"
echo " GIT_REPO=https://github.com/user/repo.git GIT_BRANCH=develop $0 build"
echo ""
echo " # Development shell"
echo " $0 dev # Start interactive dev shell"
echo ""
echo " # Clean up"
echo " $0 clean # Clean up build artifacts"
}
# Function to load signing credentials from credentials.json
load_credentials() {
local creds_file="credentials.json"
if [ -f "$creds_file" ] && command -v python3 &>/dev/null; then
echo -e "${GREEN}Loading signing credentials from credentials.json...${NC}"
local keystore_path
keystore_path=$(python3 -c "import json; print(json.load(open('$creds_file'))['android']['keystore']['keystorePath'])")
if [ -f "$keystore_path" ]; then
export KEYSTORE_FILE=$(base64 < "$keystore_path")
fi
export KEYSTORE_PASSWORD=$(python3 -c "import json; print(json.load(open('$creds_file'))['android']['keystore']['keystorePassword'])")
export KEY_ALIAS=$(python3 -c "import json; print(json.load(open('$creds_file'))['android']['keystore']['keyAlias'])")
export KEY_PASSWORD=$(python3 -c "import json; print(json.load(open('$creds_file'))['android']['keystore']['keyPassword'])")
echo -e "${GREEN}✓ Credentials loaded${NC}"
elif [ -z "$KEYSTORE_FILE" ]; then
echo -e "${YELLOW}Warning: No credentials.json found and KEYSTORE_FILE not set. Build may be unsigned.${NC}"
fi
}
# Function to build the app
build_app() {
# Validate GIT_REPO is set
if [ -z "$GIT_REPO" ]; then
echo -e "${RED}Error: GIT_REPO environment variable is required${NC}"
echo ""
echo -e "${YELLOW}Please set GIT_REPO to your repository URL:${NC}"
echo " export GIT_REPO=https://github.com/user/repo.git"
echo " $0 build"
echo ""
echo "Or use it inline:"
echo " GIT_REPO=https://github.com/user/repo.git $0 build"
exit 1
fi
# Load credentials from credentials.json if env vars not already set
if [ -z "$KEYSTORE_FILE" ] && [ "$BUILD_TYPE" = "release" ]; then
load_credentials
fi
echo -e "${GREEN}Building LibriSync in Docker...${NC}"
echo -e "${YELLOW}Repository: $GIT_REPO${NC}"
echo -e "${YELLOW}Branch: ${GIT_BRANCH:-main}${NC}"
echo -e "${YELLOW}Build Type: ${BUILD_TYPE:-debug}${NC}"
echo -e "${YELLOW}Bundle Type: ${BUNDLE_TYPE:-apk}${NC}"
echo ""
# Create output directory
mkdir -p build-output
# Build using docker compose
docker compose build librisync-build
echo -e "${GREEN}Running build container...${NC}"
docker compose run --rm librisync-build
echo ""
echo -e "${GREEN}✓ Build complete!${NC}"
echo -e "${YELLOW}Build artifacts are in: ./build-output/${NC}"
ls -lh build-output/
}
# Function to start dev container
start_dev() {
echo -e "${GREEN}Starting development container...${NC}"
echo -e "${YELLOW}You'll have shell access with all build tools available.${NC}"
echo ""
docker compose build librisync-dev
docker compose run --rm librisync-dev
}
# Function to clean build artifacts
clean_build() {
echo -e "${YELLOW}Cleaning build artifacts...${NC}"
# Remove output directory
rm -rf build-output
# Remove Docker volumes
docker compose down -v
# Remove Docker images
docker rmi librisync:latest librisync:dev 2>/dev/null || true
echo -e "${GREEN}✓ Clean complete!${NC}"
}
# Function to rebuild everything
rebuild_all() {
echo -e "${YELLOW}Rebuilding everything from scratch...${NC}"
clean_build
build_app
}
# Parse command line arguments
case "${1:-build}" in
build)
build_app
;;
dev)
start_dev
;;
clean)
clean_build
;;
rebuild)
rebuild_all
;;
help|--help|-h)
show_help
;;
*)
echo -e "${RED}Error: Unknown option '$1'${NC}"
echo ""
show_help
exit 1
;;
esac