Misc

2과제 스크립트와 파일들

Ani Gil 2021. 10. 5. 18:11

pre_builds.sh

#!/bin/bash

 

FILE_NAME=`ls Dockerfile`

 

if [ $FILE_NAME = "Dockerfile" ]

then    # Dockerfile이 존재하는 경우

    (ECR Docker commands)

else    # Dockerfile이 존재하지 않는 경우

    pip3 install flask

fi

 

builds.sh

#!/bin/bash

 

FILE_NAME=`ls Dockerfile`

 

if [ $FILE_NAME = "Dockerfile" ]

then    # Dockerfile이 존재하는 경우

    (ECR Docker commands)

else    # Dockerfile이 존재하지 않는 경우

    python3 ./app.py &

fi

 

post_builds.sh

#!/bin/bash

 

FILE_NAME=`ls Dockerfile`

 

if [ $FILE_NAME = "Dockerfile" ]

then    # Dockerfile이 존재하는 경우

    (ECR Docker commands)    # ECR Repository로 Push

else    # Dockerfile이 존재하지 않는 경우

    kill -9 `pgrep -f app.py`   # app.py가 작동 중이면 kill을 함

    echo "Test Successfully"    # 성공적으로 테스트가 끝났다는 메시지

fi

 

ApplicationStop.sh

#!/bin/bash

isExistApp=`pgrep -f app.py`

if [[ -n $isExistApp ]]; then

    kill -9 `pgrep -f app.py`

fi

 

BeforeInstall.sh

#!/bin/bash

rm /home/ec2-user/app.py

 

appspec.yml

version0.0

oslinux

files:

  - source/app.py

    destination/home/ec2-user

hooks:

  ApplicationStop:

    - locationscripts/ApplicationStop.sh

      timeout300

      runasroot

  BeforeInstall:

    - locationscripts/BeforeInstall.sh

      timeout300

      runasroot

#  AfterInstall:

#    - location: scripts/AfterInstall.sh

#      timeout: 300

#      runas: root

#  ApplicationStart:

#    - location: scripts/ApplicationStart.sh

#      timeout: 300

#      runas: root

 

buildspec.yml

version0.2

 

phases:

  install:

    runtime-version:

      python3.8

  pre_build:

    commands:

      - ./codebuild/pre_builds.sh

  build:

    commands:

      - ./codebuild/builds.sh

  post_build:

    commands:

      - ./codebuild/post_builds.sh

artifacts:

  files:

    - '**/*'

#  base-directory: base_dir

#  name: worldskillsPipline

#  discard-paths: no

 

Dockerfile

FROM amazonlinux

COPY ./app.py /app.py

COPY ./start.sh /start.sh

RUN yum -y update

RUN yum -y install python3

RUN pip3 install flask

ENTRYPOINT ["/bin/bash""/start.sh"]

 

start.sh

#!/bin/bash
python3 /app.py