Skip to content

Commit

Permalink
Merge branch 'release/v0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jritsema committed Mar 27, 2019
2 parents ddd781f + 700581c commit 53456ae
Show file tree
Hide file tree
Showing 17 changed files with 2,434 additions and 149 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.6.0 (2019-03-27)

### Enhancements

- Support for secrets in task definitions ([#41](https://github.com/turnerlabs/fargate/pull/41))
- Support for all currently available regions ([#42](https://github.com/turnerlabs/fargate/pull/42))
- Sort env vars output by key ([#33](https://github.com/turnerlabs/fargate/pull/33))


## 0.5.0 (2018-11-14)

### Enhancements
Expand Down
89 changes: 10 additions & 79 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[[constraint]]
name = "github.com/aws/aws-sdk-go"
version = "1.15.68"
version = "1.15.77"

[[constraint]]
name = "github.com/golang/mock"
Expand Down
37 changes: 24 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,16 @@ via the --image flag.
fargate service deploy [--file docker-compose.yml]
```

Deploy image and environment variables defined in a [docker compose file](https://docs.docker.com/compose/overview/) to service
Deploy image, environment variables, and secrets defined in a [docker compose file](https://docs.docker.com/compose/overview/) to service

Deploy a docker [image](https://docs.docker.com/compose/compose-file/#image) and [environment variables](https://docs.docker.com/compose/environment-variables/) defined in a docker compose file together as a single unit. Note that environments variables are replaced with what's in the compose file.
Deploy a docker [image](https://docs.docker.com/compose/compose-file/#image) and [environment variables](https://docs.docker.com/compose/environment-variables/) defined in a docker compose file together as a single unit. Note that environments variables and secrets are replaced with what's in the compose file.

Secrets can be defined as key-value pairs under the docker compose file extension field `x-fargate-secrets`. To use extension fields, the compose file version must be at least `2.1` for the 2.x series or at least `3.4` for the 3.x series.

This allows you to run `docker-compose up` locally to run your app the same way it will run in AWS. Note that while the docker-compose yaml configuration supports numerous options, only the image and environment variables are deployed to fargate. If the docker compose file defines more than one container, you can use the [label](https://docs.docker.com/compose/compose-file/#labels) `aws.ecs.fargate.deploy: 1` to indicate which container you would like to deploy. For example:

```yaml
version: '3'
version: '3.4'
services:
web:
build: .
Expand All @@ -149,6 +151,8 @@ services:
BAZ: bam
env_file:
- hidden.env
x-fargate-secrets:
QUX: arn:key:ssm:us-east-1:000000000000:parameter/path/to/my_parameter
labels:
aws.ecs.fargate.deploy: 1
redis:
Expand All @@ -164,7 +168,7 @@ fargate service info
Inspect service

Show extended information for a service including load balancer configuration,
active deployments, and environment variables.
active deployments, environment variables, and secrets.

Deployments show active versions of your service that are running. Multiple
deployments are shown if a service is transitioning due to a deployment or
Expand Down Expand Up @@ -233,30 +237,33 @@ specified with a sign such as +5 or -2.

```console
fargate service env set [--env <key=value>] [--file <pathname>]
[--secret <key=valueFrom>] [--secret-file <pathname>]
```

Set environment variables
Set environment variables and secrets

At least one environment variable must be specified via either the --env or
--file flags. You may specify any number of variables on the command line by
At least one environment variable or secret must be specified via either the --env,
--file, --secret, or --secret-file flags. You may specify any number of variables on the command line by
repeating --env before each one, or else place multiple variables in a text
file, one per line, and specify the filename with --file.
file, one per line, and specify the filename with --file and/or --secret-file.

Each --env parameter string or line in the file must be of the form
Each --env and --secret parameter string or line in the file must be of the form
"key=value", with no quotation marks and no whitespace around the "=" unless you want
literal leading whitespace in the value. Additionally, the "key" side must be
a legal shell identifier, which means it must start with an ASCII letter A-Z or
underscore and consist of only letters, digits, and underscores.

The "value" in "key=value" for each --secret flag should reference the ARN to the AWS Secrets Manager secret or AWS Systems Manager Parameter Store parameter.

##### fargate service env unset

```console
fargate service env unset --key <key-name>
```

Unset environment variables
Unset environment variables and secrets

Unsets the environment variable specified via the --key flag. Specify --key with
Unsets the environment variable or secret specified via the --key flag. Specify --key with
a key name multiple times to unset multiple variables.

##### fargate service env list
Expand Down Expand Up @@ -327,7 +334,9 @@ Console, or until they are interrupted for any reason.
##### fargate task register

```console
fargate task register [--image <docker-image>] [-e KEY=value -e KEY2=value] [--env-file dev.env]
fargate task register [--image <docker-image>] [-e KEY=value -e KEY2=value]
[--env-file dev.env] [--secret KEY3=valueFrom]
[--secret-file secrets.env]
```

Registers a new [task definition](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html) for the specified docker image or environment variables based on the latest revision of the task family and returns the new revision number.
Expand All @@ -340,7 +349,9 @@ via the --image flag.
fargate task register [--file docker-compose.yml]
```

Registers a new [Task Definition](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html) using the [image](https://docs.docker.com/compose/compose-file/#image) and [environment variables](https://docs.docker.com/compose/environment-variables/) defined in a docker compose file. Note that environments variables are replaced with what's in the compose file.
Registers a new [Task Definition](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html) using the [image](https://docs.docker.com/compose/compose-file/#image), [environment variables](https://docs.docker.com/compose/environment-variables/), and secrets defined in a docker compose file. Note that environments variables are replaced with what's in the compose file.

Secrets can be defined as key-value pairs under the docker compose file extension field `x-fargate-secrets`. To use extension fields, the compose file version must be at least `2.1` for the 2.x series or at least `3.4` for the 3.x series.

If the docker compose file defines more than one container, you can use the [label](https://docs.docker.com/compose/compose-file/#labels) `aws.ecs.fargate.deploy: 1` to indicate which container you would like to deploy.

Expand Down
55 changes: 48 additions & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"bufio"
"fmt"
"os"
"regexp"
Expand Down Expand Up @@ -44,7 +45,21 @@ CPU (CPU Units) Memory (MiB)
4096 8192 through 30720 in 1GiB increments
`)

var validRegions = []string{"us-east-1"}
var validRegions = []string{
"us-east-1",
"us-east-2",
"us-west-1",
"us-west-2",
"ca-central-1",
"eu-west-1",
"eu-west-2",
"eu-central-1",
"ap-southeast-1",
"ap-southeast-2",
"ap-northeast-1",
"ap-northheast-2",
"ap-south-1",
}

var (
clusterName string
Expand Down Expand Up @@ -100,12 +115,8 @@ CloudWatch Logs, and Amazon Route 53 into an easy-to-use CLI.`,
}
}

for _, validRegion := range validRegions {
if region == validRegion {
break
}

console.IssueExit("Invalid region: %s [valid regions: %s]", region, strings.Join(validRegions, ", "))
if err := validateRegion(region); err != nil {
console.IssueExit(err.Error())
}

config := &aws.Config{
Expand Down Expand Up @@ -195,6 +206,22 @@ func extractEnvVars(inputEnvVars []string) []ECS.EnvVar {
return envVars
}

func readVarFile(filename string) []string {
var result []string

file, err := os.Open(filename)
if err != nil {
return result
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
result = append(result, scanner.Text())
}

return result
}

func validateCpuAndMemory(inputCpuUnits, inputMebibytes string) error {
cpuUnits, err := strconv.ParseInt(inputCpuUnits, 10, 16)

Expand Down Expand Up @@ -237,3 +264,17 @@ func validateCpuAndMemory(inputCpuUnits, inputMebibytes string) error {
func validateMebibytes(mebibytes, min, max int64) bool {
return mebibytes >= min && mebibytes <= max && mebibytes%mebibytesInGibibyte == 0
}

func validateRegion(region string) error {
found := false
for _, validRegion := range validRegions {
if region == validRegion {
found = true
break
}
}
if !found {
return fmt.Errorf("Invalid region: %s [valid regions: %s]", region, strings.Join(validRegions, ", "))
}
return nil
}
45 changes: 45 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,48 @@ func TestValidateCpuAndMemory(t *testing.T) {
}
}
}

func TestReadEnvFile(t *testing.T) {
expected := []string{"FOO=bar", "BAR=baz"}
results := readVarFile("./testdata/test.env")

if len(results) != len(expected) {
t.Errorf("Expected %d results, got %d results", len(expected), len(results))
}

for i, entry := range results {
if entry != expected[i] {
t.Errorf("Expected %s, got %s", expected[i], entry)
}
}
}

func TestReadEnvFileMissing(t *testing.T) {
results := readVarFile("missing.env")

if len(results) != 0 {
t.Errorf("Expected 0 results, got %d results", len(results))
}
}

func TestRegion(t *testing.T) {
region := "us-east-1"
err := validateRegion(region)
if err != nil {
t.Error(err)
}
region = "ap-south-1"
err = validateRegion(region)
if err != nil {
t.Error(err)
}

}

func TestRegion_Invalid(t *testing.T) {
region := "invalid"
err := validateRegion(region)
if err == nil {
t.Error("expecting invalid region")
}
}
Loading

0 comments on commit 53456ae

Please sign in to comment.