8 Commits
Author SHA1 Message Date
vladp f4bcb58353 fix type GF_AUTH
Test Workflow / test (push) Successful in 2s
2025-12-08 15:30:07 +07:00
vladp 6a78475844 Merge remote-tracking branch 'origin/dev' into dev
Test Workflow / test (push) Successful in 1m26s
2025-12-01 11:39:27 +07:00
vladp 8a4b8e49f1 add test workflow 2025-12-01 11:39:15 +07:00
backdev 235ea7143a Удалить .gitea 2025-12-01 12:37:06 +08:00
backdev 520d2df3a9 Добавить .gitea 2025-12-01 12:34:24 +08:00
backdev 3b0803bef3 Удалить job.yaml 2025-12-01 12:33:50 +08:00
backdev 7d17b8d617 Обновить job.yaml 2025-12-01 12:32:06 +08:00
backdev c51608276d Добавить job 2025-12-01 12:31:34 +08:00
3 changed files with 237 additions and 2 deletions
+17
View File
@@ -0,0 +1,17 @@
name: Test Workflow
on:
push:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Print environment variables
run: |
echo "GITHUB_REPOSITORY: $GITHUB_REPOSITORY"
echo "GITHUB_SHA: $GITHUB_SHA"
echo "GITHUB_REF: $GITHUB_REF"
echo "GITHUB_ACTOR: $GITHUB_ACTOR"
echo "PATH: $PATH"
+2 -2
View File
@@ -15,8 +15,8 @@ services:
container_name: postgres
app:
image: popovtsev/ncp
# build: .
# image: popovtsev/ncp
build: .
container_name: no_copy_app
environment:
POSTGRES_DB: no_copy_
@@ -0,0 +1,218 @@
pipeline {
agent any
parameters {
string(
name: 'BRANCH',
defaultValue: 'dev',
description: 'Ветка для деплоя'
)
string(
name: 'SERVER',
defaultValue: '92.242.61.23',
description: 'Сервер для деплоя'
)
}
stages {
stage('Git pull') {
steps {
script {
checkout([
$class: 'GitSCM',
branches: [[name: params.BRANCH]],
userRemoteConfigs: [[
url: 'https://code.3err0.ru/backdev/no-copy.git',
credentialsId: 'nx-jen'
]]
])
}
}
}
stage('Stop old container') {
steps {
script {
withCredentials([
usernamePassword(
credentialsId: 'server-root-password',
usernameVariable: 'SSH_USER',
passwordVariable: 'SSH_PASS'
)
]) {
sh """
echo "Stop old container by branch ${params.BRANCH}..."
sshpass -p '$SSH_PASS' ssh $SSH_USER@$SERVER "
cd /opt/deployments/${params.BRANCH} 2>/dev/null || mkdir -p /opt/deployments/${params.BRANCH}
# Stop old container if have docker-compose
if [ -f 'docker-compose.yaml' ] || [ -f 'docker-compose.yml' ]; then
if [ -f 'docker-compose.yaml' ]; then
docker-compose -f docker-compose.yaml down 2>/dev/null || true
elif [ -f 'docker-compose.yml' ]; then
docker-compose -f docker-compose.yml down 2>/dev/null || true
fi
fi
# Stop and delete container by name
docker stop app-${params.BRANCH} 2>/dev/null || true
docker rm app-${params.BRANCH} 2>/dev/null || true
echo "Old containder deleted"
"
"""
}
}
}
}
stage('Copy to server') {
steps {
script {
withCredentials([
usernamePassword(
credentialsId: 'server-root-password',
usernameVariable: 'SSH_USER',
passwordVariable: 'SSH_PASS'
)
]) {
sh """
echo "Copy files on server..."
# Clean mkdir
sshpass -p '$SSH_PASS' ssh $SSH_USER@$SERVER "
rm -rf /opt/deployments/${params.BRANCH}/*
mkdir -p /opt/deployments/${params.BRANCH}
"
# Copy all files
sshpass -p '$SSH_PASS' scp -r ./* $SSH_USER@$SERVER:/opt/deployments/${params.BRANCH}/ 2>/dev/null || true
echo "Files copied"
"""
}
}
}
}
stage('Build on server') {
steps {
script {
withCredentials([
usernamePassword(
credentialsId: 'server-root-password',
usernameVariable: 'SSH_USER',
passwordVariable: 'SSH_PASS'
)
]) {
sh """
echo "Build on server..."
sshpass -p '$SSH_PASS' ssh $SSH_USER@$SERVER "
cd /opt/deployments/${params.BRANCH}
echo "Build Docker for branch ${params.BRANCH}..."
# delete old docker image
docker rmi app:${params.BRANCH} 2>/dev/null || true
# build from branch
if [ -f 'Dockerfile' ]; then
docker build -t app:${params.BRANCH} .
echo "Docker образ app:${params.BRANCH} собран"
fi
# or from docker-compose
if [ -f 'docker-compose.yaml' ]; then
docker-compose -f docker-compose.yaml build
echo "Build from docker-compose.yaml completed"
elif [ -f 'docker-compose.yml' ]; then
docker-compose -f docker-compose.yml build
echo "Build from docker-compose.yml completed"
fi
echo 'Build completed'
"
"""
}
}
}
}
stage('Start on server') {
steps {
script {
withCredentials([
usernamePassword(
credentialsId: 'server-root-password',
usernameVariable: 'SSH_USER',
passwordVariable: 'SSH_PASS'
)
]) {
sh """
echo "Start container..."
sshpass -p '$SSH_PASS' ssh $SSH_USER@$SERVER "
cd /opt/deployments/${params.BRANCH}
# If have docker-compose - use them
if [ -f 'docker-compose.yaml' ]; then
echo "Start docker-compose.yaml..."
docker-compose -f docker-compose.yaml up -d
elif [ -f 'docker-compose.yml' ]; then
echo "Start docker-compose.yml..."
docker-compose -f docker-compose.yml up -d
# If have Dockerfile - start
elif [ -f 'Dockerfile' ]; then
echo "Start app-${params.BRANCH}..."
docker run -d \\
--name app-${params.BRANCH} \\
-p 8080:8080 \\
app:${params.BRANCH}
else
echo "Error:Dockerfile NOT FOUND, docker-compose.yaml or docker-compose.yml"
exit 1
fi
echo 'Container start'
# Wait start
sleep 10
# Check status
echo 'status container:'
if [ -f 'docker-compose.yaml' ] || [ -f 'docker-compose.yml' ]; then
if [ -f 'docker-compose.yaml' ]; then
docker-compose -f docker-compose.yaml ps
else
docker-compose -f docker-compose.yml ps
fi
else
docker ps --filter "name=app-${params.BRANCH}"
fi
echo ''
echo 'Apps start on:'
echo 'http://$SERVER:80'
"
"""
}
}
}
}
}
post {
success {
echo "Deploy branch ${params.BRANCH} completed"
echo "App : http://$SERVER:80"
}
failure {
echo "Deploy failed"
}
}
}