-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (92 loc) · 2.72 KB
/
Copy pathbackend-ci-cd.yml
File metadata and controls
106 lines (92 loc) · 2.72 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: Backend CI/CD
on:
push:
branches:
- main
- development
- feature/**
- bugfix/**
- release/**
paths:
- 'rentplace/**'
pull_request:
branches:
- main
- development
- feature/**
- bugfix/**
- release/**
paths:
- 'rentplace/**'
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Fix gradlew permissions
working-directory: rentplace
run: chmod +x gradlew
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
working-directory: rentplace
- name: Build
working-directory: rentplace
run: ./gradlew build --no-daemon
- name: Test
working-directory: rentplace
run: ./gradlew test
build-and-push-docker-image:
runs-on: ubuntu-latest
needs: build-and-test
if: github.ref == 'refs/heads/development' || github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Setup Java 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Fix gradlew permissions
working-directory: rentplace
run: chmod +x gradlew
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
working-directory: rentplace
- name: Build
working-directory: rentplace
run: ./gradlew build --no-daemon
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build Docker image
working-directory: rentplace
run: docker build -t ${{ secrets.DOCKERHUB_BACKEND_IMAGE_NAME }} -f Dockerfile .
- name: Push Docker Image
working-directory: rentplace
run: docker push ${{ secrets.DOCKERHUB_BACKEND_IMAGE_NAME }}
deploy:
runs-on: ubuntu-latest
needs: build-and-push-docker-image
steps:
- name: SSH Execute Commands
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd Deploy
docker compose down
docker rm $(docker ps -a -q)
docker pull ${{ secrets.DOCKERHUB_BACKEND_IMAGE_NAME }}
docker compose up -d --build