Codebuild Buildspec.yml File 조건문 사용

Hoju·2022년 8월 24일

혹시 그거 아시나요? Codebuild 같은 경우는 buildspec.yml 파일을 사용해서 빌드/ 테스트를 진행합니다. 그런데 이런 생각도 되죠? 어? 환경에서 운영 체제를 Linux 기반에 운영 체제를 사용하는데 Shell Scripting도 가능할까?
정답은? "네 가능합니다" 어떻게 작성해야하는지 아래 확인을 해주시면 됩니다.

https://lxstitch.tistory.com/65 < 이 분이 정말 잘 Shell script IF문에 대해서 설명이 너무 좋으시네용

version: 0.2

phases:
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...  

      - |

        if [[ -e Dockerfile ]]; then

           docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .

        else

            echo "No Dockerfile"

        fi
      - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG      
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker image...
      - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG

중요한 점은 if 옆에 오는 대괄호는 [ (하나)가 아닌 [[ (두개) 여야합니다.

  1. 실행 결과

  2. 없다면?

profile
Devops가 되고 싶은 청소년

0개의 댓글