-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (76 loc) · 2.39 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#file: noinspection YAMLSchemaValidation
name: ds-deliver
on:
push:
branches: [ "main", "CI-CD" ]
pull_request:
branches: [ "main" ]
env:
JAVA_VERSION: 21
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.3.0
- uses: actions/setup-java@v3.10.0
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: temurin
- name: Build and Test with Maven
run: |
./mvnw clean verify -Dspring.profiles.active=test
- name: Check Test Status
id: check-test-status
run: |
if grep -q "BUILD FAILURE" target/surefire-reports/*.txt; then
echo "Tests failed."
exit 1
else
echo "Tests passed."
fi
- name: Build artifact
if: steps.check-test-status.outcome == 'success'
run: |
./mvnw --no-transfer-progress clean package -DskipTests -P prod
- name: Docker Login
if: steps.check-test-status.outcome == 'success'
uses: docker/login-action@v2.1.0
with:
username: lucianobrum
password: ${{ secrets.PWD_DOCKER_HUB }}
- name: Build and push Docker images
if: steps.check-test-status.outcome == 'success'
uses: docker/build-push-action@v4.0.0
with:
context: .
file: ./Dockerfile
push: true
tags: lucianobrum/dsdeliver:${{github.ref_name}}, lucianobrum/dsdeliver:latest
- uses: actions/checkout@master
- name: copy file via ssh password
if: steps.check-test-status.outcome == 'success'
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
source: "./docker-compose.yml"
target: "/home/ubuntu/dsdeliver"
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: deploy aws ec2
uses: appleboy/ssh-action@v0.1.7
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
script: |
cd /home/ubuntu/dsdeliver
sudo docker compose down
sudo docker system prune -a -f
sudo docker compose build
sudo docker compose up -d