Deploy to Development and Production #61
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: juulabel | |
| on: | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| issues: write | |
| checks: write | |
| pull-requests: write | |
| actions: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest # 우분투 설치 | |
| env: | |
| SPRING_PROFILES_ACTIVE: ci | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 # 코드 다운로드 / 적기 귀찮은 것들을 라이브러리(스크립트 모임) 형태로 제공하는 것이 actions 이다. | |
| - name: Setup MySQL # mysql 설정 | |
| uses: samin/mysql-action@v1 | |
| with: | |
| host port: 3306 | |
| container port: 3306 | |
| mysql database: 'newjuudb' | |
| mysql user: 'admin' | |
| mysql password: 'root' | |
| character set server: 'utf8' | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v3 # JDK를 설치 | |
| with: | |
| java-version: 21 | |
| distribution: zulu | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x ./gradlew # gradlew 실행권한 부여 | |
| - name: Build with Gradle | |
| run: ./gradlew clean build -x test # build 하기 | |
| id: buildAndTests | |
| continue-on-error: true # 테스트에 실패해도 계속 로그찍기 | |
| - name: Archive test results if tests failed # 테스트가 실패하면 결과 아카이빙 | |
| if: steps.buildAndTests.outcome == 'failure' | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: test-results # 해당 URL에 테스트 결과 아카이빙 | |
| path: | | |
| **/build/reports/tests/test/ | |
| - name: Stop workflow if tests failed # 테스트가 실패하면 테스트 실패 로그 아카이빙 후 전체 플로우 종료 | |
| if: steps.buildAndTests.outcome == 'failure' | |
| run: exit 1 | |
| # UTC가 기준이기 때문에 한국시간으로 맞추려면 +9시간 해야 한다. | |
| - name: Get current time | |
| uses: 1466587594/get-current-time@v2 | |
| id: current-time | |
| with: | |
| format: YYYY-MM-DDTHH-mm-ss | |
| utcOffset: "+09:00" | |
| - name: Show Current Time #현재시간 보여주기 | |
| run: echo "CurrentTime=${{steps.current-time.outputs.formattedTime}}" | |
| # EB에 CD 하기 위해 추가 작성 | |
| - name: Generate deployment package | |
| run: | #명령어 여러줄 적기 위해 1.deploy 폴더 생성 2. jar 파일을 deploy폴더에 복사 3. Procfile 을 deploy폴더에 복사, 4.ebextensions의 폴더를 deploy 폴더에 복사 5. deploy 폴더 압축 | |
| mkdir -p deploy | |
| cp build/libs/juulabel-0.0.1-SNAPSHOT.jar deploy/application.jar | |
| cp Procfile deploy/Procfile | |
| cp -r .ebextensions deploy/.ebextensions | |
| cp -r .platform deploy/.platform | |
| cd deploy && zip -r deploy.zip . | |
| - name: Deploy to EB | |
| uses: einaregilsson/beanstalk-deploy@v21 #엘라스틱 빈스톡으로 배포하는 라이브러 | |
| with: | |
| aws_access_key: ${{ secrets.AWS_ACCESS_KEY }} | |
| aws_secret_key: ${{ secrets.AWS_SECRET_KEY }} | |
| application_name: elbjuu # 엘리스틱 빈스톡 애플리케이션 이름 | |
| environment_name: Elbjuu-env # 엘리스틱 빈스톡 환경 이름 | |
| version_label: juulabel-${{steps.current-time.outputs.formattedTime}} | |
| region: ap-northeast-2 | |
| deployment_package: deploy/deploy.zip | |
| wait_for_environment_recovery: 300 |