Skip to content

Commit

Permalink
Merge pull request #36 from Sopo2023/feat/#1
Browse files Browse the repository at this point in the history
Feat/#1
  • Loading branch information
GayeongKimm authored Jul 28, 2024
2 parents 2fd043f + e214427 commit 4f29bfb
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI/CD using GitHub Actions & Docker
name: CI/CD using github actions & docker

on:
push:
Expand All @@ -15,49 +15,56 @@ jobs:
java-version: '17'
distribution: 'temurin'

- name: make application.yml
run: |
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION }}" > ./application.yml
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: set chmod
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew bootJar
# Gradle 빌드 후 JAR 파일 생성 확인
# 필요에 따라 `ls -l build/libs` 등을 추가하여 파일 존재 확인

- name: Build Docker image and push
- name: Docker build
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_USERNAME }}/sopo_v2 .
docker push ${{ secrets.DOCKER_USERNAME }}/sopo_v2
docker build -t alimo . # Dockerfile 경로 수정
docker tag alimo ${{ secrets.DOCKER_USERNAME }}/alimo:latest
docker push ${{ secrets.DOCKER_USERNAME }}/alimo:latest
- name: Deploy to Production
- name: Deploy with SSH
if: github.ref == 'refs/heads/main'
uses: appleboy/ssh-action@master
id: deploy-prod

with:
host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }} # EC2 private key
key: ${{ secrets.PRIVATE_KEY }} # pem 키
port: ${{ secrets.PORT }} # ssh port (22)
envs: GITHUB_SHA
script: |
# EC2에서 기존 Docker 컨테이너 및 이미지 정리
docker stop sopo_v2 || true
docker rm sopo_v2 || true
docker rmi ${{ secrets.DOCKER_USERNAME }}/sopo_v2 || true
docker pull ${{ secrets.DOCKER_USERNAME }}/sopo_v2
docker run -d -p 8080:8080 --name sopo_v2 ${{ secrets.DOCKER_USERNAME }}/sopo_v2
# Redis 서버 시작
sudo chkconfig --add redis-server
sudo chkconfig --level 345 redis-server on
sudo service redis-server start
# Docker Compose 파일이 있는 디렉토리로 이동
sudo service reids-server start
mkdir -p /home/ubuntu/app
cd /home/ubuntu/app
# docker-compose.yml 파일을 생성하거나 덮어쓰기
echo "${{ secrets.DOCKER_COMPOSE }}" > docker-compose.yml
# Docker Compose 명령어 실행
docker-compose pull
docker-compose up -d
# 사용하지 않는 Docker 데이터 정리 (선택 사항)
docker system prune -f

docker system prune -f

0 comments on commit 4f29bfb

Please sign in to comment.