Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/hajithon/chat-04-server
Browse files Browse the repository at this point in the history
…into feature/book-topic
  • Loading branch information
pingowl committed Jul 27, 2024
2 parents 1428451 + acfe9bc commit be95669
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Java CI with Gradle

# 동작 조건 설정 : main 브랜치에 push가 발생할 경우 동작한다.
on:
push:
branches: [ "develop" ]

permissions:
contents: read
id-token: write

jobs:
# Spring Boot 애플리케이션을 빌드하여 도커허브에 푸시하는 과정
build-docker-image:
runs-on: ubuntu-22.04

steps:
- name: checkout
uses: actions/checkout@v4

# 1. Java 세팅
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'


- name: make application.properties
run: |
cd ./src/main/resources
touch ./application.properties
# GitHub-Actions 에서 설정한 값을 application.properties 파일에 쓰기
echo "${{ secrets.APPLICATION_PROPERTIES }}" >> ./application.properties
shell: bash


# 2. Spring Boot 애플리케이션 빌드
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew clean bootJar -x test
# 3. Docker 이미지 빌드
- name: docker image build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/mychat .

# 4. DockerHub 로그인
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

# 5. Docker Hub 이미지 푸시
- name: docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/mychat


# Deploy Images with Docker compose
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
env:
APP: "mychat"
COMPOSE: "/home/ubuntu/compose/docker-compose.yml"
with:
username: ubuntu
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
port: ${{ secrets.EC2_SSH_PORT }}
envs: APP, COMPOSE
script_stop: true
script: |
sudo docker-compose -f $COMPOSE down
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/mychat
sudo docker-compose -f $COMPOSE up -d

0 comments on commit be95669

Please sign in to comment.