feat(landing): Make Nuxt app deployable

This commit is contained in:
2026-01-03 18:09:08 +01:00
parent 2754ed4724
commit a086763c80
4 changed files with 205 additions and 21 deletions

View File

@@ -50,6 +50,14 @@ services:
env_file: env_file:
- .env.prod - .env.prod
landing:
image: gitea.lugnas.de/denis/legalconsenthub-landing:latest
container_name: legalconsenthub-landing
ports:
- "3211:3000"
networks:
- legalconsenthub-net
keycloak: keycloak:
image: quay.io/keycloak/keycloak:26.4.0 image: quay.io/keycloak/keycloak:26.4.0
container_name: legalconsenthub-keycloak container_name: legalconsenthub-keycloak

28
landing/Dockerfile Normal file
View File

@@ -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"]

View File

@@ -1,5 +1,5 @@
{ {
"name": "nuxt-app", "name": "legalconsenthub-landing",
"type": "module", "type": "module",
"private": true, "private": true,
"scripts": { "scripts": {

View File

@@ -6,6 +6,7 @@ RED='\033[0;31m'
GREEN='\033[0;32m' GREEN='\033[0;32m'
YELLOW='\033[1;33m' YELLOW='\033[1;33m'
BLUE='\033[0;34m' BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
NC='\033[0m' NC='\033[0m'
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -13,6 +14,7 @@ TEMP_DIR=$(mktemp -d)
DEPLOY_FLAG=false DEPLOY_FLAG=false
RUN_FRONTEND=true RUN_FRONTEND=true
RUN_BACKEND=true RUN_BACKEND=true
RUN_LANDING=true
cleanup() { cleanup() {
rm -rf "$TEMP_DIR" rm -rf "$TEMP_DIR"
@@ -47,19 +49,25 @@ show_help() {
cat << EOF cat << EOF
Usage: $(basename "$0") [OPTIONS] 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: OPTIONS:
--deploy Deploy to server after successful build --deploy Deploy to server after successful build
--frontend-only Run only the frontend job --frontend-only Run only the frontend job
--backend-only Run only the backend 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 --help Show this help message
EXAMPLES: EXAMPLES:
$(basename "$0") # Run both frontend and backend in parallel $(basename "$0") # Run all jobs in parallel
$(basename "$0") --deploy # Run both jobs and deploy $(basename "$0") --deploy # Run all jobs and deploy
$(basename "$0") --frontend-only # Run only frontend job $(basename "$0") --frontend-only # Run only frontend job
$(basename "$0") --backend-only # Run only backend 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 $(basename "$0") --frontend-only --deploy # Run frontend and deploy
ENVIRONMENT: ENVIRONMENT:
@@ -236,12 +244,78 @@ backend_job() {
return ${PIPESTATUS[0]} return ${PIPESTATUS[0]}
} }
run_jobs() { landing_job() {
local run_parallel=false 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 run_parallel=true
log_info "Starting parallel jobs..." log_info "Starting $job_count parallel jobs..."
else else
log_info "Starting job..." log_info "Starting job..."
fi fi
@@ -249,24 +323,47 @@ run_jobs() {
local frontend_exit=0 local frontend_exit=0
local backend_exit=0 local backend_exit=0
local landing_exit=0
if [ "$run_parallel" = true ]; then if [ "$run_parallel" = true ]; then
local frontend_pid=""
local backend_pid=""
local landing_pid=""
if [ "$RUN_FRONTEND" = true ]; then
frontend_job true & frontend_job true &
local frontend_pid=$! frontend_pid=$!
backend_job true &
local backend_pid=$!
log_info "Frontend PID: $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" 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 "Waiting for jobs to complete..." log_info "Waiting for jobs to complete..."
echo "" echo ""
set +e set +e
if [ -n "$frontend_pid" ]; then
wait $frontend_pid wait $frontend_pid
frontend_exit=$? frontend_exit=$?
fi
if [ -n "$backend_pid" ]; then
wait $backend_pid wait $backend_pid
backend_exit=$? backend_exit=$?
fi
if [ -n "$landing_pid" ]; then
wait $landing_pid
landing_exit=$?
fi
set -e set -e
else else
if [ "$RUN_FRONTEND" = true ]; then if [ "$RUN_FRONTEND" = true ]; then
@@ -282,6 +379,13 @@ run_jobs() {
backend_exit=$? backend_exit=$?
set -e set -e
fi fi
if [ "$RUN_LANDING" = true ]; then
set +e
landing_job false
landing_exit=$?
set -e
fi
fi fi
echo "" echo ""
@@ -307,6 +411,15 @@ run_jobs() {
fi fi
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 if [ "$has_failure" = true ]; then
log_error "One or more jobs failed. Aborting pipeline." log_error "One or more jobs failed. Aborting pipeline."
exit 1 exit 1
@@ -357,6 +470,7 @@ deploy() {
main() { main() {
local original_args=("$@") local original_args=("$@")
local only_flag_used=false
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
@@ -365,13 +479,48 @@ main() {
shift shift
;; ;;
--frontend-only) --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_FRONTEND=true
RUN_BACKEND=false RUN_BACKEND=false
RUN_LANDING=false
shift shift
;; ;;
--backend-only) --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_FRONTEND=false
RUN_BACKEND=true 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 shift
;; ;;
--help) --help)
@@ -384,8 +533,8 @@ main() {
esac esac
done done
if [ "$RUN_FRONTEND" = false ] && [ "$RUN_BACKEND" = false ]; then if [ "$RUN_FRONTEND" = false ] && [ "$RUN_BACKEND" = false ] && [ "$RUN_LANDING" = false ]; then
log_error "Cannot specify both --frontend-only and --backend-only" log_error "No jobs to run. At least one job must be enabled."
exit 1 exit 1
fi fi
@@ -410,4 +559,3 @@ main() {
} }
main "$@" main "$@"