본문 바로가기

카테고리 없음

CI/CD 도입기

저번 글에 테스트가 중요하다는 말을 했다. 그 만큼 중요한 건 CD다.

CD를 정말 거창하게 설명하는 글이 많다. 그러나 우리가 알아야 할 건 기본적으로 CI / CD는 코드를 자동ㅇ로 테스트하고 배포하는 일이라는거다. 별 게 없다.

나는 회사에서 사용하는 Bitbucket의 Pipeline 기능을 사용했다. bitbucket은 내부적으로 pipelines라는 ci / cd 기능을 지원한다.

https://confluence.atlassian.com/bitbucket/get-started-with-bitbucket-pipelines-792298921.html

 

Get started with Bitbucket Pipelines - Atlassian Documentation

 

confluence.atlassian.com

https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html

 

Configure bitbucket-pipelines.yml - Atlassian Documentation

 

confluence.atlassian.com

와! 빠이뿌라인!

Bitbucket pipelines는 bitbucket-pipelines.yml라는 파일을 통해 설정할 수 있다. 나는 다음과 같이 설정했다.

# bitbucket-pipelines.yml
# This is a sample build configuration for JavaScript.
# Check our guides at https://confluence.atlassian.com/x/14UWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: node:10.16

pipelines:
  pull-requests:
    feature/*:
      - step:
          name: Build and test
          script:
            - yarn
            - yarn test

  branches:
    develop:
      - step:
          name: Deployment
          script:
            - pipe: atlassian/ssh-run:0.2.4
              variables:
                SSH_USER: "blablabla"
                SERVER: "blablabla"
                COMMAND: "sh -c "blablabla"
                PORT: "blablabla"

 

  • image 파라미터는 docker 이미지와 버전을 설정한다. 우리 회사는 node.js 개발을 하므로 node:10.16 버전을 사용했다.
  • pipelines 파라미터가 파이프라인 설정을 하는 부분이다.
    • pull-requests는 풀 리퀘스트가 발생했을 때 발생하는 상황을 다룬다. 브랜치 이름마다 다른 동작을 진행할 수 있다.
    • branch는 특정 브랜치에서 발생하는 이벤트를 기술한다. 나는 develop에 코드가 업데이트 됐을 때 회사 서버에 pull 할 수 있도록 설정했다.

물론 이게 설정의 끝은 아니다. 실제로 여기서 더 설정할 수도 있고... 나중에 더 추가할 건데... 언젠간 쓰는 걸로 하고, 이 쯤에서 마무리하겠다.