Skip to content

Update gradle-publish.yml #6

Update gradle-publish.yml

Update gradle-publish.yml #6

name: CI/CD using github actions & docker
on:
push:
branches: [ "main" ] # 해당 branch에 푸쉬 발생 시 업데이트
pull_request:
branches: [ "main" ]
jobs:
CI-CD:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'
- name: set chmod
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew :Dasom-api:build -x test --parallel
- name: Docker build & push to prod
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/dasom:latest .
docker push ${{ secrets.DOCKER_USERNAME }}/dasom:latest
- name: Deploy to prod
uses: appleboy/ssh-action@master
id: deploy-prod
with:
host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }} # EC2 private key
envs: GITHUB_SHA
script: |
docker stop dasom
docker rm dasom
docker rmi ${{ secrets.DOCKER_USERNAME }}/dasom:latest
docker pull ${{ secrets.DOCKER_USERNAME }}/dasom:latest
docker run -d -p 8080:8080 --name dasom ${{ secrets.DOCKER_USERNAME }}/dasom:latest