[CI/CD] Github Action과 친해지기 - Maven Build 하기
IT/DevOps

[CI/CD] Github Action과 친해지기 - Maven Build 하기

반응형

TL;DR

github action은 github repository의 소스를 기반으로 손쉽게 CI/CD를 구성할 수 있는 도구 입니다.

github action을 구성하기위해 yaml형식으로 정의를 해야하며 github action에서 다양한 샘픔을 제공해주고 있습니다.

그 중에 Java with Maven 샘플을 활용하여 git repository에 있는 소스를 Build해보도록 하겠습니다.

샘플 소스

https://github.com/kimdragon50/backend.git

Java with Maven 샘플 예제 가져오기

  • github.com - Actions - New workflow
  • Java with Maven 선택
  • 이렇게 하면 자동으로 git repository에 .github/workflows/maven.yaml 이 생성됩니다

AWS credentials을 secrets에 저장하기

  • github.com - Settins - Secrets
  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY

aws.yaml 커스터마이징

  • ECR배포까지는 하지 않을 것이므로 주석으로 생략합니다
  • 소스코드에 작성해놓은 dockerfile이 있어야합니다.
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven

#on:
#  push:
#    branches: [ main ]
#  pull_request:
#    branches: [ main ]

on:
  workflow_dispatch:
    inputs:
      logLevel:
        description: 'Log level'
        required: true
        default: 'warning'
      tags:
        description: 'Test scenario tags'

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'
        cache: maven
    - name: Build with Maven
      run: mvn -B package --file pom.xml

git push

git add .
git commit
# git push git-origin HEAD
git push origin HEAD

참고로 git token의 권한에 workflows가 포함되어있어야합니다.

결과

성공적으로 빌드가 되는 것을 확인할 수 있습니다. (DB가 안올라와있어서 몇번 실패 했었네요)

Git Action 사용 후기

Jenkins와 비교했을때 정말 비교할 수가 없을 정도로 쉽게 CI/CD 구성이 가능해졌습니다.

Jenkins를 사용할 경우 우선 Jenkins를 위한 서버를 구성해아하고 Jenkins install 부터 Plugin install 까지 CI/CD를 구성하기위한 Jenkins 서버 세팅이 필요 했습니다.

그런데 git action을 사용하면 별도의 서버도 필요없고 관련된 플러그인도 필요가 없습니다. 모두 yaml에서 간단한 설정으로 해결 할 수 있게 되었습니다.

사용하는 내내 소름돋았네요. 제가 만약 시스템 담당자라면 무적권 Git Action을 사용할 것 같습니다.

다음시간에는 continuous delivery(CD) 부분을 구현해보도록 하겠습니다.

반응형