0911 ~ 0918
# 0911 ~ 0918
# 0911 - CI/CD
https://www.redhat.com/ko/topics/devops/what-cicd-pipeline
# CI/CD?
- μ§μμ ν΅ν©(Continuous Integration, CI)
- "CI"λ κ°λ°μλ₯Ό μν μλν νλ‘μΈμ€μΈ μ§μμ μΈ ν΅ν©(Continuous Integration)μ μλ―Έ
- μ§μμ μΈ ν΅ν©μ΄ μ λλ‘ κ΅¬νλλ©΄ μ ν리μΌμ΄μ μ½λμ μλ‘μ΄ λ³κ²½ μ¬νμ΄ μ κΈ°μ μΌλ‘ λΉλ λ° ν μ€νΈλ₯Ό κ±°μ³ κ³΅μ 리ν¬μ§ν 리μ λ³ν©λλ€.
- μ§μμ μ 곡(Continuous Delivery, CD)
- μ§μμ μΈ μ 곡μ΄λ κ°λ°μλ€μ΄ μ ν리μΌμ΄μ μ μ μ©ν λ³κ²½ μ¬νμ΄ λ²κ·Έ ν μ€νΈλ₯Ό κ±°μ³ λ¦¬ν¬μ§ν 리(μ: GitHub λλ 컨ν μ΄λ λ μ§μ€νΈλ¦¬)μ μλμΌλ‘ μ λ‘λλλ κ²μ λ»νλ€.
- μ§μμ λ°°ν¬(Continuous Deployment, CD)
- μ§μμ μΈ λ°°ν¬(λ λ€λ₯Έ μλ―Έμ "CD": Continuous Deployment)λ κ°λ°μμ λ³κ²½ μ¬νμ 리ν¬μ§ν 리μμ κ³ κ°μ΄ μ¬μ© κ°λ₯ν νλ‘λμ νκ²½κΉμ§ μλμΌλ‘ 릴리μ€νλ κ²μ μλ―Έ
# 0912 - GitHub Actions
https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions
- GitHub Actionsλ λΉλ, ν μ€νΈ λ° λ°°ν¬ νμ΄νλΌμΈμ μλνν μ μλ CI/CD(μ§μμ ν΅ν© λ° μ§μμ μ λ¬) νλ«νΌ
# The components of GitHub Actions
- Events
- μ΄λ²€νΈλ μν¬νλ‘μ° μ€νμ νΈλ¦¬κ±°νλ μ μ₯μμ νΉμ νλ
- pushes a commit to a repository, pull reques, opens an issue...
- Workflows
- μν¬νλ‘μ°λ νλ μ΄μμ Jobμ μ€ννλ κ΅¬μ± κ°λ₯ν μλνλ νλ‘μΈμ€
- Jobs
- Jobμ λμΌν Runnerμμ μ€νλλ μν¬νλ‘μ°μ stepμ μ§ν©
- step
- κ° stepμ μ€νλ μ Έ μ€ν¬λ¦½νΈ λλ action
- action
- μ‘μ μ 볡μ‘νμ§λ§ μμ£Ό λ°λ³΅λλ μμ μ μννλ GitHub μ‘μ νλ«νΌμ© μ¬μ©μ μ§μ μ ν리μΌμ΄μ
- μ‘μ μ GitHubμμ Git 리ν¬μ§ν 리λ₯Ό κ°μ Έμ€κ±°λ, λΉλ νκ²½μ λ§λ μ¬λ°λ₯Έ λꡬ 체μΈμ μ€μ νκ±°λ, ν΄λΌμ°λ μ 곡μ 체μ λν μΈμ¦μ μ€μ ν μ μλ€.
- Runners
- λ¬λλ μν¬νλ‘μ°κ° νΈλ¦¬κ±°λ λ μν¬νλ‘μ°λ₯Ό μ€ννλ μλ²
- κ°κ°μ Jobμ κ°λ³μ Runnerμμ μ€ν
# 0915 - Workflow μμ
# build-and-deploy.yml
name: build-and-deploy
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
AWS_REGION: ap-northeast-2
ECR_REPOSITORY: ecr-continuous
ECS_SERVICE: test-service
ECS_CLUSTER: test-cluster
CONTAINER_NAME: app
TASK_FAMILY: test-task
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Cache SonarCloud packages
uses: actions/cache@v3.3.2
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v3.3.2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew build jacocoTestReport sonar --info
- uses: actions/upload-artifact@v3.1.3
with:
path: build/libs/*.jar
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'
- name: Build, tag, and push docker image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: latest
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Download task definition
id: retrieve-task-def
run: |
aws ecs describe-task-definition --task-definition $TASK_FAMILY --query taskDefinition > task-task-definition.json
echo "::set-output name=task-def-file::task-definition.json"
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.retrieve-task-def.outputs.task-def-file }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
- name: action-slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
https://github.com/ScaCap/action-ktlint
https://github.com/mikepenz/action-junit-report
https://github.com/Madrapps/jacoco-report
https://docs.github.com/en/actions/deployment/deploying-to-your-cloud-provider/deploying-to-amazon-elastic-container-service
https://github.com/8398a7/action-slack
https://github.com/marketplace/actions/slack-send
- https://velog.io/@insutance/github-action-slack-send
https://github.com/slackapi/slack-github-action