[BugFix] - ec2 응답 시 날짜 버그 수정했습니다. #114
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
# workflow 이름 | |
name: 백엔드 개발서버 배포 | |
# event trigger | |
on: | |
# 해당 브랜치로 push 될 때 실행됩니다. | |
push: | |
branches: | |
- develop | |
permissions: | |
contents: read | |
jobs: | |
build: | |
if: github.repository == 'COFLLL/CoverFlow-BE' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
## JDK Setting | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
## application.yml 파일을 생성합니다. | |
- name: make application.yml | |
run: | | |
cd ./src/main/resources | |
touch ./application.yml | |
echo "${{ secrets.APPLICATION }}" > ./application.yml | |
shell: bash | |
## application-dev.yml 파일을 생성합니다. | |
- name: make application-dev.yml | |
if: contains(github.ref, 'develop') | |
run: | | |
cd ./src/main/resources | |
touch ./application-dev.yml | |
echo "${{ secrets.APPLICATION_DEV }}" > ./application-dev.yml | |
shell: bash | |
## gradlew 실행 권한 부여 | |
- name: Grant execute permisson for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle (without Test) | |
run: ./gradlew clean build -x test --stacktrace | |
########## CD(Continuous Delivery/Deployment) ########## | |
## docker hub에 로그인하고 cofl-dev에 이미지를 빌드 & push 합니다. | |
- name: Docker build & push to dev repo | |
if: contains(github.ref, 'develop') | |
run: | | |
docker login -u "${{ secrets.DOCKER_USERNAME_DEV }}" -p "${{ secrets.DOCKER_PASSWORD_DEV }}" | |
docker build -f Dockerfile-dev -t "${{ secrets.DOCKER_USERNAME_DEV }}"/cofl-dev . | |
docker push "${{ secrets.DOCKER_USERNAME_DEV }}"/cofl-dev | |
## AWS EC2 인스턴스에 접속하고 develop을 배포합니다. | |
- name: Deploy to Dev | |
uses: appleboy/ssh-action@master | |
id: deploy-dev | |
if: contains(github.ref, 'develop') | |
with: | |
host: ${{ secrets.HOST_DEV }} # EC2 인스턴스 퍼블릭 DNS | |
username: ${{ secrets.USERNAME }} # 인스턴스를 시작하는 데 사용되는 AMI에 정의된 사용자 이름을 입력합니다. | |
key: ${{ secrets.PRIVATE_KEY }} # 키 페어의 pem 키 | |
# sudo docker-compose up -d | |
script: | | |
sudo docker login -u "${{ secrets.DOCKER_USERNAME_DEV }}" -p "${{ secrets.DOCKER_PASSWORD_DEV }}" | |
sudo docker stop cofl_spring_boot_dev | |
sudo docker rm -f $(sudo docker ps --filter 'status=exited' -a -q) | |
sudo docker pull "${{ secrets.DOCKER_USERNAME_DEV }}"/cofl-dev | |
sudo docker run --name cofl_spring_boot_dev -d --log-driver=syslog -p 8081:8081 -e SPRING_PROFILES_ACTIVE=dev "${{ secrets.DOCKER_USERNAME_DEV }}"/cofl-dev | |
sudo docker image prune -a -f |