[Deployment] Automated Deployment

Steve·2021년 7월 14일
0

웹개발 코스

목록 보기
59/59

배포 자동화

AWS 로 github 에 수정사항을 commit 하면 자동으로 수정사항을 반영하게 만들 수 있다.

배포 자동화 pipeline

Source stage -> Build stage -> Deploy stage

  1. Source stage - Github 같은 저장소에 코드 변경이 생기면 감지
  2. Build stage - source 단계에서 전달받은 코드를 compile, build, test
  3. Deploy stage - build 단계에서 전달받은 결과를 반영

Pipeline 단계는 상황과 필요에 따라 세분화되거나 간소화될 수 있다.

AWS 개발자 도구

CodeCommit

Github 과 비슷한 version control tool
github 과 차이점 - 보안에 좀더 강점, 대신 과금 가능성

CodeBuild

Compile, build, test 가능
buildspec.yml 파일을 참조하여 작업 수행

참고자료: https://docs.aws.amazon.com/ko_kr/codebuild/latest/userguide/build-spec-ref.html

CodeDeploy

실행되고 있는 서버 애플리케이션에 실시간으로 변경 사항 반영
appspec.yml 파일을 참조하여 작업 수행

참고자료: https://docs.aws.amazon.com/ko_kr/codedeploy/latest/userguide/reference-appspec-file.html

CodePipeline

파이프라인 구축
free tier 계정은 2개부터 과금

AWS IAM

Identity and Access Management

권한 관리 서비스 (admin 계정, 일반 계정같이)

예시 파일

buildspec.yml 예시 파일

version: 0.2

phases:
  pre_build:
    commands:
      - cd client
      - npm install
  build:
    commands:
      - npm run build

artifacts:
  files:
    - '**/*'
  base-directory: client/build

예시 appspec.yml 파일

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu/im-sprint-practice-deploy

hooks:
  ApplicationStop:
    - location: scripts/stop.sh
      runas: root
  AfterInstall:
    - location: scripts/initialize.sh
      runas: root
  ApplicationStart:
    - location: scripts/start.sh
      runas: root

scripts/initialize.sh

#!/bin/bash
cd /home/ubuntu/im-sprint-practice-deploy/server
npm install
npm install pm2@latest -g
sudo apt-get update
sudo apt-get install authbind
sudo touch /etc/authbind/byport/80
sudo chown ubuntu /etc/authbind/byport/80
sudo chmod 755 /etc/authbind/byport/80

scripts/start.sh

#!/bin/bash
cd /home/ubuntu/im-sprint-practice-deploy/server
authbind --deep pm2 start app.js
scripts/stop.sh

scripts.stop.sh

#!/bin/bash
cd /home/ubuntu/im-sprint-practice-deploy/server
pm2 stop app.js 2> /dev/null || true
pm2 delete app.js 2> /dev/null || true

  • gibhub 에도 관련 기능이 있다. github action, github pages
  • vrecel 은 클라만 배포 가능하다. 서버는 불가.
  • devops 포지션은 배포, 운영, 환경구성 전문가 직군이다.
  • 가면 갈수록 linux 를 잘 알아야 한다.

12factors.net

profile
게임과 프론트엔드에 관심이 많습니다.

0개의 댓글