Teste de PR
This commit is contained in:
parent
d1e21c8da9
commit
8bb74fa1c9
3 changed files with 160 additions and 2 deletions
158
pipeline.md
Normal file
158
pipeline.md
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
pipeline {
|
||||
agent any
|
||||
|
||||
triggers {
|
||||
GenericTrigger(
|
||||
genericVariables: [
|
||||
[key: 'action', value: '$.action'],
|
||||
[key: 'merged', value: '$.pull_request.merged']
|
||||
],
|
||||
causeString: 'Pipeline disparado por merge de PR no Forgejo',
|
||||
printContributedVariables: true,
|
||||
printPostContent: true,
|
||||
regexpFilterText: '$action $merged',
|
||||
regexpFilterExpression: 'closed true'
|
||||
)
|
||||
}
|
||||
|
||||
environment {
|
||||
DEPLOY_USER = "jenkins"
|
||||
DEPLOY_SERVER = "192.168.1.81"
|
||||
IMAGE_NAME = "portal-app"
|
||||
CONTAINER_NAME = "portal-app"
|
||||
REMOTE_PATH = "/home/jenkins/app"
|
||||
}
|
||||
|
||||
stages {
|
||||
|
||||
stage('Testar Conexão SSH') {
|
||||
steps {
|
||||
sshagent(credentials: ['ssh-key-jenkins']) {
|
||||
sh "ssh -o StrictHostKeyChecking=no ${DEPLOY_USER}@${DEPLOY_SERVER} 'echo Conexão SSH bem-sucedida!'"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Ver chave pública usada') {
|
||||
steps {
|
||||
sshagent(credentials: ['ssh-key-jenkins']) {
|
||||
sh 'ssh-add -L'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Checkout Código (local, só para pegar commit hash)') {
|
||||
steps {
|
||||
git branch: 'main', url: 'https://forgeo-olymp.duckdns.org/rayankonecny/portal-app.git' // usando IP local por confiabilidade
|
||||
script {
|
||||
env.GIT_COMMIT = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
||||
env.BUILD_TAG = "${env.BUILD_NUMBER}-${env.GIT_COMMIT}"
|
||||
echo "BUILD_TAG definido como: ${env.BUILD_TAG}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Clonar Projeto e Criar Dockerfile no Servidor') {
|
||||
steps {
|
||||
sshagent(credentials: ['ssh-key-jenkins']) {
|
||||
script {
|
||||
sh """
|
||||
ssh -o StrictHostKeyChecking=no ${DEPLOY_USER}@${DEPLOY_SERVER} '
|
||||
set -e
|
||||
|
||||
mkdir -p ${REMOTE_PATH}
|
||||
git config --global --add safe.directory ${REMOTE_PATH}
|
||||
rm -rf ${REMOTE_PATH}
|
||||
|
||||
git clone https://forgeo-olymp.duckdns.org/rayankonecny/portal-app.git ${REMOTE_PATH}
|
||||
|
||||
if [ -f ${REMOTE_PATH}/.env ]; then
|
||||
echo "[INFO] Removendo NODE_ENV do .env para evitar erro com Vite"
|
||||
sed -i "/NODE_ENV/d" ${REMOTE_PATH}/.env
|
||||
fi
|
||||
|
||||
cat <<EOF > ${REMOTE_PATH}/Dockerfile
|
||||
FROM node:18-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm install
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 5173
|
||||
|
||||
CMD ["npm", "run", "dev"]
|
||||
EOF
|
||||
'
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build da Imagem Podman') {
|
||||
steps {
|
||||
sshagent(credentials: ['ssh-key-jenkins']) {
|
||||
sh """
|
||||
ssh -o StrictHostKeyChecking=no ${DEPLOY_USER}@${DEPLOY_SERVER} '
|
||||
cd ${REMOTE_PATH} &&
|
||||
podman build -t ${IMAGE_NAME}:${BUILD_TAG} -t ${IMAGE_NAME}:latest .
|
||||
'
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Parar e Remover Container Antigo') {
|
||||
steps {
|
||||
sshagent(credentials: ['ssh-key-jenkins']) {
|
||||
sh """
|
||||
ssh ${DEPLOY_USER}@${DEPLOY_SERVER} '
|
||||
podman stop ${CONTAINER_NAME} || true &&
|
||||
podman rm ${CONTAINER_NAME} || true
|
||||
'
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy no Servidor') {
|
||||
steps {
|
||||
sshagent(credentials: ['ssh-key-jenkins']) {
|
||||
sh """
|
||||
ssh ${DEPLOY_USER}@${DEPLOY_SERVER} '
|
||||
podman run -d --network host --name ${CONTAINER_NAME} ${IMAGE_NAME}:${BUILD_TAG}
|
||||
'
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Verificar Status do Container') {
|
||||
steps {
|
||||
sshagent(credentials: ['ssh-key-jenkins']) {
|
||||
sh """
|
||||
ssh ${DEPLOY_USER}@${DEPLOY_SERVER} '
|
||||
podman ps | grep ${CONTAINER_NAME} || echo "Container não encontrado"
|
||||
'
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Limpeza de Imagens Antigas') {
|
||||
steps {
|
||||
sshagent(credentials: ['ssh-key-jenkins']) {
|
||||
sh """
|
||||
ssh ${DEPLOY_USER}@${DEPLOY_SERVER} '
|
||||
podman image prune -f
|
||||
'
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ import * as React from 'react'
|
|||
const App: React.FC = () => {
|
||||
return (
|
||||
<>
|
||||
<h1>Hello</h1>
|
||||
<h1>Testando</h1>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
color: rgba(188, 82, 197, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue