Skip to content

Merge branch 'dev' into test #158

Merge branch 'dev' into test

Merge branch 'dev' into test #158

name: Test Server Deploy to AWS EC2
on:
push:
branches:
- test
pull_request:
branches:
- test
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
# 저장소 체크아웃
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
env:
JAVA_TOOL_OPTIONS: "-Duser.timezone=Asia/Seoul"
- name: Create application.yml
run: |
mkdir -p ./src/main/resources
echo "${{ secrets.APPLICATION_YML }}" | base64 --decode > ./src/main/resources/application.yml
shell: bash
# gradlew 실행 권한 부여
- name: Grant permission for gradlew
run: chmod +x gradlew
# 프로젝트 빌드
- name: Build with Gradle Wrapper
run: ./gradlew build -x test
# docker hub 로그인
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# 스프링 부트 어플리케이션 docker 이미지 빌드 및 푸시
- name: Build and push Docker image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/kkm-test .
docker push ${{ secrets.DOCKER_USERNAME }}/kkm-test
# EC2 인스턴스에 배포
- name: Deploy to AWS EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
docker stop web || true
docker rm web || true
docker rmi ${{ secrets.DOCKER_USERNAME }}/kkm-test:latest || true # 이전 이미지를 삭제
docker volume prune -f # 사용되지 않는 볼륨 삭제
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker pull ${{ secrets.DOCKER_USERNAME }}/kkm-test:latest
docker run -d --name web --network my_network -p 80:8080 \
-e TZ=Asia/Seoul \
${{ secrets.DOCKER_USERNAME }}/kkm-test:latest