Skip to content

chore: cd.yml 수정 #12

chore: cd.yml 수정

chore: cd.yml 수정 #12

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 deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.WAS_HOST }}
username: ${{ secrets.WAS_USERNAME }}
port: ${{ secrets.WAS_PORT }}
key: ${{ secrets.WAS_KEY }}
script: |
cd /home/ubuntu/
sudo chown ubuntu:ubuntu .env
sudo chown ubuntu:ubuntu docker-compose.yml
sudo chmod 644 .env docker-compose.yml
sudo touch .env
sudo echo "${{ secrets.ENV_VARS }}" > .env
sudo touch docker-compose.yml
sudo echo "docker-compose.yml" | > docker-compose.yml
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-compose -f docker-compose.yml --env-file ./.env up -d
sudo docker image prune -f