Skip to content

Commit 65c7089

Browse files
authored
Create maven.yml
1 parent a60193e commit 65c7089

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

.github/workflows/maven.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Build and Deploy to Ubuntu Server
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up JDK 17
17+
uses: actions/setup-java@v3
18+
with:
19+
java-version: "17"
20+
distribution: "temurin"
21+
22+
- name: Prepare application.properties
23+
run: |
24+
mkdir config
25+
echo "${{ secrets.NODE_APP_PROPERTIES }}" > config/application.properties
26+
- name: Build with Maven
27+
run: mvn clean package -DskipTests
28+
29+
- name: Check if jar file exists
30+
run: |
31+
echo "Contents of target directory:"
32+
ls -la target
33+
if [ ! -f target/NodeBackend-0.0.1-SNAPSHOT.jar ]; then
34+
echo "Error: Jar file not found!!"
35+
exit 1
36+
fi
37+
- name: Docker build and push
38+
run: |
39+
docker login -u ${{ secrets.NODE_DOCKER_REPO }} -p ${{ secrets.NODE_DOCKER_KEY }}
40+
docker build -t ${{ secrets.NODE_DOCKER_REPO }}/node-backend:latest .
41+
docker push ${{ secrets.NODE_DOCKER_REPO }}/node-backend
42+
deploy:
43+
runs-on: ubuntu-latest
44+
needs: build
45+
46+
steps:
47+
- name: Deploy to Ubuntu Server
48+
uses: appleboy/ssh-action@master
49+
with:
50+
host: ${{ secrets.NODE_HOST }}
51+
username: ${{ secrets.NODE_USERNAME }}
52+
key: ${{ secrets.NODE_SSH_PRIVATE_KEY }}
53+
script: |
54+
sudo docker network create node || true
55+
sudo docker stop node-backend || true
56+
sudo docker rm node-backend || true
57+
sudo docker pull ${{ secrets.NODE_DOCKER_REPO }}/node-backend:latest
58+
sudo docker run -d -p 8080:8080 --net node --name node-backend ${{ secrets.NODE_DOCKER_REPO }}/node-backend:latest

0 commit comments

Comments
 (0)