| 1 | version: 0.2 |
| 2 | parameter-store: |
| 3 | build_ssh_key: "/CodeBuild/emobility_build_ssh_key" |
| 4 | phases: |
| 5 | install: |
| 6 | runtime-versions: |
| 7 | docker: 19 |
| 8 | pre_build: |
| 9 | commands: |
| 10 | - mkdir -p ~/.ssh |
| 11 | - if [ -z ${build_ssh_key} ]; then echo "missing build_ssh_key store parameter, exiting"; exit 1; fi |
| 12 | - echo "${build_ssh_key}" > ~/.ssh/id_rsa |
| 13 | - chmod 600 ~/.ssh/id_rsa |
| 14 | - ssh-keygen -F github.com || ssh-keyscan github.com >> ~/.ssh/known_hosts |
| 15 | - git config --global url."git@github.com:".insteadOf "https://github.com/" |
| 16 | - git init |
| 17 | - git remote remove origin || true |
| 18 | - if [ -z ${remote_origin} ]; then echo "missing remote_origin env variable, exiting"; exit 1; fi |
| 19 | - git remote add origin ${remote_origin} |
| 20 | - git fetch |
| 21 | - if [ -z $branch_name ]; then echo "missing branch_name env variable, exiting"; exit 1; fi |
| 22 | - git checkout -f ${branch_name} |
| 23 | - git branch --set-upstream-to origin/${branch_name} |
| 24 | - git reset --hard origin/${branch_name} |
| 25 | - git submodule update --init --recursive |
| 26 | build: |
| 27 | commands: |
| 28 | - echo Build and push started on `date` |
| 29 | - echo Building and pushing the Docker image... |
| 30 | - cd docker && make DOCKER_ECR_ACCOUNT_ID=$AWS_ACCOUNT_ID DOCKER_ECR_REGION=$AWS_DEFAULT_REGION DOCKER_ECR_REGISTRY_NAME=$IMAGE_REPO_NAME DOCKER_ECR_TAG=$IMAGE_TAG docker-push-ecr && cd .. |
| 31 | post_build: |
| 32 | commands: |
| 33 | - echo Build and push completed on `date` |
| 34 | - echo Writing image definitions file... |
| 35 | - printf '[{"name":"%s","imageUri":"%s"}]' $ECS_CONTAINER_NAME $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG > imagedefinitions.json |
| 36 | artifacts: |
| 37 | files: imagedefinitions.json |