Skip to content

Commit

Permalink
chore: ec2 docker 배포
Browse files Browse the repository at this point in the history
  • Loading branch information
osoohynn committed Dec 2, 2024
1 parent 9d359ff commit 7f3c74f
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI/CD using github actions & docker

on:
push:
branches: [ "main" ] # 해당 branch에 푸쉬 발생 시 업데이트

permissions:
contents: read

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: Gradle Caching # 속도 최적화
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle
run: ./gradlew bootJar

- name: Docker build & push to prod
run: |
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
sudo docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} .
sudo docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}
- name: Deploy
uses: appleboy/ssh-action@master
id: deploy
with:
host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }} # EC2 private key
envs: GITHUB_SHA
script: |
sudo docker rm -f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}
sudo docker run --env-file .env -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}
# sudo docker-compose up -d
# sudo docker image prune -f

0 comments on commit 7f3c74f

Please sign in to comment.