diff --git a/Jenkinsfile b/Jenkinsfile index bf819de..583c17e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,6 +31,40 @@ pipeline { } } + stage('Deploy') { + steps { + echo 'Stopping and removing old containers...' + + // 1. Stop and remove the old running containers (if they exist) + // The || true prevents the build from failing if the container doesn't exist yet + 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 'Starting new containers...' + + // 2. Start the newly built images + // You must customize the ports (-p) and environment variables (-e) as needed + sh """ + docker run -d \\ + --name ${VUE_CONTAINER_NAME} \\ + -p 443:443 \\ + ${VUE_IMAGE} + """ + + sh """ + docker run -d \\ + --name ${FLASK_CONTAINER_NAME} \\ + -p 5000:5000 \\ + ${FLASK_IMAGE} + """ + + echo 'Deployment complete!' + } + } + } + stage('Cleanup') { steps { // Optional: Stop old containers and run the new ones