HOTFIX: 삭제조건 변경 #11
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 Docker Image | |
on: | |
push: | |
branches: ["main"] | |
jobs: | |
build-docker-image: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Convert line endings to Unix | |
run: | | |
sudo apt-get install dos2unix | |
dos2unix ./gradlew | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
run: ./gradlew clean bootJar | |
- name: Docker image build | |
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/cogoserver . | |
- name: Docker login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Docker Hub push | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/cogoserver | |
run-docker-image-on-ec2: | |
needs: build-docker-image | |
runs-on: self-hosted | |
steps: | |
- name: Docker pull | |
run: sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/cogoserver | |
- name: Docker stop container | |
run: sudo docker stop cogo 2>/dev/null || true | |
- name: Docker remove container | |
run: sudo docker rm cogo 2>/dev/null || true | |
- name: Docker run new container | |
run: | | |
sudo docker run --name cogo --rm -d -p 8080:8080 \ | |
-e DB_URL=${{ secrets.DB_URL }} \ | |
-e DB_NAME=${{ secrets.DB_NAME }} \ | |
-e DB_USERNAME=${{ secrets.DB_USERNAME }} \ | |
-e DB_PW=${{ secrets.DB_PW }} \ | |
-e MAIL_SENDER=${{ secrets.MAIL_SENDER }} \ | |
-e MAIL_PW=${{ secrets.MAIL_PW }} \ | |
-e JWT_SECRET=${{ secrets.JWT_SECRET }} \ | |
-e NAVER_ID=${{ secrets.NAVER_ID }} \ | |
-e NAVER_SECRET=${{ secrets.NAVER_SECRET }} \ | |
-e NAVER_REDIRECT=${{ secrets.NAVER_REDIRECT }} \ | |
-e GOOGLE_ID=${{ secrets.GOOGLE_ID }} \ | |
-e GOOGLE_SECRET=${{ secrets.GOOGLE_SECRET }} \ | |
-e GOOGLE_REDIRECT=${{ secrets.GOOGLE_REDIRECT }} \ | |
-e KAKAO_ID=${{ secrets.KAKAO_ID }} \ | |
-e KAKAO_SECRET=${{ secrets.KAKAO_SECRET }} \ | |
-e KAKAO_REDIRECT=${{ secrets.KAKAO_REDIRECT }} \ | |
-e BUCKET_NAME=${{ secrets.BUCKET_NAME }} \ | |
-e S3_ACCESS=${{ secrets.S3_ACCESS }} \ | |
-e S3_SECRET=${{ secrets.S3_SECRET }} \ | |
-e REDIS_HOST=${{ secrets.REDIS_HOST }} \ | |
-e REDIS_PORT=${{ secrets.REDIS_PORT }} \ | |
-e SMS_KEY=${{ secrets.SMS_KEY }} \ | |
-e SMS_SECRET=${{ secrets.SMS_SECRET }} \ | |
-e SMS_FROM=${{ secrets.SMS_FROM }} \ | |
-e SQS_NAME=${{ secrets.SQS_NAME }} \ | |
${{ secrets.DOCKERHUB_USERNAME }}/cogoserver | |
sleep 5 | |
sudo docker ps -a | |
- name: Check Docker logs | |
run: sudo docker logs cogo || true | |
- name: Delete old docker image | |
run: sudo docker system prune -f |