Skip to content

Commit

Permalink
Create gradle.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
JoongHyun-Kim authored Mar 19, 2024
1 parent 7a1069d commit 04a60fd
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Deploy

on:
push:
branches: [ "main" ]
pull_request:
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'

# create application.yml
- name: create application.yml
run: |
mkdir ./src/main/resources
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION_FILE }}" > ./application.yml
shell: bash

# grant permisson
- name: Grant permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle Wrapper
run: ./gradlew build -x test

# docker
- name: Docker hub login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Docker image build
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/haemo .
- name: Docker Hub push
run: docker push ${{ secrets.DOCKER_USERNAME }}/haemo

# deploy
- name: Deploy to Instance
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.AWS_USERNAME }}
key: ${{ secrets.AWS_PRIVATEKEY }}
script: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker pull ${{ secrets.DOCKER_USERNAME }}/haemo
docker stop $(docker ps -qa)
docker run -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/haemo
docker rm $(docker ps --filter 'status=exited' -qa)
docker image prune -f

0 comments on commit 04a60fd

Please sign in to comment.