AWS CodeDeploy 설정 (S3)

AWS CodeDeploy

The flow of a typical AWS CodeDeploy deployment

The flow of a typical AWS CodeDeploy deployment

  1. 설정 목록
    EC2 On-Premises(EC2가 아닌 물리서버)
    CodeDeploy 서비스용 IAM 권한 생성
    서버용  IAM 권한 생성
    CodeDeploy Application 생성
    EC2 설정
    CodeDeploy Agent 설치/설정
    On-Premise 서버 설정
    배포 파일 준비, appspec.yml 설정 [반복]
    배포 [반복]
  2. CodeDeploy 서비스용 IAM 권한 생성
    1. [AWS-Console] IAM > Roles : Create New Role
      1. Role Type :  AWS CodeDeploy
      2. Attach Policy : AWSCodeDeployRole
  3. 서버용 IAM 권한 생성
    1. [AWS-Console] IAM > Policies : Create Policy
      {
          "Version": "2012-10-17",
          "Statement": [
              {
                  "Effect": "Allow",
                  "Action": [
                      "s3:Get*",
                      "s3:List*"
                  ],
                  "Resource": [
                      "*",
                      "arn:aws:s3:::my_source_bucket_name/*"
                  ]
              }
          ]
      }
    2. [AWS-Console] IAM > Roles : Create New Role
      1. Role Type : AWS EC2
      2. Attach Policy : 위 Policy를 선택
  4. CodeDeploy Application 생성
    1. [AWS-Console] CodeDeploy > Create New Application
    2. Service Role : 위 ‘서비스용 IAM 권한 생성’ 단계에서 생성한 IAM Role를 지정
  5. EC2 설정 (EC2 서버 전용)
    1. [AWS-Console] EC2> Launch Instance : Launch Instance
      1. IAM role : 위 ‘서버용 IAM 권한 생성’ 단계에서 생성한 IAM Role를 지정
      2. 배포를 받는 모든 서버 인스턴스에 적용
  6. CodeDeploy Agent 설치/설정
    1. 배포를 받는 모든 서버에 설치
    2. Download Installer & Install
      # Linux
      wget https://s3-ap-northeast-1.amazonaws.com/aws-codedeploy-ap-northeast-1/latest/install
      chmod +x ./install
      ./install auto
      # Windows
      if not exist "c:\temp" mkdir c:\temp
      powershell.exe -Command Read-S3Object -BucketName bucket-name -Key latest/codedeploy-agent.msi -File c:\temp\codedeploy-agent.msi
      c:\temp\codedeploy-agent.msi /quiet /l c:\temp\host-agent-install-log.txt
      

      또는 VERSION 파일을 참고로 수동 다운로드 & 설치

    3. Launch Service (OS에 따라 상이함)
      RedHat> service codedeploy-agent start
      SUSE> systemctl start codedeploy-agent.service
      Windows> powershell.exe -Command Get-Service -Name codedeployagent
    4. 참고
      1. AWS CodeDeploy Agent Operations
      2. AWS CodeDeploy Agent Source Code
  7. On-Premise 서버 설정 (On-Premise 서버 전용)
    1. Create IAM account
      1. [AWS-Console] IAM > Users : Create New Users
      2. Generate an access key for each user : on
      3. Access Key ID 와 Secret Access Key 를 메모
      4. Permissions 에서 위의 ‘서버용 IAM 권한’단계에서 생성한 Policy를 추가
    2. CodeDeploy Agent 설정
      1. Linux : /etc/codedeploy-agent/conf/codedeploy.onpremises.yml
      2. Windows : C:\ProgramData\Amazon\CodeDeploy\conf.onpremises.yml
      3. ---
        aws_access_key_id: secret-key-id
        aws_secret_access_key: secret-access-key
        iam_user_arn: IAM-user-ARN
        region: supported-region
    3. CodeDeploy Agent 서비스 재시작
    4. 참고 : Configure an On-Premises Instance to Work with AWS CodeDeploy
  8. 배포 파일 준비
    1. appspec.yml 생성
      version: 0.0
      os: linux
      files:
        - source: ./www/
          destination: /home/www/
      permissions:
        - object: /home/www/*/webapps
          pattern: "*"
          owner: root
          group: admin
          mode: 775
          type:
            - directory
        - object: /home/www/*/webapps
          pattern: "*"
          owner: root
          group: admin
          mode: 664
          type:
            - file
      hooks:
        AfterInstall:
          - location: scripts/owner-reset.sh
            timeout: 30
            runas: root
          - location: scripts/reload-httpd.sh
            timeout: 30
            runas: root
      

      참고 : AWS CodeDeploy AppSpec File Reference

    2. 위 appspec.yml 파일을 포함하여 소스를 zip 또는 tar, tar.gz 로 압축하여, 위의 서버용 IAM 권한이 지정된 S3에 업로드
  9. 배포
    1. [AWS-Console] CodeDeploy > Deployments : Create New Deployment
      1. Application : 위의 ‘CodeDeploy Application 생성’ 에서 생성한 Application
      2. Deployment Group : 위의 ‘CodeDeploy Application 생성’ 에서 생성한 Deployment Group
      3. Revision Type : Amazon S3
      4. Revision Location : 위에서 업로드 한 zip 또는 tar, tar.gz 파일의 URL
      5. Deployment Config : CodeDeployDefault.OneAtTime (일반적인 설정, 환경에 맞게 선택)
    2. Deploy Now

 

♦ References

http://docs.aws.amazon.com/ko_kr/codedeploy/latest/userguide/welcome.html
http://blog.gsclip.com/2015/09/codedeploy-%EC%9D%B4%ED%95%B4/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.