Skip to content

Commit

Permalink
[FEAT] Create gradle.yml (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
sangminee authored Jan 30, 2024
1 parent cb5d7db commit b9af6c4
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Workflow 이름
name: Spring Boot & Gradle CI/CD

on:
push:
branches: [ "feat/88-github-action" ]
# pull_request:
# branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

# JDK 17 설치
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

# github secret 환경변수로 적어둔 APPLICATION_YML으로 application.yml파일을 생성합니다.
# 환경변수가 지나치게 많아짐을 방지하기 위해 APPLICATION_YML 변수를 만들었습니다.
- name: make application.yml
run: |
cd ./src/main/resources/secret
touch ./application-aws.yml
echo "${{ secrets.APPLICATION_AWS_YML }}" >> ./application-aws.yml
touch ./application-dev-db.yml
echo "${{ secrets.APPLICATION_DEV_YML }}" >> ./application-dev-db.yml
touch ./application-jwt.yml
echo "${{ secrets.APPLICATION_JWT_YML }}" >> ./application-local-jwt.yml
shell: bash

# gradlew에 실행 권한을 부여합니다.
- name: Grant execute permisson for gradlew
run: chmod +x gradlew

# test는 CI 과정에서 수행되므로 여기서는 `-x`로 테스트를 생략했습니다.
# `--stacktrace`로 더 자세한 로그가 출력되게 해줍니다.
- name: Build with Gradle (without Test)
run: ./gradlew clean build -x test --stacktrace

# docker hub에 로그인하고 이미지를 빌드합니다. 이후에 push를 진행합니다.
# docker_username을 적지 않으면 push 시에 요청이 거부될 수 있습니다.
- name: Docker Hub build & push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} .
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}
# EC2에 접속하고 배포합니다.
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}
port: ${{ secrets.EC2_SSH_PORT }}

script: |
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
sudo docker rm -f $(sudo docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}
sudo docker-compose up -d
sudo docker image prune -f

0 comments on commit b9af6c4

Please sign in to comment.