Skip to content

Commit 2eaf09f

Browse files
committed
fix ci/cd
1 parent 6927571 commit 2eaf09f

File tree

10 files changed

+563
-29
lines changed

10 files changed

+563
-29
lines changed

.github/workflows/github-actions.yml

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Java CI/CD with Maven
1+
name: Java CI/CD with Docker Compose
22

33
on:
44
push:
@@ -56,27 +56,36 @@ jobs:
5656
uses: actions/checkout@v2
5757

5858
- name: Set up SSH
59-
uses: webfactory/ssh-agent@v0.5.3
59+
uses: webfactory/ssh-agent@v0.8.0
6060
with:
6161
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
6262

63-
- name: Add remote host to known_hosts
64-
run: ssh-keyscan -H 5.39.249.253 >> ~/.ssh/known_hosts
63+
- name: Add known hosts
64+
run: |
65+
mkdir -p ~/.ssh
66+
echo "${{ secrets.SERVER_IP }} $(ssh-keyscan -H ${{ secrets.SERVER_IP }} 2>/dev/null)" >> ~/.ssh/known_hosts
6567
66-
- name: Download build artifacts
67-
uses: actions/download-artifact@v3
68-
with:
69-
name: build-artifacts
70-
path: target/
71-
72-
- name: List files before SCP
73-
run: ls -la target/
74-
75-
- name: Copy files via SCP
76-
run: scp -r target/ [email protected]:/root
77-
78-
- name: Run deployment script
68+
- name: Deploy to server
7969
env:
8070
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
8171
GPT_TOKEN: ${{ secrets.GPT_TOKEN }}
82-
run: ssh [email protected] 'BOT_TOKEN=${{ secrets.BOT_TOKEN }} GPT_TOKEN=${{ secrets.GPT_TOKEN }} bash -s' < ./deploy.sh
72+
SERVER_IP: ${{ secrets.SERVER_IP }}
73+
SERVER_USER: ${{ secrets.SERVER_USER }}
74+
run: |
75+
ssh $SERVER_USER@$SERVER_IP << 'EOF'
76+
if [ -d "Automating-route-selection" ]; then
77+
cd Automating-route-selection
78+
git pull origin main
79+
else
80+
git clone https://github.com/Dema-koder/Automating-route-selection.git
81+
cd Automating-route-selection
82+
fi
83+
84+
# Создаем .env файл с секретами
85+
echo "BOT_TOKEN=$BOT_TOKEN" > .env
86+
echo "GPT_TOKEN=$GPT_TOKEN" >> .env
87+
88+
# Запускаем приложение
89+
docker-compose down
90+
docker-compose up -d --build
91+
EOF

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ build/
3535
.vscode/
3636

3737
### Mac OS ###
38-
.DS_Store
38+
.DS_Store
39+
40+
.env
41+
logback-test.xml
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
wrapperVersion=3.3.2
18+
distributionType=only-script
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM eclipse-temurin:22-jdk as builder
2+
WORKDIR /app
3+
4+
COPY . .
5+
6+
RUN chmod +x mvnw && \
7+
./mvnw clean package -DskipTests
8+
9+
FROM eclipse-temurin:22-jre-alpine
10+
WORKDIR /app
11+
12+
COPY --from=builder /app/target/*.jar app.jar
13+
14+
EXPOSE 8080
15+
ENTRYPOINT ["java", "-jar", "app.jar"]

docker-compose.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: '3.8'
2+
3+
services:
4+
postgres:
5+
image: postgres:15
6+
container_name: postgres
7+
environment:
8+
POSTGRES_USER: app_user
9+
POSTGRES_PASSWORD: secretpass
10+
POSTGRES_DB: app_db
11+
ports:
12+
- "5433:5432"
13+
volumes:
14+
- postgres_data:/var/lib/postgresql/data
15+
healthcheck:
16+
test: ["CMD-SHELL", "pg_isready -U app_user -d app_db"]
17+
interval: 5s
18+
timeout: 5s
19+
retries: 5
20+
21+
app:
22+
build:
23+
context: .
24+
dockerfile: Dockerfile
25+
container_name: app
26+
depends_on:
27+
postgres:
28+
condition: service_healthy
29+
env_file:
30+
- .env
31+
environment:
32+
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/app_db
33+
SPRING_DATASOURCE_USERNAME: app_user
34+
SPRING_DATASOURCE_PASSWORD: secretpass
35+
SPRING_JPA_HIBERNATE_DDL-AUTO: update
36+
BOT_TOKEN: ${BOT_TOKEN}
37+
GPT_TOKEN: ${GPT_TOKEN}
38+
ports:
39+
- "8080:8080"
40+
restart: unless-stopped
41+
42+
volumes:
43+
postgres_data:

0 commit comments

Comments
 (0)