test commit push #43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CD | |
| # main 브랜치에 push 될 때만 실행 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| # 1단계: 빌드 | |
| build: | |
| runs-on: self-hosted # self-hosted runner에서 실행 | |
| steps: | |
| # 1. 레포지토리 체크아웃 | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GIT_ACTION_TOKEN }} | |
| submodules: true # 서브모듈 포함 체크아웃 | |
| # 2. 서브모듈 초기화 | |
| - name: Update submodule | |
| run: git submodule update --init --recursive | |
| # 3. JDK 21 설정 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| # 4. gradlew에 실행 권한 부여 | |
| - name: Grant execute permission for Gradlew | |
| run: chmod +x gradlew | |
| # 5. Gradle로 빌드 (bootJar 생성) | |
| - name: Build with Gradle | |
| run: | | |
| ./gradlew clean bootjar -Pprofile=dev | |
| # 6. Docker Hub 로그인 | |
| - name: Log in to Docker Hub | |
| run: | | |
| echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
| # 7. Docker 이미지 빌드 및 Docker Hub로 push | |
| - name: Docker build & push | |
| run: | | |
| docker buildx build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} --push . | |
| # 2단계: 배포 | |
| deploy: | |
| runs-on: self-hosted | |
| needs: build # build job이 끝난 뒤 실행됨 | |
| steps: | |
| # 1. 레포지토리 재체크아웃 | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # 2. .env 파일 생성 | |
| - name: Create .env file | |
| run: | | |
| echo "${{ secrets.ENV_DEV }}" > .env | |
| # 3. 배포 디렉토리 설정 | |
| - name: Setup deployment directory | |
| run: | | |
| echo "Current user: $(whoami)" | |
| echo "Home directory: $HOME" | |
| mkdir -p /home/ec2-user/cesco-BackEnd | |
| cp docker-compose.yml /home/ec2-user/cesco-BackEnd/ | |
| cp .env /home/ec2-user/cesco-BackEnd/ | |
| # 4. Docker 배포 실행 | |
| - name: Deploy with Docker | |
| run: | | |
| cd /home/ec2-user/cesco-BackEnd | |
| docker compose down | |
| docker compose pull | |
| docker compose up -d --build |