Skip to content

Commit

Permalink
Merge pull request #6 from kayac/load-plain-taskdef
Browse files Browse the repository at this point in the history
Load a plain task definition.
  • Loading branch information
fujiwara authored Jan 18, 2018
2 parents a45220f + 4cdf07b commit a6e0c30
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ timeout: 5m
ecspresso works as below.
- Register a new task definition from JSON file.
- JSON file is same format as `aws ecs describe-task-definition` output.
- JSON file is allowed both of formats as below.
- `aws ecs describe-task-definition` output.
- `aws ecs register-task-definition --cli-input-json` input.
- Replace ```{{ env `FOO` `bar` }}``` syntax in the JSON file to environment variable "FOO".
- If "FOO" is not defined, replaced by "bar"
- Replace ```{{ must_env `FOO` }}``` syntax in the JSON file to environment variable "FOO".
Expand Down
9 changes: 8 additions & 1 deletion ecspresso.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,14 @@ func (d *App) LoadTaskDefinition(path string) (*ecs.TaskDefinition, error) {
if err := config.LoadWithEnvJSON(&c, path); err != nil {
return nil, err
}
return c.TaskDefinition, nil
if c.TaskDefinition != nil {
return c.TaskDefinition, nil
}
var td ecs.TaskDefinition
if err := config.LoadWithEnvJSON(&td, path); err != nil {
return nil, err
}
return &td, nil
}

func (d *App) LoadServiceDefinition(path string) (*ecs.CreateServiceInput, error) {
Expand Down
27 changes: 27 additions & 0 deletions ecspresso_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
package ecspresso_test

import (
"testing"
"time"

"github.com/kayac/ecspresso"
)

func TestLoadTaskDefinition(t *testing.T) {
for _, path := range []string{"tests/td.json", "tests/td-plain.json"} {
c := &ecspresso.Config{
Region: "ap-northeast-1",
Timeout: 300 * time.Second,
Service: "test",
Cluster: "default",
TaskDefinitionPath: path,
}
app, err := ecspresso.NewApp(c)
if err != nil {
t.Error(err)
}
td, err := app.LoadTaskDefinition(path)
if err != nil || td == nil {
t.Errorf("%s load failed: %s", path, err)
}
}
}
57 changes: 57 additions & 0 deletions tests/td-plain.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"status": "ACTIVE",
"networkMode": "awsvpc",
"family": "katsubushi",
"placementConstraints": [],
"requiresCompatibilities": [
"FARGATE"
],
"volumes": [],
"taskRoleArn": "arn:aws:iam::999999999999:role/ecsTaskRole",
"executionRoleArn": "arn:aws:iam::999999999999:role/ecsTaskRole",
"containerDefinitions": [
{
"environment": [
{
"name": "worker_id",
"value": "3"
}
],
"name": "katsubushi",
"mountPoints": [],
"portMappings": [
{
"protocol": "tcp",
"containerPort": 11212,
"hostPort": 11212
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "fargate",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "katsubushi"
}
},
"image": "katsubushi/katsubushi:{{ env `TAG` `latest` }}",
"dockerLabels": {
"name": "katsubushi"
},
"cpu": 256,
"ulimits": [
{
"softLimit": 100000,
"name": "nofile",
"hardLimit": 100000
}
],
"memory": 16,
"essential": true,
"volumesFrom": []
}
],
"revision": 1,
"cpu": "1024",
"memory": "2048"
}
59 changes: 59 additions & 0 deletions tests/td.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"taskDefinition": {
"status": "ACTIVE",
"networkMode": "awsvpc",
"family": "katsubushi",
"placementConstraints": [],
"requiresCompatibilities": [
"FARGATE"
],
"volumes": [],
"taskRoleArn": "arn:aws:iam::999999999999:role/ecsTaskRole",
"executionRoleArn": "arn:aws:iam::999999999999:role/ecsTaskRole",
"containerDefinitions": [
{
"environment": [
{
"name": "worker_id",
"value": "3"
}
],
"name": "katsubushi",
"mountPoints": [],
"portMappings": [
{
"protocol": "tcp",
"containerPort": 11212,
"hostPort": 11212
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "fargate",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "katsubushi"
}
},
"image": "katsubushi/katsubushi:{{ env `TAG` `latest` }}",
"dockerLabels": {
"name": "katsubushi"
},
"cpu": 256,
"ulimits": [
{
"softLimit": 100000,
"name": "nofile",
"hardLimit": 100000
}
],
"memory": 16,
"essential": true,
"volumesFrom": []
}
],
"revision": 1,
"cpu": "1024",
"memory": "2048"
}
}

0 comments on commit a6e0c30

Please sign in to comment.