Skip to content

chore: Dockerfile 수정 #3

chore: Dockerfile 수정

chore: Dockerfile 수정 #3

Workflow file for this run

name: Build, Push Docker Image and Deploy to EC2 for Merge
on:
push:
branches: [ "dev" ]
pull_request:
types: [ "closed" ]
branches: [ "dev" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permisson for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build -x test
- name: Docker Hub build & push
run: |
sudo docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PWD }}
sudo docker build -t ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }} .
sudo docker push ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}:latest
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: SSH into EC2 and create .env
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.WAS_HOST }}
username: ${{ secrets.WAS_USERNAME }}
port: ${{ secrets.WAS_PORT }}
key: ${{ secrets.WAS_KEY }}
script: |
echo "${{ secrets.ENV_VARS }}" > /InNOut-Backend/.env
- name: SSH into EC2 and deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.WAS_HOST }}
username: ${{ secrets.WAS_USERNAME }}
port: ${{ secrets.WAS_PORT }}
key: ${{ secrets.WAS_KEY }}
script: |
sudo docker ps
sudo docker rm -f $(sudo docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}:latest
sudo docker run -d -p 9000:9000 ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}:latest
sudo docker image prune -f