Merge pull request 'feature/task-30-docker' (#31) from feature/task-30-docker into master
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good
Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good
Details
Reviewed-on: #31pull/35/head
commit
24839dc3fe
|
@ -0,0 +1,11 @@
|
|||
# Используем официальный образ OpenJDK 17 как базовый образ
|
||||
FROM openjdk:17
|
||||
|
||||
# Установка рабочей директории внутри контейнера
|
||||
WORKDIR /app
|
||||
|
||||
# Копируем JAR-файл приложения из локальной директории внутрь контейнера
|
||||
COPY ServerMonitorBot-0.0.1-SNAPSHOT.jar app.jar
|
||||
|
||||
# Команда для запуска Spring Boot приложения при старте контейнера
|
||||
CMD ["java", "-jar", "app.jar"]
|
|
@ -0,0 +1,64 @@
|
|||
pipeline {
|
||||
agent {
|
||||
docker {
|
||||
image 'maven:3.9.5-eclipse-temurin-17'
|
||||
args '-v /root/.m2:/root/.m2'
|
||||
}
|
||||
}
|
||||
|
||||
environment {
|
||||
SSH_HOST = credentials('ROCK_PI_5_SSH_HOST')
|
||||
SSH_PORT = credentials('ROCK_PI_5_SSH_PORT')
|
||||
SSH_USER = credentials('ROCK_PI_5_SSH_USER')
|
||||
SSH_PASS = credentials('ROCK_PI_5_SSH_PASS')
|
||||
PATH_TO_DEV_FOLDER = credentials('SERVERMONITORBOT_PATH_TO_DEV_FOLDER')
|
||||
IMAGE_NAME = 'servermonitorbot'
|
||||
IMAGE_VERSION = 'latest'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Init container') {
|
||||
steps {
|
||||
sh 'apt-get update && apt-get install -y sshpass openssh-client'
|
||||
}
|
||||
}
|
||||
stage('Build') {
|
||||
steps {
|
||||
withCredentials([file(credentialsId: 'SERVERMONITORBOT_APPLICATION_YAML', variable: 'application_yaml')]) {
|
||||
sh "cp -f \$application_yaml src/main/resources/application.yml"
|
||||
}
|
||||
sh 'mvn -B -DskipTests -X clean package spring-boot:repackage'
|
||||
}
|
||||
}
|
||||
stage('Prune images pre') {
|
||||
steps {
|
||||
sh """
|
||||
sshpass -p ${SSH_PASS} ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} 'docker image prune --all --force'
|
||||
"""
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
script {
|
||||
sh """
|
||||
sshpass -p ${SSH_PASS} ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} 'mkdir -p ${PATH_TO_DEV_FOLDER}'
|
||||
sshpass -p ${SSH_PASS} ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} 'rm -f ${PATH_TO_DEV_FOLDER}/{*.*}'
|
||||
sshpass -p ${SSH_PASS} scp -o StrictHostKeyChecking=no -P ${SSH_PORT} target/*.jar ${SSH_USER}@${SSH_HOST}:${PATH_TO_DEV_FOLDER}/
|
||||
sshpass -p ${SSH_PASS} scp -o StrictHostKeyChecking=no -P ${SSH_PORT} Dockerfile ${SSH_USER}@${SSH_HOST}:${PATH_TO_DEV_FOLDER}/
|
||||
sshpass -p ${SSH_PASS} scp -o StrictHostKeyChecking=no -P ${SSH_PORT} docker-compose.yml ${SSH_USER}@${SSH_HOST}:${PATH_TO_DEV_FOLDER}/
|
||||
sshpass -p ${SSH_PASS} ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} 'cd ${PATH_TO_DEV_FOLDER} && docker build --no-cache -t ${IMAGE_NAME}:${IMAGE_VERSION} .'
|
||||
sshpass -p ${SSH_PASS} ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} 'cd ${PATH_TO_DEV_FOLDER} && docker compose up -d'
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Prune images post') {
|
||||
steps {
|
||||
sh """
|
||||
sshpass -p ${SSH_PASS} ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} 'docker image prune --all --force'
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
pipeline {
|
||||
agent {
|
||||
docker {
|
||||
image 'maven:3.9.5-eclipse-temurin-17'
|
||||
args '-v /root/.m2:/root/.m2'
|
||||
}
|
||||
}
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh 'mvn -B -DskipTests -X clean package spring-boot:repackage'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
version: '3'
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: .
|
||||
depends_on:
|
||||
- db
|
||||
networks:
|
||||
default:
|
||||
|
||||
db:
|
||||
image: postgres:latest
|
||||
environment:
|
||||
POSTGRES_USER: servermonitorbot
|
||||
POSTGRES_PASSWORD: servermonitorbot
|
||||
POSTGRES_DB: servermonitorbot
|
||||
networks:
|
||||
default:
|
||||
|
||||
networks:
|
||||
default:
|
51
pom.xml
51
pom.xml
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<version>3.1.3</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>ru.ldeloff</groupId>
|
||||
|
@ -15,6 +15,11 @@
|
|||
<description>ServerMonitorBot</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<flyway.version>9.16.0</flyway.version>
|
||||
<db.url>${database.url}</db.url>
|
||||
<db.user>${database.username}</db.user>
|
||||
<db.password>${database.password}</db.password>
|
||||
<start-class>ru.ldeloff.servermonitorbot.ServerMonitorBotApplication</start-class>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -40,7 +45,7 @@
|
|||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>6.7.0</version>
|
||||
<version>6.8.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jcraft</groupId>
|
||||
|
@ -51,14 +56,15 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.liquibase</groupId>
|
||||
<artifactId>liquibase-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-core</artifactId>
|
||||
<version>${flyway.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -75,6 +81,39 @@
|
|||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-maven-plugin</artifactId>
|
||||
<version>${flyway.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>migrate</id>
|
||||
<phase>deploy</phase>
|
||||
<goals>
|
||||
<goal>migrate</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<url>${database.url}</url>
|
||||
<user>${database.username}</user>
|
||||
<password>${database.password}</password>
|
||||
<locations>
|
||||
<location>classpath:db/migration</location>
|
||||
</locations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
|
|
@ -2,20 +2,14 @@ spring:
|
|||
application:
|
||||
name: ServerMonitorBot
|
||||
datasource:
|
||||
url: jdbc:postgresql://localhost:5432/servermonitorbot
|
||||
url: jdbc:postgresql://db:5432/servermonitorbot
|
||||
username: servermonitorbot
|
||||
password: servermonitorbot
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: none
|
||||
liquibase:
|
||||
enabled: true
|
||||
change-log: classpath:db/scripts/changelog-master.xml
|
||||
url: jdbc:postgresql://localhost:5432/servermonitorbot
|
||||
user: servermonitorbot
|
||||
password: servermonitorbot
|
||||
liquibase-schema: "liquibase"
|
||||
default-schema: "servermonitorbot"
|
||||
flyway:
|
||||
locations: classpath:db/migration
|
||||
bot:
|
||||
name: "ServerMonitorBot"
|
||||
token: "token"
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
--liquibase formatted sql
|
||||
|
||||
--changeset L_DelOff:create_table_users rollbackSplitStatements:true
|
||||
--comment: Создание таблицы пользователей
|
||||
CREATE TABLE users
|
|
@ -1,5 +1,3 @@
|
|||
--liquibase formatted sql
|
||||
|
||||
--changeset L_DelOff:create_table_roles rollbackSplitStatements:true
|
||||
--comment: Создание таблицы ролей
|
||||
CREATE TABLE roles
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<databaseChangeLog
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||
|
||||
<include file="release_0_0_1/changelog.xml" relativeToChangelogFile="true"/>
|
||||
|
||||
|
||||
</databaseChangeLog>
|
|
@ -1,16 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<databaseChangeLog
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||
|
||||
<include file="scripts/01_create_table_users.sql" relativeToChangelogFile="true"/>
|
||||
<include file="scripts/02_create_table_roles.sql" relativeToChangelogFile="true"/>
|
||||
<include file="scripts/03_add_FK_users_to_roles.sql" relativeToChangelogFile="true"/>
|
||||
<include file="scripts/04_add_roles.sql" relativeToChangelogFile="true"/>
|
||||
<include file="scripts/05_add_anonymous_role.sql" relativeToChangelogFile="true"/>
|
||||
<include file="scripts/06_refactor_users_table.sql" relativeToChangelogFile="true"/>
|
||||
<include file="scripts/07_refactor_roles_table.sql" relativeToChangelogFile="true"/>
|
||||
<include file="scripts/08_add_roles.sql" relativeToChangelogFile="true"/>
|
||||
|
||||
</databaseChangeLog>
|
Loading…
Reference in New Issue