feat: 여러 서버 인스턴스에서 실시간 마인드맵의 모든 사용자가 동일한 접속자 목록 Redis 저장 #10
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: Deploy to EC2 with Docker hub | |
| on: | |
| push: | |
| branches: | |
| - dev | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 소스코드 체크아웃 | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| # Gradle 실행 권한 부여 | |
| - name: Make gradlew executable | |
| run: chmod +x ./gradlew | |
| # Docker hub 로그인 | |
| - name: Log in to Docker Hub | |
| uses: docker/[email protected] | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| # Docker Buildx 설정 추가 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # Dockerfile을 사용 이미지 빌드 & 푸시 | |
| - name: Build and push Docker image | |
| uses: docker/[email protected] | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| tags: | | |
| ${{ secrets.DOCKER_USERNAME }}/gitdeun:latest | |
| ${{ secrets.DOCKER_USERNAME }}/gitdeun:${{ github.sha }} | |
| # docker-compose.yml 업로드 | |
| - name: Upload docker-compose.yml | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_PRIVATE_KEY }} | |
| source: "docker-compose.prod.yml" | |
| target: "${{ secrets.EC2_TARGET_PATH }}/" | |
| # EC2에서 환경 변수를 설정하고 애플리케이션 실행 | |
| - name: Deploy via SSH | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{secrets.EC2_HOST}} | |
| username: ${{secrets.EC2_USERNAME}} | |
| key: ${{ secrets.EC2_PRIVATE_KEY }} | |
| port: 22 | |
| script: | | |
| set -euo pipefail | |
| # 배포 경로/로그 폴더 | |
| mkdir -p ${{ secrets.EC2_TARGET_PATH }}/logs | |
| cd ${{ secrets.EC2_TARGET_PATH }} | |
| # 멀티라인 .env 안전 저장 | |
| cat > ./.env <<'ENV_EOF' | |
| ${{ secrets.ENV_FILE }} | |
| ENV_EOF | |
| chmod 600 ./.env | |
| # compose가 참조할 환경변수(이미지 태그/계정) | |
| export TAG=${{ github.sha }} | |
| export DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }} | |
| # Docker Hub 로그인 | |
| echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
| # 이미지 갱신 후 구동 | |
| docker compose -f docker-compose.prod.yml pull | |
| docker compose -f docker-compose.prod.yml up -d --remove-orphans | |
| docker image prune -f --filter "until=168h" |