Github Actions로 Heroku서버에 배포하기(CI/CD)
CI/CD 란 간단하게 말해서 어플리케이션 개발 단계부터 배포때까지 이 모든 단계들을 자동화를 통해서 조금 더 효율적이고 빠르게 사용자에게 빈번이 배포할 수 있도록 만드는 것을 말한다.
CI ( Continuous Integration) 지속적인 통합
1)코드 변경사항을 주기적으로 빈번하게 merge 해야한다.(작은 단위로 나눠서 repo 에 merge)
2)통합을 위한 단계(빌드,테스트,머지)의 자동화
주기적으로 merge 를 하기에 코드의 문제점을 빠르게 발견, merge 충돌을 막을수 있다.빠르게 버그 수정 용이
이를 통한 코드의 퀄리티 향상
모든 개발자들에게 자신의 작성한 코드에 대해서는 unit test를 포함해야 한다.
CD(Continuous Delievery or Deployment) 지속적인 제공,배포
마지막 배포단계에서 자동화
1)ci를 통한 주기적인 merge를 통해 빌드,테스트,머지가 자동화되었다면, 이를 배포하는 단계에서 자동화진행된다.
회사마다, 팀마다 다른 방식을 적용할 수 있다.
다양한 툴들
Jenkins , Travis CI ,GitLab CI/CD ,CircleCI ,GithubActions
CI/CD 도구의 선택은 개발팀의 특정 요구 사항과 요구 사항에 따라 다르며 팀 규모, 팀 프로젝트의 복잡성, 가용 예산 과 같은 요소를 고려해서 선택해야 한다.
Github Actions로 Heroku서버에 배포하기(CI/CD)
오른쪽 상단에 - Account settings 를 들어가게되면 API KEY 를 확인할 수 있다.이를 카피 해놓은다.
그리고 내가 배포할 REPO에 간다.
Setting - Secrets and variables -Actions 를 눌어서 New repository secret을 생성 한다.이름은 상관없지만 알기쉽게 작성하고 내용은 아까 헤로쿠에서 복사한 api key 값을 넣는다.
git 파일에 .github-workflows- depoly.yml 의 순으로 파일을 추가한다.
# This is a basic workflow to help you get started with Actions
name: Deploy
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: Deploy to Heroku
uses: AkhileshNS/heroku-deploy@v3.12.12
with:
# This will be used for authentication. You can find it in your heroku homepage account settings
heroku_api_key: ${{ secrets.HEROKU_DEPLOY_KEY }} <- actions 에 만든 key 이름
# Email that you use with heroku
heroku_email: 헤로쿠 메일 주소
# The appname to use for deploying/updating
heroku_app_name: 헤로쿠에서 새롭게 만든 app 이름
추가로 system.poperties 과 Procfile 파일 생성해야 한다.
system.poperties 는 내가 사용한 java 버전을 적어준다. 11버전이상부터는 적어줘야 헤로쿠에 문제가 안생긴다.
Procfile 을 아래와 같이 만든다. 나중에 버젼업이 되면 수정 필요 .
web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/sns-0.0.1-SNAPSHOT.jar
이를 다 하고 main에 커밋, 푸쉬를 하게되면 actions 파일이 이렇게 된다.
헤로쿠사이트에서도 이와같이 변하며 빌드업중이다.