Git Product home page Git Product logo

circleci-demo-aws-ecs-ecr's Introduction

CircleCI Demo: AWS ECS ECR CircleCI status

Deploy to AWS ECS from ECR via CircleCI 2.0 using Orbs (Example Project)

This project provides an example of how to use orbs to conveniently build a Docker image on CircleCI, push the Docker image to an Amazon Elastic Container Registry (ECR), and then deploy to Amazon Elastic Container Service (ECS) using AWS Fargate. Specifically, the aws-ecr and the aws-ecs Orbs will be used in this project.

A tutorial walkthrough is available for the project at https://circleci.com/docs/2.0/ecs-ecr/

Alternative branches

Prerequisites

Set up required AWS resources

Builds of this project rely on AWS resources to be present in order to succeed. For convenience, the prerequisite AWS resources may be created using the terraform scripts procided in the terraform_setup directory.

  1. Ensure terraform is installed on your system.
  2. Edit terraform_setup/terraform.tfvars to fill in the necessary variable values (an Amazon account with sufficient privileges to create resources like an IAM account, VPC, EC2 instances, Elastic Load Balancer, etc is required). (It is not advisable to commit this file to a public repository after it has been populated with your AWS credentials)
  3. Use terraform to create the AWS resources
    cd terraform_setup
    terraform init
    # Review the plan
    terraform plan
    # Apply the plan to create the AWS resources
    terraform apply
    
  4. You can run terraform destroy to destroy most of the created AWS resources but in case of lingering undeleted resources, it is recommended to check the AWS Management Console to see if there are any remaining undeleted resources to avoid unwanted costs. In particular, please check the ECS, CloudFormation and VPC pages.

Configure environment variables on CircleCI

The following environment variables must be set for the project on CircleCI via the project settings page, before the project can be built successfully.

Variable Description
AWS_ACCESS_KEY_ID Used by the AWS CLI
AWS_SECRET_ACCESS_KEY Used by the AWS CLI
AWS_DEFAULT_REGION Used by the AWS CLI. Example value: "us-east-1" (Please make sure the specified region is supported by the Fargate launch type)
AWS_ACCOUNT_ID AWS account id. This information is required for deployment.
AWS_RESOURCE_NAME_PREFIX Prefix that some of the required AWS resources are assumed to have in their names. The value should correspond to the aws_resource_prefix variable value in terraform_setup/terraform.tfvars.

Useful Links & References

circleci-demo-aws-ecs-ecr's People

Contributors

cdrn avatar lokst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

circleci-demo-aws-ecs-ecr's Issues

AWS provider no longer compatible with latest version of terraform

Hi,

The provider constraints within this project version = "~> 1.35" unfortunately is no longer compatible with the later versions of terraform.

Error given:

terraform init    

Initializing the backend...

Initializing provider plugins...
- Checking for available provider plugins...

Provider {"aws"} v1.60.0 is not compatible with Terraform 0.12.9.

Provider version 2.7.0 is the earliest compatible version. Select it with 
the following version constraint:

	version = "~> 2.7"

Terraform checked all of the plugin versions matching the given constraint:
    ~> 1.35

Consult the documentation for this provider for more information on
compatibility between provider and Terraform versions.


Error: incompatible provider version

Changing the version number to "~> 2.0" seems to work however.

CannotPullContainerError: Error response from daemon: manifest for not found

I tried to build a project from master branch.
Terraform part - successful
Circle CI part - successfull in GUI
Though, when I go to ECS console and check tasks > they are continuosly failing with error :

CannotPullContainerError: Error response from daemon: manifest for nginx:0f6b3cdf5e24f0da3dd932acd84fd90e9786a522 not found

Tried to reproduce this with ECR locally on my own server and same error was in case I try to perform docker run with image which docker can't find locally
So, at the end after modifying to :
docker run -it --name ccitt1 8xxxxxxxxxxxxxxx.dkr.ecr.us-xxxx-x.amazonaws.com/cci:0f6b3cdf5e24f0da3dd932acd84fd90e9786a522 /bin/sh

I was able to run it
No files from repo were modified other than terraform + project setting modified in gui + workflow itself is succesfull

I guess task definition is made under the hood in build & deploy? Or this is something specific to ECS/Fargate?
Last time master was built 1 month ago

Update1:
Within task definition in ECS, i see in json following :

"stopTimeout": null,
      "image": "nginx:0f6b3cdf5e24f0da3dd932acd84fd90e9786a522",
      "startTimeout": null,

I think this is an issue, as naming for image should be AWS specific and not nginx to be build properly by fargate . Found couple other people on web having same error because of invalid tag. Failed to Pull container error (400) from ECR API
Update2:
In GUI, checked configuration for workflow (deploy-service-update) :
PREVIOUS_TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition ${AWS_RESOURCE_NAME_PREFIX}-service)
CONTAINER_IMAGE_NAME_UPDATES="$(echo container=${AWS_RESOURCE_NAME_PREFIX}-service,tag=${CIRCLE_SHA1})"

Provided terraform script builds task with nginx by default.
So, maybe this is not coincidense and some transformation error in workflow within lines 172 - 213

Thanks ,
Vladyslav

How to pass environment variables from env file

In public-service.yml file i want to pass environment variables from local.env file instead of keyvalue pair. How to do that?
ContainerDefinitions:
- Name: !Ref 'ServiceName'
Image: !Ref 'ImageUrl'
Essential: true
Command: ['./apiserv']
PortMappings:
- ContainerPort: !Ref 'ContainerPort'
Environment:
- Name:
Value

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.