feat: gradle 파일 추가 #6
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: Build, Push Docker Image and Deploy to EC2 | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Create application-secret.yml | |
run: | | |
pwd | |
touch src/main/resources/application-secret.yml | |
echo "${{ secrets.APPLICATION_SECRET_YML }}" >> src/main/resources/profiles/application-secret.yml | |
cat src/main/resources/profiles/application-secret.yml | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
- name: Gradle build | |
run: chmod +x ./gradlew && ./gradlew build | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/m-log-api:ver_1 | |
deploy: | |
needs: build_and_push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Deploy to EC2 | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USER }} | |
key: ${{ secrets.EC2_KEY }} | |
script: | | |
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/m-log-api:ver_1 | |
/home/ec2-user/deploy.sh |