DevOps/๐Ÿ“Œ Issue!

[DevOps] Elastic Beanstalk + Github Actions ํ™˜๊ฒฝ์—์„œ Deployment failed: Error: Deployment failed! Current State: Version: Sample Application, Health: Red, Health Status: Degraded ๋ฌธ์ œ ํ•ด๊ฒฐ

Alchemists 2023. 1. 14. 16:43
728x90

Github Actions๋กœ ์Šคํ”„๋ง๋ถ€ํŠธ๋ฅผ CI/CDํ• ๋•Œ Elastic Beanstalk์—์„œ ๋ฐฐํฌ๋ฅผ ํ•˜๋ คํ–ˆ๊ณ , grade.yml์— Beanstalk ์„ค์ •์„ ํ•ด์ฃผ๋Š”๋ถ€๋ถ„์—์„œ ๊ณ„์† ์—๋Ÿฌ๊ฐ€ ํ„ฐ์กŒ๋‹ค

 

์˜ˆ๋ฅผ ๋“ค๋ฉด

์ด๊ฑด deployment_package๊ฐ€ ์ด๋ฏธ ์žˆ๋‹ค๋Š” ์—๋Ÿฌ ๊ฐ™์•˜๊ณ 

 

์ด๋ ‡๊ฒŒ ๋ฐ‘์—๋‹ค true๋กœ ์„ค์ •ํ•ด๋‘์—ˆ๋‹ค!

์ด ์—๋Ÿฌ๊ฐ€ jolla ๋นก์ณค๋‹ค ์ž๊พธ ์„ฑ๋Šฅ์ €ํ•˜๋๋‹ค ๊ทธ๋Ÿฌ๋Š”๋ฐ ์–ด๋””์„œ ๋ฌธ์ œ์ธ์ง€ ๋ชจ๋ฅด๋‹ˆ๊นŒ ๋ถ„๋…ธ ๊ทธ ์žก์ฑ„์˜€๋‹ค. 

 

๊ทธ๋ž˜์„œ ์ด๊ฒŒ ์™œ ์ž˜๋ชป๋๋‚˜ ์ƒ๊ฐ์„ ํ•ด๋ดค๊ณ  ๋‘๊ฐ€์ง€๋ฅผ ๊ณ ์น˜๋‹ˆ ํ•ด๊ฒฐ๋˜์—ˆ๋‹ค.

 

1. gradle.yml์„ ์“ฐ๋Š” ์ˆœ์„œ์˜ ๋ฌธ์ œ

์›๋ž˜๋Š” gradle -> docker->EB ์ˆœ์„œ๋กœ ์ง„ํ–‰ํ–ˆ์–ด์•ผ ํ–ˆ๋Š”๋ฐ gradle->EB->docker๋กœ ์จ์ฃผ๋Š”๊ฒŒ ๋ฌธ์ œ์˜€๋‹ค. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
jobs:
  build:
 
    runs-on: ubuntu-latest
 
    steps:
    - uses: actions/checkout@v3
    - name: Set up JDK 11
      uses: actions/setup-java@v3
      with:
        java-version: '11'
        distribution: 'temurin'
    - name: Build with Gradle
      uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
      with:
        arguments: build
      # Beanstalk ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์‚ฌ์šฉ
      # ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ด๋‘” IAM ์ธ์ฆํ‚ค๋ฅผ ์‚ฌ์šฉ
    - name: Beanstalk Deploy
      uses: einaregilsson/beanstalk-deploy@v20
      with:
          aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          application_name: docker-elasticbeanstalk
          environment_name: docker-elasticbeanstalk-env
          version_label: "github-action--${{ steps.format-time.outputs.replaced }}"
          region: ap-northeast-2
          deployment_package: Dockerrun.aws.json
          
        ### Gradle ###
    - name: Run chmod to make gradlew executable
      run: chmod +x ./gradlew
 
    - name: Build with Gradle
      run: ./gradlew build
 
 
    - name: Docker build
      run: |
          docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
          docker build -t spring-boot-cicd .
          docker tag spring-boot-cicd taeong/spring-boot-cicd:latest
          docker push taeong/spring-boot-cicd:latest
    - name: Get timestamp
      uses: gerred/actions/current-time@master
      id: current-time
 
    - name: Run string replace
      uses: frabert/replace-string-action@master
      id: format-time
      with:
          pattern: '[:\.]+'
          string: "${{ steps.current-time.outputs.time }}"
          replace-with: '-'
          flags: 'g'
cs

 

 

2. eb version label์˜ ๋ฌธ์ œ

 

version_label: github-action-${{steps.current-time.outputs.formattedTime}}๋ผ๊ณ  ์จ์คฌ๋Š”๋ฐ gradleํŒŒ์ผ ์–ด๋–ค ๊ณณ์—๋„ ์‹œ๊ฐ„๊ด€๋ จ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ๋‘์ง€ ์•Š์•˜๋‹ค.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
      - name: Build with Gradle
        run: ./gradlew build
 
      - 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}}"
        shell: bash
 
 
      - name: Docker build
        run: |
          docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
          docker build -t docker-jungmin .
          docker tag docker-jungmin jungminleeee/docker-jungmin:latest
          docker push jungminleeee/docker-jungmin:latest
        # Beanstalk ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์‚ฌ์šฉ
        # ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ด๋‘” IAM ์ธ์ฆํ‚ค๋ฅผ ์‚ฌ์šฉ
      - name: Deploy to EB
        uses: einaregilsson/beanstalk-deploy@v21
        with:
          aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          application_name: jungminExercise
          environment_name: Jungminexercise-env
          version_label: github-action-${{steps.current-time.outputs.formattedTime}}
          region: ap-northeast-2
          deployment_package: Dockerrun.aws.json
          use_existing_version_if_available: true
cs

 

์ด๋Ÿฐ์‹์œผ๋กœ ๋ฐ”๊ฟ”๋ณด์•˜๋‹ค!

 

์ตœ์ข…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
 
name: Java CI with Gradle
 
on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]
 
permissions:
  contents: read
 
jobs:
  build:
 
    runs-on: ubuntu-latest
 
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 11
        uses: actions/setup-java@v2
        with:
          java-version: '11'
          distribution: 'adopt'
 
        ### Gradle ###
      - name: Run chmod to make gradlew executable
        run: chmod +x gradlew
 
      - name: Build with Gradle
        run: ./gradlew build
 
      - 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}}"
        shell: bash
 
 
      - name: Docker build
        run: |
          docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
          docker build -t docker-jungmin .
          docker tag docker-jungmin jungminleeee/docker-jungmin:latest
          docker push jungminleeee/docker-jungmin:latest
        # Beanstalk ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์‚ฌ์šฉ
        # ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ด๋‘” IAM ์ธ์ฆํ‚ค๋ฅผ ์‚ฌ์šฉ
      - name: Deploy to EB
        uses: einaregilsson/beanstalk-deploy@v21
        with:
          aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          application_name: jungminExercise
          environment_name: Jungminexercise-env
          version_label: github-action-${{steps.current-time.outputs.formattedTime}}
          region: ap-northeast-2
          deployment_package: Dockerrun.aws.json
          use_existing_version_if_available: true
cs
728x90