forked from jitsucom/jitsu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemulate-ci-build.sh
More file actions
executable file
·200 lines (173 loc) · 6.29 KB
/
Copy pathemulate-ci-build.sh
File metadata and controls
executable file
·200 lines (173 loc) · 6.29 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/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
log_info() { echo -e "${BLUE}ℹ️ $1${NC}"; }
log_success() { echo -e "${GREEN}✅ $1${NC}"; }
log_warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
log_error() { echo -e "${RED}❌ $1${NC}"; }
# Cleanup function
cleanup() {
if docker ps -a --format '{{.Names}}' | grep -q '^builder-ci$'; then
log_info "Cleaning up builder-ci container..."
docker stop builder-ci >/dev/null 2>&1 || true
docker rm builder-ci >/dev/null 2>&1 || true
fi
}
# Ensure cleanup happens on exit (success or failure)
trap cleanup EXIT
# Parse arguments
BUILD_BUILDER=false
NO_CACHE=false
SKIP_LINT=false
TARGETS="console rotor profiles"
for arg in "$@"; do
case "$arg" in
--build-builder)
BUILD_BUILDER=true
;;
--no-cache)
NO_CACHE=true
;;
--skip-lint)
SKIP_LINT=true
;;
--target)
shift
TARGETS="$1"
;;
--help|-h)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Emulates the CI build process locally"
echo ""
echo "Options:"
echo " --build-builder Build the builder image from builder.Dockerfile (default: pull from hub)"
echo " --no-cache Build Docker images without using cache"
echo " --skip-lint Skip lint, format, and test steps - go straight to Docker builds"
echo " --target <name> Build only specific target(s) (default: 'console rotor profiles')"
echo " --help, -h Show this help message"
echo ""
echo "Example:"
echo " $0 # Pull builder image and run full CI build"
echo " $0 --build-builder # Build builder image locally and run CI build"
echo " $0 --no-cache # Run CI build without Docker cache"
echo " $0 --skip-lint # Skip lint/test, only build Docker images"
echo " $0 --target rotor # Build only the rotor image"
echo " $0 --target \"console rotor\" # Build console and rotor images"
echo " $0 --skip-lint --target rotor --no-cache # Fast rotor-only clean build"
exit 0
;;
esac
shift
done
log_info "Cleaning local "
# Generate version with timestamp
VERSION="local.$(date +%Y%m%d%H%M%S)"
SHORT_SHA=$(git rev-parse --short=7 HEAD 2>/dev/null || echo "unknown")
log_info "Starting CI build emulation"
log_info "Version: ${VERSION}"
log_info "Commit: ${SHORT_SHA}"
log_info "Targets: ${TARGETS}"
if [ "$NO_CACHE" == "true" ]; then
log_warning "Docker cache disabled"
fi
if [ "$SKIP_LINT" == "true" ]; then
log_warning "Skipping lint, format, and test steps"
fi
# Step 1: Build or pull the builder image
if [ "$SKIP_LINT" == "false" ] || [ "$BUILD_BUILDER" == "true" ]; then
if [ "$BUILD_BUILDER" == "true" ]; then
log_info "Building builder image..."
BUILDER_CACHE_FLAG=""
if [ "$NO_CACHE" == "true" ]; then
BUILDER_CACHE_FLAG="--no-cache"
fi
docker build --progress=plain ${BUILDER_CACHE_FLAG} -f builder.Dockerfile -t jitsucom/jitsu-builder:latest .
log_success "Builder image built successfully"
else
log_info "Pulling builder image from GitHub Container Registry..."
docker pull jitsucom/jitsu-builder:latest
log_success "Builder image pulled successfully"
fi
fi
# Step 2: Emulate lint.yml workflow
if [ "$SKIP_LINT" == "false" ]; then
log_info "Starting lint and test workflow..."
# Remove existing builder container if it exists
if docker ps -a --format '{{.Names}}' | grep -q '^builder-ci$'; then
log_info "Removing existing builder-ci container..."
docker stop builder-ci >/dev/null 2>&1 || true
docker rm builder-ci >/dev/null 2>&1 || true
fi
# Start builder container
log_info "Starting builder container..."
docker run -d --name builder-ci -v "$(pwd)":/workspace -w /workspace -e CI=true jitsucom/jitsu-builder:latest tail -f /dev/null
log_success "Builder container started"
# Fetch dependencies from store
docker exec builder-ci pnpm fetch
log_success "Dependencies fetched"
# Install dependencies
log_info "Installing dependencies..."
docker exec builder-ci pnpm install --frozen-lockfile
log_success "Dependencies installed"
# Check code format
log_info "Checking code format..."
docker exec builder-ci pnpm run format:check:all
log_success "Code format check passed"
# Run codegen
log_info "Running codegen..."
docker exec builder-ci pnpm codegen
log_success "Codegen completed"
# Run typecheck
log_info "Running typecheck..."
docker exec builder-ci pnpm typecheck
log_success "Typecheck passed"
# Run linter
log_info "Running linter..."
docker exec builder-ci pnpm lint
log_success "Linter passed"
# Run tests
log_info "Running tests..."
docker exec builder-ci pnpm test
log_success "Tests passed"
fi
# Step 3: Emulate services.yaml workflow
log_info "Starting services Docker build..."
REGISTRY="jitsucom"
# Set cache flag for buildx
CACHE_FLAG=""
if [ "$NO_CACHE" == "true" ]; then
CACHE_FLAG="--no-cache"
fi
for TARGET in $TARGETS; do
log_info "Building ${TARGET}..."
docker buildx build \
--progress=plain \
${CACHE_FLAG} \
--target ${TARGET} \
--platform linux/amd64 \
--build-arg JITSU_BUILD_VERSION=${VERSION} \
--build-arg JITSU_BUILD_DOCKER_TAG=local \
--build-arg JITSU_BUILD_COMMIT_SHA=${SHORT_SHA} \
--build-arg CI=true \
-t ${REGISTRY}/${TARGET}:${VERSION} \
-t ${REGISTRY}/${TARGET}:local \
-f all.Dockerfile \
--load \
.
log_success "${TARGET} built successfully"
log_info "Tagged as: ${REGISTRY}/${TARGET}:${VERSION}"
log_info "Tagged as: ${REGISTRY}/${TARGET}:local"
done
log_success "All builds completed successfully!"
log_info ""
log_info "Built images:"
for TARGET in $TARGETS; do
echo " - ${REGISTRY}/${TARGET}:${VERSION}"
echo " - ${REGISTRY}/${TARGET}:local"
done