pipeline { agent any environment { // Tag images with the build number so they are unique FRONTEND_IMAGE = "chore-app-backend:${env.BUILD_ID}" BACKEND_IMAGE = "chore-app-frontend:${env.BUILD_ID}" VUE_CONTAINER_NAME = "chore-app-frontend" FLASK_CONTAINER_NAME = "chore-app-backend" NETWORK_NAME = "chore-app-net" } stages { stage('Checkout') { steps { // Pulls code from your configured Git repo checkout scm } } stage('Build Frontend (Vue) App') { steps { dir('web/vue-app') { sh 'docker build -t ${FRONTEND_IMAGE} .' } } } stage('Build Backend (Flask) App') { steps { dir('.') { sh 'docker build -t ${BACKEND_IMAGE} .' } } } stage('Deploy') { steps { echo 'Stopping and removing old containers...' sh "docker stop ${VUE_CONTAINER_NAME} || true" sh "docker rm ${VUE_CONTAINER_NAME} || true" sh "docker stop ${FLASK_CONTAINER_NAME} || true" sh "docker rm ${FLASK_CONTAINER_NAME} || true" echo 'Cleaning up and creating network...' sh "docker network rm -f ${NETWORK_NAME} || true" sh "docker network create ${NETWORK_NAME}" echo "Starting new containers" sh """ docker run -d \\ --name ${VUE_CONTAINER_NAME} \\ --network ${NETWORK_NAME} \\ -p 443:443 \\ ${FRONTEND_IMAGE} """ sh """ docker run -d \\ --name ${FLASK_CONTAINER_NAME} \\ --network ${NETWORK_NAME} \\ ${BACKEND_IMAGE} """ echo 'Deployment complete!' } } stage('Cleanup') { steps { // Optional: Stop old containers and run the new ones // Note: In production, you would push to a registry (DockerHub) instead sh "echo 'Build Complete. Images ready: ${FRONTEND_IMAGE} and ${BACKEND_IMAGE}'" } } } }