feat: EFUB week11 ์ธ์ #1
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 Amazon EC2 | |
on: | |
push: | |
branches: [ "week11" ] | |
jobs: | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'zulu' | |
- name: make application.yml | |
run: | | |
mkdir ./blog/src/main/resources | |
cd ./blog/src/main/resources | |
touch ./application.yml | |
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml | |
- name: Gradle Caching | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Build with Gradle | |
run: | | |
cd ./blog | |
chmod +x ./gradlew | |
./gradlew build -x test | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
# Docker ์ด๋ฏธ์ง ๋น๋ ๋ฐ ํธ์ | |
- name: Docker build & push | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./blog | |
file: ./blog/Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKER_REPO }}:latest | |
# ์๋ฒ์ ๋ฐฐํฌ | |
- name: Deploy to Server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
envs: GITHUB_SHA | |
script: | | |
sudo docker rm -f $(sudo docker ps -qa) | |
sudo docker pull ${{ secrets.DOCKER_REPO }}:lastest | |
sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_REPO }}:latest | |
sudo docker image prune -f |