bugfix/main-13-UpdateConfigurations #17

Merged
husbando_enjoyer merged 16 commits from bugfix/main-13-UpdateConfigurations into main 2025-12-28 11:15:37 +01:00
Showing only changes of commit 558a3198f4 - Show all commits

View File

@@ -2,6 +2,7 @@ pipeline {
agent none agent none
options { options {
disableConcurrentBuilds()
timestamps() timestamps()
} }
@@ -13,7 +14,7 @@ pipeline {
) )
string( string(
name: 'JENKINS_JOB_NAME', name: 'JENKINS_JOB_NAME',
defaultValue: 'TallerCiCd', defaultValue: 'CD',
description: 'Nombre del job que se consulta en Jenkins' description: 'Nombre del job que se consulta en Jenkins'
) )
string( string(
@@ -33,6 +34,14 @@ pipeline {
PYTHONDONTWRITEBYTECODE = 1 PYTHONDONTWRITEBYTECODE = 1
} }
triggers {
gitea(
branchFilterType: 'Include',
branchFilter: 'main',
secret: ''
)
}
stages { stages {
/* ========================= /* =========================
@@ -83,55 +92,18 @@ pipeline {
sh ''' sh '''
set -e set -e
OLD_BACKEND_LATEST_ID=$(docker images -q cafeteria-backend:latest || true)
OLD_BACKEND_PREVIOUS_ID=$(docker images -q cafeteria-backend:previous || true)
OLD_FRONTEND_LATEST_ID=$(docker images -q cafeteria-frontend:latest || true)
OLD_FRONTEND_PREVIOUS_ID=$(docker images -q cafeteria-frontend:previous || true)
docker build \ docker build \
--build-arg APP_VERSION=${APP_VERSION} \ --build-arg APP_VERSION=${APP_VERSION} \
--build-arg GIT_COMMIT=${COMMIT_SHORT} \ --build-arg GIT_COMMIT=${COMMIT_SHORT} \
--build-arg COMMIT_AUTHOR="${COMMIT_AUTHOR}" \ --build-arg COMMIT_AUTHOR="${COMMIT_AUTHOR}" \
--build-arg BUILD_NUMBER=${BUILD_NUMBER} \ --build-arg BUILD_NUMBER=${BUILD_NUMBER} \
-t cafeteria-backend:latest \ -t cafeteria-backend:${APP_VERSION} \
./backend ./backend
docker build \ docker build \
--build-arg VITE_API_BASE=${VITE_API_BASE} \ --build-arg VITE_API_BASE=${VITE_API_BASE} \
-t cafeteria-frontend:latest \ -t cafeteria-frontend:${APP_VERSION} \
./frontend ./frontend
NEW_BACKEND_LATEST_ID=$(docker images -q cafeteria-backend:latest || true)
NEW_FRONTEND_LATEST_ID=$(docker images -q cafeteria-frontend:latest || true)
if [ -n "$OLD_BACKEND_LATEST_ID" ]; then
docker tag "$OLD_BACKEND_LATEST_ID" cafeteria-backend:previous
fi
if [ -n "$OLD_FRONTEND_LATEST_ID" ]; then
docker tag "$OLD_FRONTEND_LATEST_ID" cafeteria-frontend:previous
fi
if [ -n "$OLD_BACKEND_PREVIOUS_ID" ] && \
[ "$OLD_BACKEND_PREVIOUS_ID" != "$OLD_BACKEND_LATEST_ID" ] && \
[ "$OLD_BACKEND_PREVIOUS_ID" != "$NEW_BACKEND_LATEST_ID" ]; then
docker rmi "$OLD_BACKEND_PREVIOUS_ID" || true
fi
if [ -n "$OLD_FRONTEND_PREVIOUS_ID" ] && \
[ "$OLD_FRONTEND_PREVIOUS_ID" != "$OLD_FRONTEND_LATEST_ID" ] && \
[ "$OLD_FRONTEND_PREVIOUS_ID" != "$NEW_FRONTEND_LATEST_ID" ]; then
docker rmi "$OLD_FRONTEND_PREVIOUS_ID" || true
fi
cleanup_tags() {
repo="$1"
docker images --format "{{.Repository}}:{{.Tag}}" \
| awk -v repo="$repo" '$0 ~ "^"repo":" && $0 !~ /:latest$|:previous$/' \
| xargs -r docker rmi || true
}
cleanup_tags cafeteria-backend
cleanup_tags cafeteria-frontend
''' '''
} }
} }
@@ -153,9 +125,9 @@ pipeline {
sh ''' sh '''
set -e set -e
echo "Deploying backend ${BUILD_NUMBER}" echo "Deploying ${APP_VERSION}"
BACKEND_TAG=latest FRONTEND_TAG=latest docker compose up -d BACKEND_TAG=${APP_VERSION} FRONTEND_TAG=${APP_VERSION} docker compose up -d
''' '''
} }
} }