fix : target에 맞춰서 수정 #47
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: AWS EC2 Deploy | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
# ubuntu 버전 지정 | |
runs-on: ubuntu-22.04 | |
env: | |
working-directory: ./server-springboot | |
steps: | |
# Checkout 진행 | |
- uses: actions/checkout@v3 | |
# JDK 17 설치 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
# Gradle 캐싱 | |
- 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: Make application.properties | |
run: | | |
cd ./src/main/resources | |
touch ./application.yml | |
echo "${{ secrets.YML }}" > ./application.yml | |
shell: bash | |
- name: Build with Gradle | |
run: | | |
chmod +x ./gradlew | |
./gradlew clean build -x test | |
# Gradle BootJar | |
- name: BootJar with Gradle | |
run: ./gradlew clean bootJar -Dspring.profiles.active=release | |
# Docker Image Push | |
- name: Docker Image push | |
run: | | |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
docker build -t ${{ secrets.DOCKERHUB_USERNAME}}/${{ secrets.DOCKERHUB_REPOSITORY}} . | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} | |
# EC2 depoly | |
- name: EC2 depoly | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_SERVER_IP }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
script: | | |
sudo docker ps | |
sudo docker rm -f $(docker ps -qa) | |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} | |
sudo docker run -d -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} | |
docker system prune -f | |
# sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} | |
# docker-compose up -d | |
# docker image prune -f | |
# sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
# chmod +x /usr/local/bin/docker-compose | |
# sudo docker-compose stop ${{ secrets.DOCKER_SERVICE_NAME }} | |
# sudo docker-compose rm -f ${{ secrets.DOCKER_SERVICE_NAME }} | |
# sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} | |
# sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} ${{ secrets.DOCKER_IMAGE_NAME }} | |
# sudo docker-compose up -d |