diff --git a/deployment/docker-compose-prod.yaml b/deployment/docker-compose-prod.yaml index ca9f661..e85a4e2 100755 --- a/deployment/docker-compose-prod.yaml +++ b/deployment/docker-compose-prod.yaml @@ -50,6 +50,14 @@ services: env_file: - .env.prod + landing: + image: gitea.lugnas.de/denis/legalconsenthub-landing:latest + container_name: legalconsenthub-landing + ports: + - "3211:3000" + networks: + - legalconsenthub-net + keycloak: image: quay.io/keycloak/keycloak:26.4.0 container_name: legalconsenthub-keycloak diff --git a/landing/Dockerfile b/landing/Dockerfile new file mode 100644 index 0000000..7f71690 --- /dev/null +++ b/landing/Dockerfile @@ -0,0 +1,28 @@ +FROM node:22.16.0-alpine AS builder + +WORKDIR /app + +RUN npm install -g pnpm@10.13.1 + +COPY landing/package.json landing/pnpm-lock.yaml ./ + +RUN pnpm install --frozen-lockfile + +COPY landing/ . + +RUN pnpm build + +FROM node:22.16.0-alpine AS runner + +WORKDIR /app + +COPY --from=builder /app/.output /app/.output + +ENV NODE_ENV=production +ENV HOST=0.0.0.0 +ENV PORT=3000 + +EXPOSE 3000 + +CMD ["node", ".output/server/index.mjs"] + diff --git a/landing/package.json b/landing/package.json index d6a3d51..5ba3a4e 100644 --- a/landing/package.json +++ b/landing/package.json @@ -1,5 +1,5 @@ { - "name": "nuxt-app", + "name": "legalconsenthub-landing", "type": "module", "private": true, "scripts": { diff --git a/pipeline.sh b/pipeline.sh index eb6054f..d089df3 100755 --- a/pipeline.sh +++ b/pipeline.sh @@ -6,6 +6,7 @@ RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' +MAGENTA='\033[0;35m' NC='\033[0m' SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -13,6 +14,7 @@ TEMP_DIR=$(mktemp -d) DEPLOY_FLAG=false RUN_FRONTEND=true RUN_BACKEND=true +RUN_LANDING=true cleanup() { rm -rf "$TEMP_DIR" @@ -47,19 +49,25 @@ show_help() { cat << EOF Usage: $(basename "$0") [OPTIONS] -CI/CD Pipeline Script - Runs frontend and backend builds in parallel with optional deployment +CI/CD Pipeline Script - Runs frontend, backend, and landing builds in parallel with optional deployment OPTIONS: --deploy Deploy to server after successful build --frontend-only Run only the frontend job --backend-only Run only the backend job + --landing-only Run only the landing page job + --no-frontend Skip the frontend job + --no-backend Skip the backend job + --no-landing Skip the landing page job --help Show this help message EXAMPLES: - $(basename "$0") # Run both frontend and backend in parallel - $(basename "$0") --deploy # Run both jobs and deploy + $(basename "$0") # Run all jobs in parallel + $(basename "$0") --deploy # Run all jobs and deploy $(basename "$0") --frontend-only # Run only frontend job $(basename "$0") --backend-only # Run only backend job + $(basename "$0") --landing-only # Run only landing page job + $(basename "$0") --no-landing # Run frontend and backend only $(basename "$0") --frontend-only --deploy # Run frontend and deploy ENVIRONMENT: @@ -236,12 +244,78 @@ backend_job() { return ${PIPESTATUS[0]} } -run_jobs() { - local run_parallel=false +landing_job() { + local log_file="$TEMP_DIR/landing.log" + local use_prefix=$1 - if [ "$RUN_FRONTEND" = true ] && [ "$RUN_BACKEND" = true ]; then + ( + set +e + + echo "==================== LANDING JOB ====================" + log_info "Starting landing page build..." + + cd "$SCRIPT_DIR/landing" || exit 1 + + log_info "Installing dependencies..." + pnpm install --frozen-lockfile + if [ $? -ne 0 ]; then + log_error "Dependencies installation failed" + exit 1 + fi + log_success "Dependencies installed" + + log_info "Running linting..." + pnpm lint + if [ $? -ne 0 ]; then + log_error "Linting failed" + exit 1 + fi + log_success "Linting passed" + + log_info "Running type checking..." + pnpm type-check + if [ $? -ne 0 ]; then + log_error "Type checking failed" + exit 1 + fi + log_success "Type checking passed" + + log_info "Building Docker image..." + mkdir -p "$SCRIPT_DIR/.buildx-cache/landing" + docker buildx build \ + --platform linux/amd64 \ + --tag "gitea.lugnas.de/denis/legalconsenthub-landing:latest" \ + --tag "gitea.lugnas.de/denis/legalconsenthub-landing:$GIT_SHA" \ + --file ./Dockerfile \ + --cache-from type=local,src="$SCRIPT_DIR/.buildx-cache/landing" \ + --cache-to type=local,dest="$SCRIPT_DIR/.buildx-cache/landing",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-landing:latest" + log_info "Image: gitea.lugnas.de/denis/legalconsenthub-landing:$GIT_SHA" + + exit 0 + ) 2>&1 | if [ "$use_prefix" = true ]; then prefix_output "LANDING" "$MAGENTA"; else cat; fi | tee "$log_file" + + return ${PIPESTATUS[0]} +} + +run_jobs() { + local job_count=0 + [ "$RUN_FRONTEND" = true ] && ((job_count++)) + [ "$RUN_BACKEND" = true ] && ((job_count++)) + [ "$RUN_LANDING" = true ] && ((job_count++)) + + local run_parallel=false + if [ "$job_count" -gt 1 ]; then run_parallel=true - log_info "Starting parallel jobs..." + log_info "Starting $job_count parallel jobs..." else log_info "Starting job..." fi @@ -249,24 +323,47 @@ run_jobs() { local frontend_exit=0 local backend_exit=0 + local landing_exit=0 if [ "$run_parallel" = true ]; then - frontend_job true & - local frontend_pid=$! + local frontend_pid="" + local backend_pid="" + local landing_pid="" - backend_job true & - local backend_pid=$! + if [ "$RUN_FRONTEND" = true ]; then + frontend_job true & + frontend_pid=$! + log_info "Frontend PID: $frontend_pid" + fi + + if [ "$RUN_BACKEND" = true ]; then + backend_job true & + backend_pid=$! + log_info "Backend PID: $backend_pid" + fi + + if [ "$RUN_LANDING" = true ]; then + landing_job true & + landing_pid=$! + log_info "Landing PID: $landing_pid" + fi - 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=$? - wait $backend_pid - backend_exit=$? + if [ -n "$frontend_pid" ]; then + wait $frontend_pid + frontend_exit=$? + fi + if [ -n "$backend_pid" ]; then + wait $backend_pid + backend_exit=$? + fi + if [ -n "$landing_pid" ]; then + wait $landing_pid + landing_exit=$? + fi set -e else if [ "$RUN_FRONTEND" = true ]; then @@ -282,6 +379,13 @@ run_jobs() { backend_exit=$? set -e fi + + if [ "$RUN_LANDING" = true ]; then + set +e + landing_job false + landing_exit=$? + set -e + fi fi echo "" @@ -307,6 +411,15 @@ run_jobs() { fi fi + if [ "$RUN_LANDING" = true ]; then + if [ "$landing_exit" -eq 0 ]; then + log_success "Landing job completed successfully" + else + log_error "Landing job failed with exit code $landing_exit" + has_failure=true + fi + fi + if [ "$has_failure" = true ]; then log_error "One or more jobs failed. Aborting pipeline." exit 1 @@ -357,6 +470,7 @@ deploy() { main() { local original_args=("$@") + local only_flag_used=false while [[ $# -gt 0 ]]; do case $1 in @@ -365,13 +479,48 @@ main() { shift ;; --frontend-only) + if [ "$only_flag_used" = true ]; then + log_error "Cannot combine multiple --*-only flags" + exit 1 + fi + only_flag_used=true RUN_FRONTEND=true RUN_BACKEND=false + RUN_LANDING=false shift ;; --backend-only) + if [ "$only_flag_used" = true ]; then + log_error "Cannot combine multiple --*-only flags" + exit 1 + fi + only_flag_used=true RUN_FRONTEND=false RUN_BACKEND=true + RUN_LANDING=false + shift + ;; + --landing-only) + if [ "$only_flag_used" = true ]; then + log_error "Cannot combine multiple --*-only flags" + exit 1 + fi + only_flag_used=true + RUN_FRONTEND=false + RUN_BACKEND=false + RUN_LANDING=true + shift + ;; + --no-frontend) + RUN_FRONTEND=false + shift + ;; + --no-backend) + RUN_BACKEND=false + shift + ;; + --no-landing) + RUN_LANDING=false shift ;; --help) @@ -384,8 +533,8 @@ main() { esac done - if [ "$RUN_FRONTEND" = false ] && [ "$RUN_BACKEND" = false ]; then - log_error "Cannot specify both --frontend-only and --backend-only" + if [ "$RUN_FRONTEND" = false ] && [ "$RUN_BACKEND" = false ] && [ "$RUN_LANDING" = false ]; then + log_error "No jobs to run. At least one job must be enabled." exit 1 fi @@ -410,4 +559,3 @@ main() { } main "$@" -