Skip to content

Commit

Permalink
Create gradle.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmondBreez3 authored Nov 14, 2023
1 parent a9619f9 commit 8776821
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Java CI with Gradle and Redis

on:
push:
branches:
- main

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Set up NTP
run: |
sudo apt-get update
sudo apt-get install -y ntp
sudo service ntp start
- name: make application-db.yml
run: |
cd ./src/main/resources
touch ./application-db.yml
echo "${{ secrets.DB_PROPERTIES }}" > ./application-db.yml
shell: bash

- name: make application-real.yml
run: |
cd ./src/main/resources
touch ./application-real.yml
echo "${{ secrets.PROPERTIES_PROD }}" > ./application-real.yml
shell: bash

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew build -x test

- name: Start Redis Container
run: |
docker run -d -p 6379:6379 --name my-redis redis:latest
shell: bash

- name: Docker build
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t app -f DockerFile .
docker tag app ${{ secrets.DOCKER_USERNAME }}/bapmate:latest
docker push ${{ secrets.DOCKER_USERNAME }}/bapmate:latest
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }} # EC2 인스턴스 퍼블릭 DNS
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }} # pem 키
# 도커 작업
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/bapmate:latest
docker stop $(docker ps -a -q)
docker run -d --log-driver=syslog -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/bapmate:latest
docker rm $(docker ps --filter 'status=exited' -a -q)
docker image prune -a -f

0 comments on commit 8776821

Please sign in to comment.