ci: implements jenkins deploy

This commit is contained in:
2026-02-21 09:26:25 +01:00
parent b5c8364b47
commit 2a342dc69e
3 changed files with 133 additions and 0 deletions

86
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,86 @@
pipeline {
agent any
environment {
APP_NAME = "pablotj-portfolio-web"
IMAGE_NAME = "${APP_NAME}"
REGISTRY_URL = "registry.pablotj.com"
NAMESPACE = "andromeda"
USER = "andromeda"
PASS = credentials('docker-registry-password')
TAG = "latest"
HOST_PORT = "8080"
CONTAINER_PORT = "3000"
IMAGE_FULL = "${REGISTRY_URL}/${NAMESPACE}/${IMAGE_NAME}:${TAG}"
}
stages {
stage('Prepare Workspace & Checkout') {
steps {
echo "Cleaning workspace"
deleteDir()
}
}
stage('Checkout') {
steps {
echo "Checking out repo..."
checkout scm
}
}
stage('Load Environment') {
steps {
echo "Loading .env secret from Jenkins..."
withCredentials([file(credentialsId: 'pablotj-portfolio-website-env', variable: 'SECRET_ENV')]) {
sh 'cp $SECRET_ENV .env'
}
}
}
stage('Build Docker Image') {
steps {
echo "Building Docker image..."
sh '''
docker build -t ${IMAGE_NAME}:${TAG} .
'''
}
}
stage('Tag & Push Docker Image') {
steps {
echo "Tagging and pushing Docker image to registry..."
sh '''
docker tag ${IMAGE_NAME}:${TAG} ${IMAGE_FULL}
echo $PASS | docker login ${REGISTRY_URL} -u ${USER} --password-stdin
docker push ${IMAGE_FULL}
'''
}
}
stage('Deploy Docker Container') {
steps {
echo "Stopping old container and running new container..."
sh '''
docker stop ${APP_NAME} || true
docker rm ${APP_NAME} || true
docker run -d \
--name ${APP_NAME} \
-p ${HOST_PORT}:${CONTAINER_PORT} \
--env-file .env \
${IMAGE_FULL}
'''
}
}
}
post {
success {
echo "✅ Deployment completed successfully!"
}
failure {
echo "❌ Pipeline failed!"
}
}
}