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 |