Skip to content

run-rentify-api [ Dalguring ] #176

run-rentify-api [ Dalguring ]

run-rentify-api [ Dalguring ] #176

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