Skip to content

Commit

Permalink
ывдал
Browse files Browse the repository at this point in the history
  • Loading branch information
XyL1GaN4eG committed Jul 18, 2024
1 parent 1afd3d3 commit ccab3d4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 132 deletions.
80 changes: 38 additions & 42 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,56 +28,50 @@ jobs:
- name: Debug environment variables
run: printenv # Вывести все переменные окружения для отладки

- name: Build userService
run: mvn -e -B package --file userService/pom.xml # Собрать проект Maven, указав путь к pom.xml

- name: List built files
run: ls -la userService/target # Показать список файлов в целевой папке после сборки
- name: Discover and build microservices
run: |
for dir in $(find weatherProject -mindepth 1 -maxdepth 1 -type d); do
echo "Building microservice in $dir"
mvn -e -B package --file $dir/pom.xml
done
- name: Deploy userService to Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: 'userService/target/userService-0.0.1-SNAPSHOT.jar' # Указать путь к скомпилированному JAR файлу
target: '/home/xyl1gan4eg/myJavaProjects/weatherProject' # Указать целевой путь на сервере
port: 22
timeout: 30s
command_timeout: 10m
use_insecure_cipher: false
rm: false
debug: false
strip_components: 0
overwrite: true
tar_dereference: false
tar_exec: tar
proxy_port: 22
proxy_timeout: 30s
proxy_use_insecure_cipher: false # Настройки для scp-action, чтобы копировать файл на удаленный сервер
- name: List built files for all microservices
run: |
for dir in $(find weatherProject -mindepth 1 -maxdepth 1 -type d); do
echo "Listing files in $dir/target"
ls -la $dir/target
done
- name: Deploy microservices to Server
run: |
for dir in $(find weatherProject -mindepth 1 -maxdepth 1 -type d); do
service_name=$(basename $dir)
scp -i ${{ secrets.SSH_PRIVATE_KEY }} -o StrictHostKeyChecking=no $dir/target/*.jar ${{ secrets.SERVER_USERNAME }}@${{ secrets.SERVER_HOST }}:/home/xyl1gan4eg/myJavaProjects/weatherProject/$service_name/
done
- name: SSH into server and restart userService
- name: SSH into server and restart microservices
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
echo "Checking for JAR file..."
if [ -f /home/xyl1gan4eg/myJavaProjects/weatherProject/userService/target/userService-0.0.1-SNAPSHOT.jar ]; then
echo "JAR file found. Proceeding with service restart."
if sudo systemctl is-active --quiet user-service; then
sudo systemctl stop user-service
for dir in $(find /home/xyl1gan4eg/myJavaProjects/weatherProject -mindepth 1 -maxdepth 1 -type d); do
service_name=$(basename $dir)
echo "Checking for JAR file in $dir"
jar_file=$(ls $dir/target/*.jar 2> /dev/null)
if [ -n "$jar_file" ]; then
echo "JAR file found for $service_name. Proceeding with service restart."
if sudo systemctl is-active --quiet $service_name; then
sudo systemctl stop $service_name
fi
sudo cp $jar_file /opt/$service_name/
sudo systemctl start $service_name
else
echo "No JAR file found for $service_name!"
exit 1
fi
sudo cp /home/xyl1gan4eg/myJavaProjects/weatherProject/userService/targer/userService-0.0.1-SNAPSHOT.jar /opt/userService/
sudo systemctl start user-service
else
echo "JAR file not found!"
exit 1
fi
done
- name: List files on server for debug
uses: appleboy/ssh-action@master
Expand All @@ -86,5 +80,7 @@ jobs:
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
echo "Listing files in /home/xyl1gan4eg/myJavaProjects/weatherProject/userService/"
ls -la /home/xyl1gan4eg/myJavaProjects/weatherProject/userService/ # Показать список файлов в целевой папке для отладки
for dir in $(find /home/xyl1gan4eg/myJavaProjects/weatherProject -mindepth 1 -maxdepth 1 -type d); do
echo "Listing files in $dir"
ls -la $dir
done
2 changes: 1 addition & 1 deletion .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 32 additions & 89 deletions weatherApiService/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,89 +1,32 @@
name: Deploy to Ubuntu Server

on:
push:
branches:
- main # Запускать workflow при push на ветку main

jobs:
deploy:
runs-on: ubuntu-latest # Использовать последний доступный образ Ubuntu

steps:
- name: Checkout repository
uses: actions/checkout@v2 # Проверить репозиторий на машину сборки

- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'temurin' # Установить JDK 17 от Temurin
java-version: '17'

- name: Set environment variables
run: |
echo "DB_URL=${{ secrets.DB_URL }}" >> $GITHUB_ENV
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> $GITHUB_ENV
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> $GITHUB_ENV # Установить переменные окружения из секретов GitHub
- name: Debug environment variables
run: printenv # Вывести все переменные окружения для отладки

- name: Build userService
run: mvn -e -B package --file userService/pom.xml # Собрать проект Maven, указав путь к pom.xml

- name: List built files
run: ls -la userService/target # Показать список файлов в целевой папке после сборки

- name: Deploy userService to Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: 'userService/target/userService-0.0.1-SNAPSHOT.jar' # Указать путь к скомпилированному JAR файлу
target: '/home/xyl1gan4eg/myJavaProjects/weatherProject' # Указать целевой путь на сервере
port: 22
timeout: 30s
command_timeout: 10m
use_insecure_cipher: false
rm: false
debug: false
strip_components: 0
overwrite: true
tar_dereference: false
tar_exec: tar
proxy_port: 22
proxy_timeout: 30s
proxy_use_insecure_cipher: false # Настройки для scp-action, чтобы копировать файл на удаленный сервер

- name: SSH into server and restart userService
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
echo "Checking for JAR file..."
if [ -f /home/xyl1gan4eg/myJavaProjects/weatherProject/userService/target/userService-0.0.1-SNAPSHOT.jar ]; then
echo "JAR file found. Proceeding with service restart."
if sudo systemctl is-active --quiet user-service; then
sudo systemctl stop user-service
fi
sudo cp /home/xyl1gan4eg/myJavaProjects/weatherProject/userService/targer/userService-0.0.1-SNAPSHOT.jar /opt/userService/
sudo systemctl start user-service
else
echo "JAR file not found!"
exit 1
fi
- name: List files on server for debug
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
echo "Listing files in /home/xyl1gan4eg/myJavaProjects/weatherProject/userService/"
ls -la /home/xyl1gan4eg/myJavaProjects/weatherProject/userService/ # Показать список файлов в целевой папке для отладки
spring:
application:
name: weatherApiService
datasource:
url: jdbc:postgresql://localhost:5432/weatherproject
username: username
password: password
hikari:
allow-pool-suspension: true # Enable Hikari pool suspension for JVM checkpoint restore
jpa:
hibernate:
ddl-auto: none # Disable automatic schema generation by Hibernate
properties:
hibernate:
allow_jdbc_metadata_access: false # Disable Hibernate usage of JDBC metadata
show-sql: true # Enable logging of SQL statements
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect # Specify the dialect for PostgreSQL
sql:
init:
mode: never # Disable database initialization performed by Spring

rabbitmq:
host: localhost
port: 5672
username: guest
password: guest

weather:
api:
url: "http://api.weatherapi.com/v1/current.json?key=${WEATHER_API_KEY}&q={city}&aqi=yes"

0 comments on commit ccab3d4

Please sign in to comment.