Merge pull request #66 from Memento-Makers/feature/diary #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to EC2 | |
on: | |
pull_request: | |
branches: ["stage"] | |
push: | |
branches: ["stage"] | |
jobs: | |
build_deploy_stage: | |
name: Build, Deploy to EC2 | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: "./emopic" | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 11 | |
# 캐시 추가 | |
- name: Cache Gradle packages | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
# gradlew 권한 변경 | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
## gradle build | |
- name: Clean with Gradle | |
run: ./gradlew clean | |
## gradle build | |
- name: Build with Gradle | |
run: ./gradlew bootJar | |
# gradle 캐쉬 제거 | |
- name: Cleanup Gradle Cache | |
# Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. | |
# Restoring these files from a GitHub Actions cache might cause problems for future builds. | |
if: ${{ always() }} | |
run: | | |
rm -f ~/.gradle/caches/modules-2/modules-2.lock | |
rm -f ~/.gradle/caches/modules-2/gc.properties | |
## 서버 이미지 빌드 및 도커허브에 push | |
- name: server docker build and push | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -t ${{ secrets.DOCKER_STAGE_IMAGE_NAME}} . | |
docker push ${{ secrets.DOCKER_STAGE_IMAGE_NAME }} | |
## docker 이미지 다운로드 및 docker compose 명령어를 이용해 컨테아너 살행 | |
- name: executing remote ssh commands using password | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.STAGE_HOST }} | |
username: ${{ secrets.STAGE_USERNAME }} | |
key: ${{ secrets.STAGE_SERVER_KEY }} | |
script: | | |
sudo docker rm -f $(docker ps -qa) | |
sudo docker pull ${{ secrets.DOCKER_STAGE_IMAGE_NAME }} | |
docker compose up -d | |
docker image prune -f |