-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (65 loc) · 2.32 KB
/
github-actions-rentify-api.yml
File metadata and controls
79 lines (65 loc) · 2.32 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
name: Workflow rentify-api
run-name: run-rentify-api [ ${{ github.actor }} ]
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v6
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
java-version: '21'
distribution: 'corretto'
cache: 'gradle'
- name: chmod Gradle
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build -x test
- name: Run Test
run: ./gradlew test
- name: Login to Docker Hub
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push Docker Image
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/universal-device-rental:latest
- name: Copy files to GCP
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: appleboy/scp-action@v1
with:
host: ${{ secrets.GCP_HOST }}
username: ${{ secrets.GCP_USERNAME }}
key: ${{ secrets.GCP_SSH_KEY }}
source: "docker-compose.yml,monitoring/**"
target: "/home/${{ secrets.GCP_USERNAME }}/ecommerce-project/infra"
- name: Deploy to GCP
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: appleboy/ssh-action@v1.2.4
with:
host: ${{ secrets.GCP_HOST }}
username: ${{ secrets.GCP_USERNAME }}
key: ${{ secrets.GCP_SSH_KEY }}
script: |
sudo mkdir -p /home/${{ secrets.GCP_USERNAME }}/ecommerce-project/infra
cd /home/${{ secrets.GCP_USERNAME }}/ecommerce-project/infra
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/universal-device-rental:latest
sudo docker compose down
sudo docker compose up -d
sudo docker image prune -f