Skip to content

Commit

Permalink
✨ feat: CI/CD 자동 배포
Browse files Browse the repository at this point in the history
Giyhub Action으로 Ec2 자동배포를 구성했습니다.
  • Loading branch information
dlrjs2360 authored Dec 10, 2023
1 parent fdda1cd commit 09e3185
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# 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

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'

# yml 주입
- name: make ymls
run: |
cd ./src/main/resources
touch ./application-prod.yml
echo "${{ secrets.APPLICATION_PROD }}" > ./application-prod.yml
touch ./application-redis.yml
echo "${{ secrets.APPLICATION_REDIS }}" > ./application-redis.yml
touch ./application-mail.yml
echo "${{ secrets.APPLICATION_MAIL }}" > ./application-mail.yml
touch ./secrets.yml
echo "${{ secrets.SECRETS }}" > ./secrets.yml
touch ./application-s3.yml
echo "${{ secrets.APPLICATION_S3 }}" > ./application-s3.yml
# 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x gradlew

# 배포 전 테스트
- name: Build with Gradle
run: ./gradlew build -x test

# 도커 허브 푸쉬
- name: Docekr Build
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_USERNAME }}/hbc .
docker push ${{ secrets.DOCKER_USERNAME }}/hbc
# 도커 컨테이너 변경
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ec2-user
key: ${{ secrets.PRIVATE_KEY }} # pem 키
script: |
sudo docker rm $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/hbc
docker-compose up -d
sudo docker image prune -f

0 comments on commit 09e3185

Please sign in to comment.