Update application.yml code #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 to Docker Hub | |
on: | |
push: | |
branches: | |
- main | |
env: | |
DOCKER_IMAGE_NAME: back-apigateway | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN}} | |
EC2_HOST: ${{ secrets.EC2_HOST }} | |
EC2_SSH_USER: ${{ secrets.EC2_SSH_USER }} | |
EC2_SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_PRIVATE_KEY }} | |
jobs: | |
build-and-push-docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 8 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '8' | |
distribution: 'temurin' | |
- name: Change gradlew permissions | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
run: ./gradlew build | |
# 도커 이미지 빌드 | |
- name: Build the Docker image | |
run: docker build . --file Dockerfile --tag ${{ env.DOCKER_IMAGE_NAME }}:latest | |
# 도커 허브 로그인 | |
- name: Login to Docker Hub using Access Token | |
run: echo "${{ env.DOCKER_HUB_TOKEN }}" | docker login -u ${{ env.DOCKER_USERNAME }} --password-stdin | |
# 도커 태그 설정 | |
- name : Set the tag of Docker image | |
run: docker tag ${{ env.DOCKER_IMAGE_NAME }} ${{ env.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGE_NAME }} | |
# 도커 이미지 업로드 | |
- name: Push the Docker image | |
run: docker push ${{ env.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGE_NAME }} | |
# 아마존 EC2 로 배포 (임시용 / 이후 쿠버네티스 적용 예정) | |
- name: Deploy to EC2 | |
if: success() | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.EC2_HOST }} | |
username: ${{ env.EC2_SSH_USER }} | |
key: ${{ env.EC2_SSH_PRIVATE_KEY }} | |
script: | | |
git clone https://github.com/DB-Inc-Capstone/.github.git | |
cd .github | |
git pull origin main | |
sudo docker-compose down | |
sudo docker-compose pull | |
sudo docker-compose up -d |