Skip to content

Commit cbdc2d5

Browse files
committed
Initial commit
0 parents  commit cbdc2d5

930 files changed

Lines changed: 477579 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ecs-cli/out/
2+
bin/
3+
*.swp
4+
*.orig
5+
ecs-cli/vendor/pkg

LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the
4+
License. A copy of the License is located at
5+
6+
http://aws.amazon.com/apache2.0/
7+
8+
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9+
CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
10+
and limitations under the License.
11+
12+
***
13+
14+
Note: Other license terms may apply to certain, identified software files contained within or distributed with the accompanying software if such terms are included in the directory containing the accompanying software. Such other license terms will then apply in lieu of the terms of the software license above.
15+

Makefile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
14+
ROOT := $(shell pwd)
15+
16+
all: generate build
17+
18+
SOURCEDIR=./ecs-cli
19+
SOURCES := $(shell find $(SOURCEDIR) -name '*.go')
20+
LOCAL_BINARY=bin/local/ecs-cli
21+
LINUX_BINARY=bin/linux-amd64/ecs-cli
22+
DARWIN_BINARY=bin/darwin-amd64/ecs-cli
23+
24+
.PHONY: build
25+
build: $(LOCAL_BINARY)
26+
27+
$(LOCAL_BINARY): $(SOURCES)
28+
. ./scripts/shared_env && ./scripts/build_binary.sh ./bin/local
29+
@echo "Built ecs-cli"
30+
31+
.PHONY: test
32+
test: generate
33+
. ./scripts/shared_env && go test -timeout=120s -v -cover github.com/aws/amazon-ecs-cli/ecs-cli/modules/...
34+
35+
.PHONY: generate
36+
generate: $(SOURCES)
37+
. ./scripts/shared_env && go install github.com/golang/mock/mockgen && go generate github.com/aws/amazon-ecs-cli/ecs-cli/modules/...
38+
39+
.PHONY: docker-build
40+
docker-build:
41+
docker run -v $(shell pwd):/usr/src/app/src/github.com/aws/amazon-ecs-cli \
42+
--workdir=/usr/src/app/src/github.com/aws/amazon-ecs-cli \
43+
--env GOPATH=/usr/src/app \
44+
golang:1.4-cross make $(LINUX_BINARY)
45+
docker run -v $(shell pwd):/usr/src/app/src/github.com/aws/amazon-ecs-cli \
46+
--workdir=/usr/src/app/src/github.com/aws/amazon-ecs-cli \
47+
--env GOPATH=/usr/src/app \
48+
golang:1.4-cross make $(DARWIN_BINARY)
49+
50+
.PHONY: supported-platforms
51+
supported-platforms: $(LINUX_BINARY) $(DARWIN_BINARY)
52+
53+
$(LINUX_BINARY): $(SOURCES)
54+
@mkdir -p ./bin/linux-amd64
55+
. ./scripts/shared_env && TARGET_GOOS=linux GOARCH=amd64 ./scripts/build_binary.sh ./bin/linux-amd64
56+
@echo "Built ecs-cli for linux"
57+
58+
$(DARWIN_BINARY): $(SOURCES)
59+
@mkdir -p ./bin/darwin-amd64
60+
. ./scripts/shared_env && TARGET_GOOS=darwin GOARCH=amd64 ./scripts/build_binary.sh ./bin/darwin-amd64
61+
@echo "Built ecs-cli for darwin"
62+
63+
.PHONY: clean
64+
clean:
65+
rm -rf ./ecs-cli/vendor/pkg ||:
66+
rm -rf ./bin/ ||:
67+
rm -rf ./ecs-cli/vendor/bin ||:

NOTICE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Amazon ECS Command Line Interface
2+
Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.

README.md

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# Amazon ECS CLI
2+
3+
The ECS Command Line Interface (ECS CLI) is a command line interface for Amazon
4+
EC2 Container Service (ECS) that provides high level commands to simplify
5+
creating, updating, and monitoring clusters and tasks from a local development
6+
environment. The Amazon ECS CLI supports
7+
[Docker Compose](https://docs.docker.com/compose/), a popular open-source tool
8+
for defining and running multi-container applications. Use the ECS CLI as part
9+
of your everyday development and testing cycle as an alternative to the AWS
10+
Management Console.
11+
12+
For more information about Amazon ECS, see the
13+
[Amazon ECS Developer Guide](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html).
14+
For information about installing and using the ECS CLI, see the
15+
[ECS Command Line Interface](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI.html).
16+
17+
The AWS Command Line Interface (AWS CLI) is a unified client for AWS services
18+
that provides commands for all public API operations. These commands are lower
19+
level than those provided by the ECS CLI. For more information about supported
20+
services and to download the AWS Command Line Interface, see the
21+
[AWS Command Line Interface](http://aws.amazon.com/cli/) product detail page.
22+
23+
## Installing
24+
25+
Download the binary archive for your platform, decompress the archive, and
26+
install the binary on your `$PATH`. You can use the provided `md5` hash to
27+
verify the integrity of your download.
28+
29+
* Linux:
30+
* [https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest](https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest)
31+
* [https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest.md5](https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest.md5)
32+
* Macintosh:
33+
* [https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-darwin-amd64-latest](https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-darwin-amd64-latest)
34+
* [https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-darwin-amd64-latest.md5](https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-darwin-amd64-latest.md5)
35+
* Windows:
36+
* (Not yet implemented)
37+
38+
## Configuring the CLI
39+
40+
Before using the CLI, you need to configure your AWS credentials, the AWS
41+
region in which to create your cluster, and the name of the ECS cluster to use
42+
with the `ecs-cli configure` command. These settings are stored in
43+
`~/.ecs/config`. You can use any existing AWS named profiles in
44+
`~/.aws/credentials` for your credentials with the `--profile` option.
45+
46+
```
47+
$ ecs-cli help configure
48+
NAME:
49+
configure - Configures your AWS credentials, the AWS region to use, and the EC2 Container Service cluster name to use with the ECS CLI.
50+
51+
USAGE:
52+
command configure [command options] [arguments...]
53+
54+
OPTIONS:
55+
--region, -r Specify the AWS Region to use. [$AWS_REGION]
56+
--access-key Specify the AWS access key to use. [$AWS_ACCESS_KEY_ID]
57+
--secret-key Specify the AWS secret key to use. [$AWS_SECRET_ACCESS_KEY]
58+
--profile, -p Specify your AWS credentials with an existing named profile from ~/.aws/credentials. [$AWS_PROFILE]
59+
--cluster, -c Specify the ECS cluster name to use. If the cluster does not exist, it will be created.
60+
```
61+
62+
## Using the CLI
63+
After installing the ECS CLI and configuring your credentials, you are ready to
64+
create an ECS cluster using the ECS CLI.
65+
66+
```
67+
$ ecs-cli help up
68+
NAME:
69+
up - Create the ECS Cluster (if it does not already exist) and the AWS resources required to set up the cluster.
70+
71+
USAGE:
72+
command up [command options] [arguments...]
73+
74+
OPTIONS:
75+
--keypair Specify the name of an existing Amazon EC2 key pair to enable SSH access to the EC2 instances in your cluster.
76+
--capability-iam Acknowledge that this command may create IAM resources.
77+
--size [Optional] Specify the number of instances to register to the cluster. The default is 1.
78+
--azs [Optional] Specify a comma-separated list of 2 VPC availability zones in which to create subnets (these AZs must be in the 'available' status). This option is recommended if you do not specify a VPC ID with the --vpc option. WARNING: Leaving this option blank can result in failure to launch container instances if an unavailable AZ is chosen at random.
79+
--security-group [Optional] Specify an existing security group to associate it with container instances. Defaults to creating a new one.
80+
--cidr [Optional] Specify a CIDR/IP range for the security group to use for container instances in your cluster. Defaults to 0.0.0.0/0 if --security-group is not specified
81+
--port [Optional] Specify a port to open on a new security group that is created for your container instances if an existing security group is not specified with the --security-group option. Defaults to port 80.
82+
--subnets [Optional] Specify a comma-separated list of existing VPC Subnet IDs in which to launch your container instances. This option is required if you specify a VPC with the --vpc option.
83+
--vpc [Optional] Specify the ID of an existing VPC in which to launch your container instances. If you specify a VPC ID, you must specify a list of existing subnets in that VPC with the --subnets option. If you do not specify a VPC ID, a new VPC is created with two subnets.
84+
--instance-type [Optional] Specify the EC2 instance type for your container instances.
85+
```
86+
87+
For example, to create an ECS cluster with two Amazon EC2 instances:
88+
89+
```
90+
$ ecs-cli up --keypair my-key --capability-iam --size 2
91+
```
92+
93+
It will take a few minutes to create the resources requested by `ecs-cli up`.
94+
To see when the cluster is ready to run tasks you can use the AWS CLI to
95+
confirm the ECS instances are registered:
96+
97+
98+
```
99+
$ aws ecs list-container-instances --cluster your-cluster-name
100+
{
101+
"containerInstanceArns": [
102+
"arn:aws:ecs:us-east-1:980116778723:container-instance/6a302e06-0aa6-4bbc-9428-59b17089b887",
103+
"arn:aws:ecs:us-east-1:980116778723:container-instance/7db3c588-0ef4-49fa-be32-b1e1464f6eb5",
104+
]
105+
}
106+
107+
```
108+
109+
**Note:** The default security group created by `ecs-cli up` allows inbound
110+
traffic on port 80 by default. To allow inbound traffic from a different port,
111+
specify the port you wish to open with the `--port` option. To add more ports
112+
to the default security group, go to EC2 Security Groups in the AWS Management
113+
Console and search for the security group with “ecs-cli”. Add a rule as
114+
described in
115+
[the documentation]( http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-network-security.html#adding-security-group-rule).
116+
Alternatively, you may specify an existing security group ID with the
117+
`--security-group` option.
118+
119+
Once the cluster is created you can run tasks – groups of containers – on the
120+
ECS cluster. First, author a
121+
[Docker Compose configuration file]( https://docs.docker.com/compose).
122+
You can run the configuration file locally using Docker Compose. Here is an
123+
example Docker Compose configuration file that creates a web page:
124+
125+
```
126+
web:
127+
image: amazon/amazon-ecs-sample
128+
ports:
129+
- "80:80"
130+
```
131+
132+
To run the configuration file on Amazon ECS use `ecs-cli compose up`. This
133+
creates an ECS task definition and starts an ECS task. You can see the task
134+
that is running with `ecs-cli compose ps`, for example:
135+
136+
```
137+
$ ecs-cli compose ps
138+
Name State Ports
139+
fd8d5a69-87c5-46a4-80b6-51918092e600/web RUNNING 54.209.244.64:80->80/tcp
140+
```
141+
142+
Navigate your web browser to the task’s IP address to see the sample app
143+
running in the ECS cluster.
144+
145+
You can also run tasks as services. The ECS service scheduler ensures that the
146+
specified number of tasks are constantly running and reschedules tasks when a
147+
task fails (for example, if the underlying container instance fails for some
148+
reason).
149+
150+
```
151+
$ ecs-cli compose --project-name wordpress-test service create
152+
153+
INFO[0000] Using Task definition TaskDefinition=ecscompose-wordpress-test:1
154+
INFO[0000] Created an ECS Service serviceName=ecscompose-service-wordpress-test taskDefinition=ecscompose-wordpress-test:1
155+
156+
```
157+
158+
You can then start the tasks in your service with the following command:
159+
`$ ecs-cli compose --project-name wordpress-test service start`
160+
161+
It may take a minute for the tasks to start. You can monitor the progress using
162+
this command:
163+
```
164+
$ ecs-cli compose --project-name wordpress-test service ps
165+
Name State Ports
166+
34333aa6-e976-4096-991a-0ec4cd5af5bd/mysql RUNNING
167+
34333aa6-e976-4096-991a-0ec4cd5af5bd/wordpress RUNNING 54.186.138.217:80->80/tcp
168+
```
169+
170+
171+
## ECS CLI Commands
172+
173+
For a complete list of commands, see the
174+
[ECS CLI documentation](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI.html).
175+
176+
177+
## Building the CLI
178+
### Developing
179+
180+
Running ``scripts/vendor.sh`` creates/updates the vedor/ directory with
181+
dependencies.
182+
183+
For developing code, the correct GOPATH can be printed by running
184+
`./scripts/shared_env` script.
185+
186+
This can be set as GOPATH on the dev box.
187+
188+
### Building
189+
190+
Running `make build` creates a standalone executable in the `bin/local`
191+
directory
192+
193+
```bash
194+
$ pwd
195+
/home/ubuntu/github/src/github.com/aws/amazon-ecs-cli
196+
$ make build
197+
$ ls bin/local
198+
ecs-cli
199+
```
200+
201+
### Cross-compiling
202+
203+
The `make docker-build` target will build standalone amd64 executables for
204+
darwin and linux. The output will be in `bin/darwin-amd64` and `bin/linux-amd64`
205+
respectively.
206+
207+
If you have set up the appropriate bootstrap environments, you may also directly
208+
run the `make supported-platforms` target to create standalone amd64 executables
209+
for darwin and linux platforms.
210+
211+
## Testing
212+
213+
### Running tests
214+
215+
Running ``make test`` runs unit tests in the package.
216+
217+
## License
218+
219+
The ECS CLI is distributed under the
220+
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0),
221+
see LICENSE and NOTICE for more information.

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

ecs-cli/main.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package main
15+
16+
import (
17+
"os"
18+
19+
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/command"
20+
ecscompose "github.com/aws/amazon-ecs-cli/ecs-cli/modules/compose/cli/ecs/app"
21+
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/version"
22+
"github.com/codegangsta/cli"
23+
)
24+
25+
func main() {
26+
27+
app := cli.NewApp()
28+
app.Name = version.AppName
29+
app.Usage = "Command line interface for Amazon ECS"
30+
app.Version = version.String()
31+
app.Author = "Amazon Web Services"
32+
33+
composeFactory := ecscompose.NewProjectFactory()
34+
35+
app.Commands = []cli.Command{
36+
command.ConfigureCommand(),
37+
command.UpCommand(),
38+
command.DownCommand(),
39+
command.ScaleCommand(),
40+
command.PsCommand(),
41+
ecscompose.ComposeCommand(composeFactory),
42+
}
43+
app.Run(os.Args)
44+
}

0 commit comments

Comments
 (0)