Guest User

Untitled

a guest
May 20th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. image: docker:latest
  2.  
  3. variables:
  4. REPOSITORY_URL: <AWS ACCOUNT ID>.dkr.ecr.eu-central-1.amazonaws.com/<ECS REPOSITORY NAME>
  5. REGION: eu-central-1
  6. TASK_DEFINTION_NAME: <TASK DEFINITION NAME>
  7. CLUSTER_NAME: <CLUSTER NAME>
  8. SERVICE_NAME: <SERVICE NAME>
  9.  
  10. services:
  11. - docker:dind
  12.  
  13. before_script:
  14. - apk add --no-cache curl jq python py-pip
  15. - pip install awscli
  16. - $(aws ecr get-login --no-include-email --region "${REGION}")
  17. - IMAGE_TAG="$(echo $CI_COMMIT_SHA | head -c 8)"
  18.  
  19. stages:
  20. - build
  21. - deploy
  22.  
  23. build:
  24. stage: build
  25. script:
  26. - echo "Building image..."
  27. - docker build -t $REPOSITORY_URL:latest .
  28. - echo "Tagging image..."
  29. - docker tag $REPOSITORY_URL:latest $REPOSITORY_URL:$IMAGE_TAG
  30. - echo "Pushing image..."
  31. - docker push $REPOSITORY_URL:latest
  32. - docker push $REPOSITORY_URL:$IMAGE_TAG
  33. only:
  34. - master
  35.  
  36. deploy:
  37. stage: deploy
  38. script:
  39. - echo $REPOSITORY_URL:$IMAGE_TAG
  40. - TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition "$TASK_DEFINTION_NAME" --region "${REGION}")
  41. - NEW_CONTAINER_DEFINTIION=$(echo $TASK_DEFINITION | python $CI_PROJECT_DIR/update_task_definition_image.py $REPOSITORY_URL:$IMAGE_TAG)
  42. - echo "Registering new container definition..."
  43. - aws ecs register-task-definition --region "${REGION}" --family "${TASK_DEFINTION_NAME}" --container-definitions "${NEW_CONTAINER_DEFINTIION}"
  44. - echo "Updating the service..."
  45. - aws ecs update-service --region "${REGION}" --cluster "${CLUSTER_NAME}" --service "${SERVICE_NAME}" --task-definition "${TASK_DEFINTION_NAME}"
  46. only:
  47. - master
Add Comment
Please, Sign In to add comment