-
-
Save darkredz/92ae99a1a93d924d0539d2db28d46040 to your computer and use it in GitHub Desktop.
Revisions
-
jlis created this gist
May 15, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ image: docker:latest variables: REPOSITORY_URL: <AWS ACCOUNT ID>.dkr.ecr.eu-central-1.amazonaws.com/<ECS REPOSITORY NAME> REGION: eu-central-1 TASK_DEFINTION_NAME: <TASK DEFINITION NAME> CLUSTER_NAME: <CLUSTER NAME> SERVICE_NAME: <SERVICE NAME> services: - docker:dind before_script: - apk add --no-cache curl jq python py-pip - pip install awscli - $(aws ecr get-login --no-include-email --region "${REGION}") - IMAGE_TAG="$(echo $CI_COMMIT_SHA | head -c 8)" stages: - build - deploy build: stage: build script: - echo "Building image..." - docker build -t $REPOSITORY_URL:latest . - echo "Tagging image..." - docker tag $REPOSITORY_URL:latest $REPOSITORY_URL:$IMAGE_TAG - echo "Pushing image..." - docker push $REPOSITORY_URL:latest - docker push $REPOSITORY_URL:$IMAGE_TAG only: - master deploy: stage: deploy script: - echo $REPOSITORY_URL:$IMAGE_TAG - TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition "$TASK_DEFINTION_NAME" --region "${REGION}") - NEW_CONTAINER_DEFINTIION=$(echo $TASK_DEFINITION | python $CI_PROJECT_DIR/update_task_definition_image.py $REPOSITORY_URL:$IMAGE_TAG) - echo "Registering new container definition..." - aws ecs register-task-definition --region "${REGION}" --family "${TASK_DEFINTION_NAME}" --container-definitions "${NEW_CONTAINER_DEFINTIION}" - echo "Updating the service..." - aws ecs update-service --region "${REGION}" --cluster "${CLUSTER_NAME}" --service "${SERVICE_NAME}" --task-definition "${TASK_DEFINTION_NAME}" only: - master This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ import sys, json, argparse parser = argparse.ArgumentParser('Replaces image in the task definition') parser.add_argument('image_uri', metavar='I', type=str, nargs='+', help='The new image URI') args = parser.parse_args() definition = json.load(sys.stdin)['taskDefinition']['containerDefinitions'] definition[0]['image'] = args.image_uri[0] print json.dumps(definition)