feat: Use caching in pipeline

This commit is contained in:
2025-12-06 19:24:39 +01:00
parent 248370a3f9
commit d441159560
2 changed files with 45 additions and 37 deletions

3
.gitignore vendored
View File

@@ -64,3 +64,6 @@ legalconsenthub/.api-client-middleware
### TestContainers persistent data ###
legalconsenthub-backend/postgres-data/
### Docker BuildKit cache ###
.buildx-cache/

View File

@@ -116,15 +116,15 @@ validate_environment() {
frontend_job() {
local log_file="$TEMP_DIR/frontend.log"
local use_prefix=$1
(
set +e
echo "==================== FRONTEND JOB ===================="
log_info "Starting frontend build..."
cd "$SCRIPT_DIR/legalconsenthub" || exit 1
log_info "Installing dependencies..."
pnpm install --frozen-lockfile
if [ $? -ne 0 ]; then
@@ -132,7 +132,7 @@ frontend_job() {
exit 1
fi
log_success "Dependencies installed"
log_info "Running linting..."
pnpm lint
if [ $? -ne 0 ]; then
@@ -140,7 +140,7 @@ frontend_job() {
exit 1
fi
log_success "Linting passed"
log_info "Running type checking..."
pnpm type-check
if [ $? -ne 0 ]; then
@@ -148,42 +148,44 @@ frontend_job() {
exit 1
fi
log_success "Type checking passed"
log_info "Building Docker image..."
docker buildx build \
--platform linux/amd64 \
--tag "gitea.lugnas.de/denis/legalconsenthub:latest" \
--tag "gitea.lugnas.de/denis/legalconsenthub:$GIT_SHA" \
--file ./Dockerfile \
--cache-from type=local,src="$SCRIPT_DIR/.buildx-cache/frontend" \
--cache-to type=local,dest="$SCRIPT_DIR/.buildx-cache/frontend",mode=max \
--push \
..
if [ $? -ne 0 ]; then
log_error "Docker build failed"
exit 1
fi
log_success "Docker image built and pushed successfully"
log_info "Image: gitea.lugnas.de/denis/legalconsenthub:latest"
log_info "Image: gitea.lugnas.de/denis/legalconsenthub:$GIT_SHA"
exit 0
) 2>&1 | if [ "$use_prefix" = true ]; then prefix_output "FRONTEND" "$BLUE"; else cat; fi | tee "$log_file"
return ${PIPESTATUS[0]}
}
backend_job() {
local log_file="$TEMP_DIR/backend.log"
local use_prefix=$1
(
set +e
echo "==================== BACKEND JOB ===================="
log_info "Starting backend build..."
cd "$SCRIPT_DIR/legalconsenthub-backend" || exit 1
log_info "Building application..."
./gradlew build -x test
if [ $? -ne 0 ]; then
@@ -191,7 +193,7 @@ backend_job() {
exit 1
fi
log_success "Build completed"
log_info "Running ktlint check..."
./gradlew ktlintCheck
if [ $? -ne 0 ]; then
@@ -199,7 +201,7 @@ backend_job() {
exit 1
fi
log_success "ktlint check passed"
log_info "Running tests..."
./gradlew test
if [ $? -ne 0 ]; then
@@ -207,33 +209,36 @@ backend_job() {
exit 1
fi
log_success "Tests passed"
log_info "Building Docker image..."
mkdir -p "$SCRIPT_DIR/.buildx-cache/backend"
docker buildx build \
--platform linux/amd64 \
--tag "gitea.lugnas.de/denis/legalconsenthub-backend:latest" \
--tag "gitea.lugnas.de/denis/legalconsenthub-backend:$GIT_SHA" \
--file ./Dockerfile \
--cache-from type=local,src="$SCRIPT_DIR/.buildx-cache/backend" \
--cache-to type=local,dest="$SCRIPT_DIR/.buildx-cache/backend",mode=max \
--push \
..
if [ $? -ne 0 ]; then
log_error "Docker build failed"
exit 1
fi
log_success "Docker image built and pushed successfully"
log_info "Image: gitea.lugnas.de/denis/legalconsenthub-backend:latest"
log_info "Image: gitea.lugnas.de/denis/legalconsenthub-backend:$GIT_SHA"
exit 0
) 2>&1 | if [ "$use_prefix" = true ]; then prefix_output "BACKEND" "$GREEN"; else cat; fi | tee "$log_file"
return ${PIPESTATUS[0]}
}
run_jobs() {
local run_parallel=false
if [ "$RUN_FRONTEND" = true ] && [ "$RUN_BACKEND" = true ]; then
run_parallel=true
log_info "Starting parallel jobs..."
@@ -241,22 +246,22 @@ run_jobs() {
log_info "Starting job..."
fi
echo ""
local frontend_exit=0
local backend_exit=0
if [ "$run_parallel" = true ]; then
frontend_job true &
local frontend_pid=$!
backend_job true &
local backend_pid=$!
log_info "Frontend PID: $frontend_pid"
log_info "Backend PID: $backend_pid"
log_info "Waiting for jobs to complete..."
echo ""
set +e
wait $frontend_pid
frontend_exit=$?
@@ -270,7 +275,7 @@ run_jobs() {
frontend_exit=$?
set -e
fi
if [ "$RUN_BACKEND" = true ]; then
set +e
backend_job false
@@ -281,9 +286,9 @@ run_jobs() {
echo ""
echo "==================== JOB SUMMARY ===================="
local has_failure=false
if [ "$RUN_FRONTEND" = true ]; then
if [ "$frontend_exit" -eq 0 ]; then
log_success "Frontend job completed successfully"
@@ -292,7 +297,7 @@ run_jobs() {
has_failure=true
fi
fi
if [ "$RUN_BACKEND" = true ]; then
if [ "$backend_exit" -eq 0 ]; then
log_success "Backend job completed successfully"
@@ -301,25 +306,25 @@ run_jobs() {
has_failure=true
fi
fi
if [ "$has_failure" = true ]; then
log_error "One or more jobs failed. Aborting pipeline."
exit 1
fi
log_success "All jobs completed successfully"
}
launch_in_iterm() {
log_info "Launching pipeline in new iTerm window..."
local script_path="$0"
local args=""
for arg in "$@"; do
args="$args $arg"
done
osascript <<EOF
tell application "iTerm"
create window with default profile
@@ -329,7 +334,7 @@ tell application "iTerm"
activate
end tell
EOF
log_success "Pipeline launched in iTerm window"
exit 0
}
@@ -352,7 +357,7 @@ deploy() {
main() {
local original_args=("$@")
while [[ $# -gt 0 ]]; do
case $1 in
--deploy)