ci: implements jenkins deploy
This commit is contained in:
14
Dockerfile
Normal file
14
Dockerfile
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Stage 1: build
|
||||||
|
FROM node:20-alpine AS build
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build # Esto genera /dist
|
||||||
|
|
||||||
|
# Stage 2: serve con Nginx
|
||||||
|
FROM nginx:alpine
|
||||||
|
COPY --from=build /app/dist /usr/share/nginx/html
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
EXPOSE 80
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
77
Jenkinsfile
vendored
Normal file
77
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
|
||||||
|
environment {
|
||||||
|
REGISTRY_URL = "registry.pablotj.com"
|
||||||
|
USER = "andromeda"
|
||||||
|
PASS = credentials('docker-registry-password')
|
||||||
|
}
|
||||||
|
|
||||||
|
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: 'env', variable: 'SECRET_ENV')]) {
|
||||||
|
sh 'cp $SECRET_ENV .env'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build and Tag Docker Image') {
|
||||||
|
steps {
|
||||||
|
echo "Building Docker image..."
|
||||||
|
sh '''
|
||||||
|
make build
|
||||||
|
make tag
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('ush Docker Image') {
|
||||||
|
steps {
|
||||||
|
echo "Tagging and pushing Docker image to registry..."
|
||||||
|
sh '''
|
||||||
|
echo $PASS | docker login ${REGISTRY_URL} -u ${USER} --password-stdin
|
||||||
|
make push
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Deploy Docker Container') {
|
||||||
|
steps {
|
||||||
|
echo "Stopping old container and running new container..."
|
||||||
|
sh '''
|
||||||
|
make stop
|
||||||
|
make run
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
success {
|
||||||
|
echo "✅ Deployment completed successfully!"
|
||||||
|
}
|
||||||
|
failure {
|
||||||
|
echo "❌ Pipeline failed!"
|
||||||
|
}
|
||||||
|
always {
|
||||||
|
deleteDir()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
Makefile
Normal file
38
Makefile
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
STACK=pablotj-portfolio
|
||||||
|
APP_NAME=pablotj-portfolio-web
|
||||||
|
IMAGE_NAME=$(APP_NAME)
|
||||||
|
|
||||||
|
REGISTRY_URL=registry.pablotj.com
|
||||||
|
NAMESPACE=andromeda
|
||||||
|
TAG?=latest
|
||||||
|
|
||||||
|
HOST_PORT=8180
|
||||||
|
CONTAINER_PORT=80
|
||||||
|
|
||||||
|
IMAGE_FULL=$(REGISTRY_URL)/$(NAMESPACE)/$(IMAGE_NAME):$(TAG)
|
||||||
|
|
||||||
|
build:
|
||||||
|
docker build -t $(IMAGE_NAME):$(TAG) .
|
||||||
|
|
||||||
|
tag:
|
||||||
|
docker tag $(IMAGE_NAME):$(TAG) $(IMAGE_FULL)
|
||||||
|
|
||||||
|
push:
|
||||||
|
docker push $(IMAGE_FULL)
|
||||||
|
|
||||||
|
run:
|
||||||
|
docker run -d \
|
||||||
|
--name $(APP_NAME) \
|
||||||
|
--name mi-contenedor-suelto \
|
||||||
|
--label com.docker.compose.service="$(APP_NAME)" \
|
||||||
|
--label com.docker.compose.project="$(STACK)" \
|
||||||
|
--network andromeda \
|
||||||
|
-p $(HOST_PORT):$(CONTAINER_PORT) \
|
||||||
|
--env-file .env \
|
||||||
|
$(IMAGE_FULL)
|
||||||
|
|
||||||
|
stop:
|
||||||
|
docker stop $(APP_NAME) || true
|
||||||
|
docker rm $(APP_NAME) || true
|
||||||
|
|
||||||
|
deploy: build tag push stop run
|
||||||
Reference in New Issue
Block a user