๐Ÿ™‚0819[AWS CI/CD]

๋ง์ง€ยท2022๋…„ 8์›” 19์ผ
0

๐Ÿ“Œ cloud9

๐Ÿ“™ Cloud 9

create environment

name : my-cloud9

default๋กœ ์œ ์ง€
cost-saving setting ; ์ž๋™์œผ๋กœ ์ตœ๋Œ€์ ˆ์ „๋ชจ๋“œ ์ „ํ™˜ (ec2) - Network settings (advanced)

vpc default๋กœ ํ•ด๋„ ๋จ. ๊ทผ๋ฐ ๊ทธ๋ƒฅ ์„ค์ •ํ•˜์ž.
+ํƒœ๊ทธ ๋„ฃ๊ธฐ

ํ™•์ธ ํ›„ create


IDE ํ™˜๊ฒฝ ์ƒ์„ฑ ์™„๋ฃŒ


my-cloud9์ด ํ™ˆํด๋”(environment).


hello.py ํŒŒ์ผ ์ƒ์„ฑ (my-cloud ํด๋” ์šฐํด๋ฆญ - New File)

import sys
print('Hello, World!')
print('The sum of 2 and 3 is 5.')
sum = int(sys.argv[1]) + int(sys.argv[2])
print('The sum of {0} and {1} is {2}.'.format(sys.argv[1], sys.argv[2], sum))

ํŒŒ์ผ์— ์œ„ ๋ช…๋ น์–ด ์ž…๋ ฅ


run


command ์ด์šฉ

๐Ÿ“™ ํŒŒ์ด์ฌ์œผ๋กœ AWS SDK (boto3) ํ™œ์šฉ s3 ๋‹ค๋ฃจ๊ธฐ

boto3๋ฅผ ์„ค์น˜ํ•ด์•ผํ•จ (SDK)

curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py
python -m pip --version
rm get-pip.py
python -m pip install boto3
python -m pip show boto3

์œ„ ๋ช…๋ น์–ด bashํƒญ์—์„œ ์ž…๋ ฅํ•˜์—ฌ ์„ค์น˜

s3.pyํŒŒ์ผ ํƒญ์—์„œ ์ƒ์„ฑํ•˜์—ฌ ์•„๋ž˜ ๋ช…๋ น์–ด ์ž…๋ ฅ

import sys
import boto3
from botocore.exceptions import ClientError

def get_s3(region=None):
    """
    Get a Boto 3 Amazon S3 resource with a specific AWS Region or with your
    default AWS Region.
    """
    return boto3.resource('s3', region_name=region) if region else boto3.resource('s3')

def list_my_buckets(s3):
    print('Buckets:\n\t', *[b.name for b in s3.buckets.all()], sep="\n\t")

def create_and_delete_my_bucket(bucket_name, region, keep_bucket):
    s3 = get_s3(region)

    list_my_buckets(s3)

    try:
        print('\nCreating new bucket:', bucket_name)
        bucket = s3.create_bucket(
            Bucket=bucket_name,
            CreateBucketConfiguration={
                'LocationConstraint': region
            }
        )
    except ClientError as e:
        print(e)
        sys.exit('Exiting the script because bucket creation failed.')


    bucket.wait_until_exists()
    list_my_buckets(s3)

    if not keep_bucket:
        print('\nDeleting bucket:', bucket.name)
        bucket.delete()

        bucket.wait_until_not_exists()
        list_my_buckets(s3)
    else:
        print('\nKeeping bucket:', bucket.name)


def main():
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('bucket_name', help='The name of the bucket to create.')
    parser.add_argument('region', help='The region in which to create your bucket.')
    parser.add_argument('--keep_bucket', help='Keeps the created bucket. When not '
                                              'specified, the bucket is deleted '
                                              'at the end of the demo.',
                        action='store_true')

    args = parser.parse_args()

    create_and_delete_my_bucket(args.bucket_name, args.region, args.keep_bucket)


if __name__ == '__main__':
    main()

์ปค๋งจ๋“œ์ฐฝ์— ์•„๋ž˜ ๋ช…๋ น์–ด ์ž…๋ ฅ.

s3.py s3.lovemj.shop ap-northeast-2 --keep_bucket

๐Ÿ“Œ codecommit

๐Ÿ“™iam ์‚ฌ์šฉ์ž ์ƒ์„ฑ

ํƒœ๊ทธ skipํ•˜๊ณ  ์ƒ์„ฑ, .csvํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ .

dev-user ํด๋ฆญํ•ด์„œ ์‚ฌ์šฉ์ž ์ง„์ž… - ๋ณด์•ˆ ์ž๊ฒฉ ์ฆ๋ช… - ํ•˜๋‹จ์œผ๋กœ ๋‚ด๋ ค์„œ AWS CodeCommit์— ๋Œ€ํ•œ HTTPS Git ์ž๊ฒฉ ์ฆ๋ช…์—์„œ ์ž๊ฒฉ์ฆ๋ช… ์ƒ์„ฑํ•ด๋‘๊ธฐ. + ์ž๊ฒฉ์ฆ๋ช…๋‹ค์šด๋กœ๋“œ
->github์ด์šฉํ• ๋•Œ ๋งค๋ฒˆ ๋กœ๊ทธ์ธํ•˜์ง€ ์•Š์•„๋„ ๋˜๋„๋ก.

๐Ÿ“™ codecommit

โœ”๏ธ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ์ƒ์„ฑ - ์ด๋ฆ„ : my-repo -์ƒ์„ฑ

โœ”๏ธcloud9 bash์—์„œ ๋ฒ„์ „ ํ™•์ธ

โœ”๏ธcodecommit https ๋ณต์ œํ•ด์„œ git clone ์ง„ํ–‰

git clone https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/my-repo

-> ์ด๋ฏธ ์ž๊ฒฉ์ฆ๋ช… ๋˜์–ด์žˆ์–ด์„œ aws configure ๋ช…๋ น์–ด ํ•„์š” ์—†์Œ ์ถ”ํ›„์— ๋‹ค๋ฅธ ec2์—์„œ ํ•˜๊ฑฐ๋‚˜ ํ•˜๋ฉด aws configure ํ•ด์„œ ์ž๊ฒฉ์ฆ๋ช… ํ•ด์ฃผ๋ฉด ๋จ. ๊ธฐํƒ€ - aws git ์ž๊ฒฉ์ฆ๋ช… ์ฐธ๊ณ 
->migration ์‹ค์Šตํ•˜๊ธฐ ์œ„ํ•ด ์ƒ์„ฑ๋œ my-repo ์‚ญ์ œ

โœ”๏ธ github๋ฆฌํฌ์ง€ํ† ๋ฆฌ migration

git clone ํ•˜๊ธฐ ์œ„ํ•ด github ์ฃผ์†Œ ๋ณต์‚ฌ

migrationํ•˜๊ธฐ ์œ„ํ•ด codecommit ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ์ฃผ์†Œ ๋ณต์‚ฌํ•˜์—ฌ ๋งˆ์ด๊ทธ๋ž˜์ด์…˜ ์ง„ํ–‰

ec2-user:~/environment $ mkdir git-migration
ec2-user:~/environment $ git clone --mirror https://github.com/mangjini/hello-world.git git-migration
ec2-user:~/environment/git-migration (BARE:master) $ git push -uf https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/my-repo --all 

๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ ์™„๋ฃŒ ํ™•์ธ

๐Ÿ“Œ code build

๐Ÿ“™ code commit์—์„œ ์ฝ”๋“œ ๋นŒ๋“œ๋ฅผ์œ„ํ•œ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ์ƒ์„ฑํ•˜๊ธฐ

๐Ÿ“™ cloud9

ec2-user:~/environment $ npm install vue
ec2-user:~/environment $ npm install --global vue-cli

codebuild-repo์ฃผ์†Œ ๋ณต์‚ฌํ•ด์„œ git clone.

ec2-user:~/environment $ git clone https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/codebuild-repo

vue ์›นํŒฉ ์„ค์น˜

ec2-user:~/environment $ vue init webpack codebuild-repo
ec2-user:~/environment $ cd codebuild-repo/
ec2-user:~/environment/codebuild-repo (master) $ ls
build  config  index.html  node_modules  package.json  package-lock.json  README.md  src  static  test
ec2-user:~/environment/codebuild-repo (master) $ 
ec2-user:~/environment/codebuild-repo (master) $ git add.
git: 'add.' is not a git command. See 'git --help'.

The most similar command is
        add
ec2-user:~/environment/codebuild-repo (master) $ git add .
ec2-user:~/environment/codebuild-repo (master) $ git status
ec2-user:~/environment/codebuild-repo (master) $ git commit -m "uploading new file"
ec2-user:~/environment/codebuild-repo (master) $ git push

๐Ÿ“™ s3

โœ”๏ธs3 ๋ฒ„ํ‚ท- ์†์„ฑ -์ •์  ์›น ์‚ฌ์ดํŠธ ํ˜ธ์ŠคํŒ… ํŽธ์ง‘


๋ณ€๊ฒฝ์‚ฌํ•ญ ์ €์žฅ ํด๋ฆญ

โœ”๏ธ๊ถŒํ•œ - ํผ๋ธ”๋ฆญ ์•ก์„ธ์Šค ํ—ˆ์šฉ ํ™•์ธ

โœ”๏ธ ๊ถŒํ•œ - ๋ฒ„ํ‚ท์ •์ฑ… ํŽธ์ง‘ - ์ •์ฑ… ์ƒ์„ฑ๊ธฐ

โœ”๏ธ

ARN : arn:aws:s3:::s3.lovemj.shop

{
  "Id": "Policy1660876142326",
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1660876078119",
      "Action": [
        "s3:GetObject"
      ],
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::s3.lovemj.shop/*",
      "Principal": "*"
    }
  ]
}


arn์— ๋ฒ„ํ‚ท์ด๋ฆ„ ์˜†์— /* ๊ผญํ•ด์ฃผ๊ธฐ!

๐Ÿ“™ code build

ํ”„๋กœ์ ํŠธ ๋นŒ๋“œ - ๋นŒ๋“œ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ


๋‚˜๋จธ์ง€ default - ๋นŒ๋“œ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

๐Ÿ“™ iam- ์—ญํ• 

codebuild ๊ฒ€์ƒ‰ - s3 role ํด๋ฆญ

๊ถŒํ•œ์ •์ฑ…- ๊ถŒํ•œ ์ถ”๊ฐ€ - ์ •์ฑ… ์—ฐ๊ฒฐ - s3 ๊ฒ€์ƒ‰ - s3FullAccess - ํ•˜๋‹จ์— ์ •์ฑ… ์—ฐ๊ฒฐ ํด๋ฆญ

๐Ÿ“™ ๋นŒ๋“œ

๊ฒฝ๋กœ์— ๋งž๊ฒŒ buildspec.yml ์ƒ์„ฑ

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 16
    commands:
      - npm i npm@latest -g
  pre_build:
    commands:
      - npm install
  build:
    commands:
      - npm run build
  post_build:
    commands:
      - aws s3 sync ./dist s3://s3.lovemj.shop

git add .
git commit -m "codebuild test commit"
git push

codebuild์—์„œ ๋นŒ๋“œ ์‹œ์ž‘

s3์†์„ฑ์—์„œ ๋ฒ„ํ‚ท ์›น์‚ฌ์ดํŠธ ์—”๋“œํฌ์ธํŠธ๋กœ ์ง„์ž…

route53์—์„œ ๋„๋ฉ”์ธ ์„ค์ • -> ๋ฒ„ํ‚ท ์ด๋ฆ„๊ณผ ๋„๋ฉ”์ธ์ด ๊ฐ™์•„์•ผํ•จ.

๐Ÿ“Œ ์ฝ”๋“œ ์ˆ˜์ •ํ•ด๋ณด๊ณ  ๋‹ค์‹œ ๋นŒ๋“œ

๐Ÿ“™ ์ฝ”๋“œ ์ˆ˜์ •

cli ํ™˜๊ฒฝ์—์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ง„์ž…ํ•˜์—ฌ ์ˆ˜์ • ๊ฐ€๋Šฅ

ec2-user:~/environment/codebuild-repo/src/components (master) $ vi HelloWorld.vue 

โœ”๏ธ git pushํ•ด์ฃผ๊ธฐ

ec2-user:~/environment/codebuild-repo (master) $ git add .

ec2-user:~/environment/codebuild-repo (master) $ git status

ec2-user:~/environment/codebuild-repo (master) $ git commit -m "Hello mangji add"

ec2-user:~/environment/codebuild-repo (master) $ git push 

โœ”๏ธcode build์—์„œ ๋นŒ๋“œ์‹œ์ž‘ ํด๋ฆญ

์ˆ˜์ • ํ™•์ธ

๐Ÿ“Œ code deploy

๐Ÿ“™ ์—ญํ•  ๋งŒ๋“ค๊ธฐ

iam - ์—ญํ•  ๋งŒ๋“ค๊ธฐ -


-> ์—ญํ•  ์ƒ์„ฑ

โœ”๏ธ์—ญํ• ์— ์‹ ๋ขฐ ๊ด€๊ณ„ ํŽธ์ง‘

codedeployroleํด๋ฆญ - ์‹ ๋ขฐ ๊ด€๊ณ„ - ์‹ ๋ขฐ ์ •์ฑ… ํŽธ์ง‘ -
๊ธฐ์กด json๋ฌธ ์‚ญ์ œํ•˜๊ณ  ์•„๋ž˜ ๋‚ด์šฉ ๋ถ™์—ฌ๋„ฃ๊ธฐ

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "Service": [
                    "codedeploy.us-east-2.amazonaws.com",
                    "codedeploy.us-east-1.amazonaws.com",
                    "codedeploy.us-west-1.amazonaws.com",
                    "codedeploy.us-west-2.amazonaws.com",
                    "codedeploy.eu-west-3.amazonaws.com",
                    "codedeploy.ca-central-1.amazonaws.com",
                    "codedeploy.eu-west-1.amazonaws.com",
                    "codedeploy.eu-west-2.amazonaws.com",
                    "codedeploy.eu-central-1.amazonaws.com",
                    "codedeploy.ap-east-1.amazonaws.com",
                    "codedeploy.ap-northeast-1.amazonaws.com",
                    "codedeploy.ap-northeast-2.amazonaws.com",
                    "codedeploy.ap-southeast-1.amazonaws.com",
                    "codedeploy.ap-southeast-2.amazonaws.com",
                    "codedeploy.ap-south-1.amazonaws.com",
                    "codedeploy.sa-east-1.amazonaws.com"
                ]
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

์ •์ฑ… ์—…๋ฐ์ดํŠธ ํด๋ฆญ

๐Ÿ“™ ์ •์ฑ… ์ƒ์„ฑ

iam - ์ •์ฑ…- ์ •์ฑ… ์ƒ์„ฑ - JSON - ๊ธฐ์กด ๋‚ด์šฉ ์ง€์šฐ๊ณ  ์•„๋ž˜ ๋‚ด์šฉ ๋ถ™์—ฌ๋„ฃ๊ธฐ

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:Get*",
        "s3:List*"
      ],
      "Resource": [
        "arn:aws:s3:::replace-with-your-s3-bucket-name/*",
        "arn:aws:s3:::aws-codedeploy-us-east-2/*",
        "arn:aws:s3:::aws-codedeploy-us-east-1/*",
        "arn:aws:s3:::aws-codedeploy-us-west-1/*",
        "arn:aws:s3:::aws-codedeploy-us-west-2/*",
        "arn:aws:s3:::aws-codedeploy-ca-central-1/*",
        "arn:aws:s3:::aws-codedeploy-eu-west-1/*",
        "arn:aws:s3:::aws-codedeploy-eu-west-2/*",
        "arn:aws:s3:::aws-codedeploy-eu-west-3/*",
        "arn:aws:s3:::aws-codedeploy-eu-central-1/*",
        "arn:aws:s3:::aws-codedeploy-ap-east-1/*",
        "arn:aws:s3:::aws-codedeploy-ap-northeast-1/*",
        "arn:aws:s3:::aws-codedeploy-ap-northeast-2/*",
        "arn:aws:s3:::aws-codedeploy-ap-southeast-1/*",        
        "arn:aws:s3:::aws-codedeploy-ap-southeast-2/*",
        "arn:aws:s3:::aws-codedeploy-ap-south-1/*",
        "arn:aws:s3:::aws-codedeploy-sa-east-1/*"
      ]
    }
  ]
}

๋‹ค์Œ : ํƒœ๊ทธ - ํƒœ๊ทธ ์ƒ๋žต - ๋‹ค์Œ: ๊ฒ€ํ† 

์ด๋ฆ„ : codedeploy-ec2 , ์ •์ฑ… ์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญ

๐Ÿ“™ ๋งŒ๋“  ์ •์ฑ…์„ ๋ถ€์—ฌํ•˜๊ธฐ ์œ„ํ•œ ์—ญํ•  ๋งŒ๋“ค๊ธฐ

iam- ์—ญํ• - ์—ญํ• ๋งŒ๋“ค๊ธฐ

-๋‹ค์Œ - codedeploy-ec2 ์„ ํƒ , s3 ๊ฒ€์ƒ‰ํ•ด์„œ AmazonS3FullAccess ์„ ํƒ - ๋‹ค์Œ - ์—ญํ•  ์ด๋ฆ„ : codedeploy-ec2-role

์—ญํ• ์ƒ์„ฑ ํด๋ฆญ

๐Ÿ“™ ์˜คํ† ์Šค์ผ€์ผ๋ง

์‹œ์ž‘ ํ…œํ”Œ๋ฆฟ์œผ๋กœ ํ•ด๋„ ๋˜์ง€๋งŒ ์‹œ์ž‘๊ตฌ์„ฑ์œผ๋กœ ํ•ด๋ณด์ž.
โœ”๏ธec2- ์‹œ์ž‘๊ตฌ์„ฑ- ์‹œ์ž‘ ๊ตฌ์„ฑ์ƒ์„ฑ - ์ด๋ฆ„ : my-lc - AMI : ami-01711d925a1e4cc3a - ์ธ์Šคํ„ด์Šค ์œ ํ˜• : t2.micro - ์ธ์Šคํ„ด์Šค ํ”„๋กœํ•„์— ์—ญํ•  ํ• ๋‹น

โœ”๏ธ๋ณด์•ˆ๊ทธ๋ฃน ์„ ํƒ

โœ”๏ธ ํ‚ค ํŽ˜์–ด ์„ ํƒ, ์ฒดํฌ๋ฐ•์Šค ์ฒดํฌ

โœ”๏ธ ๋‹ค์‹œ ์œ„๋กœ ์˜ฌ๋ผ๊ฐ€์„œ ,์ถ”๊ฐ€๊ตฌ์„ฑ - ๊ณ ๊ธ‰์„ธ๋ถ€ ์ •๋ณด ํŽผ์น˜๊ธฐ ; ์‚ฌ์šฉ์ž ๋ฐ์ดํ„ฐ :

#!/bin/bash
yum update -y
yum install -y ruby
curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto

->codedeploy ์—์ด์ „ํŠธ ์„ค์น˜ ํ•„์š”.
(ec2๊ฐ€ ์ฝ”๋“œ๋””ํ”Œ๋กœ์ด๋กœ๋ถ€ํ„ฐ ์˜ค๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›๊ธฐ ์œ„ํ•ด.)

-> ์‹œ์ž‘ ๊ตฌ์„ฑ ์ƒ์„ฑ ํด๋ฆญ

โœ”๏ธ๋‹ค์‹œ ์™ผ์ชฝ ec2 ๋ฉ”๋‰ด์—์„œ - auto scaling ๊ทธ๋ฃน - auto scaling ๊ทธ๋ฃน ์ƒ์„ฑ

โœ”๏ธ์ด๋ฆ„ : my-asg, ํ•˜๋‹จ์— ์‹œ์ž‘ ๊ตฌ์„ฑ์œผ๋กœ ์ „ํ™˜ ํด๋ฆญ , ๋งŒ๋“ค์–ด๋‘” ์‹œ์ž‘ ๊ตฌ์„ฑ ์„ ํƒ (my-lc)

โœ”๏ธ๋„คํŠธ์›Œํฌ MY-VPC , ํผ๋ธ”๋ฆญ ์„œ๋ธŒ๋„ท ์„ ํƒ (A,C)

โœ”๏ธ ์ƒˆ ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ์— ์—ฐ๊ฒฐ - ์œ ํ˜• : ALB - ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ ์ด๋ฆ„ : my-asg-alb - ์ฒด๊ณ„ ; internet-facing (์ธํ„ฐ๋„ท ๋ฐฐํฌ ์šฉ์ด๋‹ˆ๊นŒ) - ์•„๊นŒ ์„ ํƒํ•ด๋‘” ๋„คํŠธ์›Œํฌ ํ™•์ธ - ๋ฆฌ์Šค๋„ˆ ๋ฐ ๋ผ์šฐํŒ… - ๋Œ€์ƒ๊ทธ๋ฃน์ƒ์„ฑ ; ์ด๋ฆ„ : my-asg-tg

๋‚˜๋จธ์ง€ default, ๋‹ค์Œ
์ƒํƒœํ™•์ธ elb๋กœ ํ•˜๋ฉด ๋ณด๋‹ค์ •ํ™•ํ•˜๊ณ  ์ž์„ธํ•œ ์ƒํƒœํ™•์ธ ๊ฐ€๋Šฅ. ํ•˜์ง€๋งŒ ์ง€๊ธˆ ์šฐ๋ฆฌ deploy์ผ€์ด์Šค์—์„œ๋Š” ๋งž์ง€ ์•Š์•„์„œ ec2๋กœ ๊ทธ๋Œ€๋กœ ๋‘๊ฒ ์Œ. (deploy ๋ฐฐํฌ ํ…€์ค‘์— ์ƒํƒœํ™•์ธ๋˜๋ฉด ๊ณค๋ž€)

โœ”๏ธ ๊ทธ๋ฃนํฌ๊ธฐ ์„ค์ • - ๋‹ค์Œ

โœ”๏ธ ๋‹ค skipํ•˜๊ณ  , auto scaling ๊ทธ๋ฃน ์ƒ์„ฑ ํด๋ฆญ
ํฌ๊ธฐ์กฐ์ •์ •์ฑ… ๋‚˜์ค‘์—

โœ”๏ธ ์˜คํ† ์Šค์ผ€์ผ๋ง ์„ ํƒํ•ด์„œ ์ •๋ณด ๋ณด๊ธฐ

๐Ÿ“™ cloud9


ํด๋” ์ƒ์„ฑ ; codedeploy


ํŒŒ์ผ ์ƒ์„ฑ ;index.html

index.html ํŒŒ์ผ ์•ˆ์— ๋‚ด์šฉ ๋„ฃ์–ด์ฃผ๊ธฐ

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Sample Deployment</title>
  <style>
    body {
      color: #ffffff;
      background-color: #0188cc;
      font-family: Arial, sans-serif;
      font-size: 14px;
    }
    h1 {
      font-size: 500%;
      font-weight: normal;
      margin-bottom: 0;
    }
    h2 {
      font-size: 200%;
      font-weight: normal;
      margin-bottom: 0;
    }
  </style>
</head>
<body>
  <div align="center">
    <h1>Congratulations</h1>
    <h2>This application was deployed using AWS CodeDeploy.</h2>
    <p>For next steps, read the <a href="http://aws.amazon.com/documentation/codedeploy">AWS CodeDeploy Documentation</a>.</p>
  </div>
</body>
</html>


ํŒŒ์ผ์ƒ์„ฑ ; appspec.yml
์•„๋ž˜ ๋‚ด์šฉ ๋„ฃ์–ด์ฃผ๊ธฐ

version: 0.0
os: linux
files:
  - source: /index.html
    destination: /var/www/html/
hooks:
  BeforeInstall:
    - location: scripts/install_dependencies
      timeout: 300
      runas: root
    - location: scripts/start_server
      timeout: 300
      runas: root
  ApplicationStop:
    - location: scripts/stop_server
      timeout: 300
      runas: root

ํด๋”์ƒ์„ฑ ;scripts , ์•ˆ์—install_dependencies,start_server,stop_server ํŒŒ์ผ ์ƒ์„ฑ

๋‚ด์šฉ ;

vi install_dependencies
#!/bin/bash
yum install -y httpd

vi start_server
#!/bin/bash
systemctl start httpd

vi stop_server
#!/bin/bash
isExistApp = `pgrep httpd`
if [[ -n $isExistApp ]]; then
     systemctl stop httpd
fi

๐Ÿ“ข ํ™•์žฅ์ž๋ช… ์—†๋Š” ํŒŒ์ผ์ƒ์„ฑ์€ GUI์—์„œ ์ƒ์„ฑ X CLI์—์„œ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”. ์ธ์ฝ”๋”ฉ์— ๋ฌธ์ œ ์ƒ๊น€.

โœ”๏ธํŒŒ์ผ ์••์ถ• ๋ฐ s3๋กœ ๋ณด๋‚ด๊ธฐ , ํ™•์ธ

# zip -r codedeploy-sample.zip *
# aws s3 cp codedeploy-sample.zip s3://s3.lovemj.shop

ec2-user:~/environment/codedeploy $ aws s3 ls s3://s3.lovemj.shop
                           PRE static/
2022-08-19 07:27:06       1676 codedeploy-sample.zip
2022-08-19 05:25:42        516 index.html

๐Ÿ“™ code deploy

code deploy - ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ - ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ƒ์„ฑ

๋ฐฐํฌ๊ทธ๋ฃน ์ƒ์„ฑ - ์ด๋ฆ„ : my-dg - ์„œ๋น„์Šค ์—ญํ•  : codedeployrole - ํ™˜๊ฒฝ ๊ตฌ์„ฑ : Amazon ec2 ์˜คํ† ์Šค์ผ€์ผ๋ง ๊ทธ๋ฃน ;๋งŒ๋“ค์–ด๋‘” my-asg ์„ ํƒ

๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ - ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ ํ™œ์„ฑํ™” ํ•ด์ œ - ๋ฐฐํฌ๊ทธ๋ฃน์ƒ์„ฑ

๋ฐฐํฌ ์ƒ์„ฑ - ์•„๋ž˜์™€ ๊ฐ™์ด ์ž…๋ ฅ , ๋ฐฐํฌ๋งŒ๋“ค๊ธฐ ํด๋ฆญ

-> ๋ฐฐํฌ ์™„๋ฃŒ

๐Ÿ“™ ALB์—์„œ ์ฃผ์†Œ ํ™•์ธ


์›นํŽ˜์ด์ง€ ์ ‘๊ทผ ํ™•์ธ

์ฃผ์†Œ ๊ฐ„์†Œํ™”

๐Ÿ“™ index ํŒŒ์ผ ์ˆ˜์ •

ec2-user:~/environment/codedeploy $ rm -rf codedeploy-sample.zip 
ec2-user:~/environment/codedeploy $ zip -r codedeploy-sample.zip *
  adding: appspec.yml (deflated 53%)
  adding: index.html (deflated 47%)
  adding: scripts/ (stored 0%)
  adding: scripts/install_dependencies (stored 0%)
  adding: scripts/start_server (stored 0%)
  adding: scripts/stop_server (deflated 15%)
ec2-user:~/environment/codedeploy $ ll
total 12
-rw-r--r-- 1 ec2-user ec2-user  357 Aug 19 07:09 appspec.yml
-rw-rw-r-- 1 ec2-user ec2-user 1685 Aug 19 08:08 codedeploy-sample.zip
-rw-r--r-- 1 ec2-user ec2-user  732 Aug 19 08:06 index.html
drwxr-xr-x 2 ec2-user ec2-user   73 Aug 19 07:19 scripts
ec2-user:~/environment/codedeploy $ aws s3 cp codedeploy-sample.zip s3://s3.lovemj.shop
upload: ./codedeploy-sample.zip to s3://s3.lovemj.shop/codedeploy-sample.zip
ec2-user:~/environment/codedeploy $ aws s3 ls s3://s3.lovemj.shop
                           PRE static/
2022-08-19 08:10:14       1685 codedeploy-sample.zip
2022-08-19 05:25:42        516 index.html


๋ฐฐํฌ์žฌ์‹œ๋„ ํด๋ฆญ


์›นํŽ˜์ด์ง€์—์„œ ๋ฐ”๋€ ๊ฒƒ ํ™•์ธ

๐Ÿ“Œ pipeline

๐Ÿ“™ ์‚ฌ์šฉ์ž์„ค์ •

์‚ฌ์šฉ์ž - ๋งŒ๋“ค์–ด๋‘”๊ฒƒ ์„ ํƒ - ๊ถŒํ•œ์ถ”๊ฐ€

๊ธฐ์กด์ •์ฑ…์ง์ ‘์—ฐ๊ฒฐ-AWSCodePipeline_FullAccess ์„ ํƒ - ๋‹ค์Œ (์™„๋ฃŒ)

๐Ÿ“™ โœ”๏ธ-โœ๏ธ๐Ÿ“ขโญ๏ธ๐Ÿ“Œ

๐Ÿ“Œ ๊ธฐํƒ€

โญ๏ธ aws git ์ž๊ฒฉ์ฆ๋ช…

aws configure

git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.useHttpPath true
profile
๊พธ์ค€ํžˆ, ์ฐจ๊ทผ์ฐจ๊ทผ

0๊ฐœ์˜ ๋Œ“๊ธ€