Skip to content

Commit

Permalink
Add ecs-deploy task def variable substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
graphman65 authored and hamstah committed Mar 2, 2022
1 parent 66655c4 commit 398ada1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions ecs/deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Flags:
--image=IMAGE ... Change the images to the new ones. Format is container_name=image. Can be repeated.
--timeout=300s Timeout when waiting for services to update
--task-json=TASK-JSON Path to a JSON file with the task definition to use
--task-variables=k=v Variables to be replaced in the task definition
--overwrite-account-ids Overwrite account IDs in role ARN with the caller account ID
--assume-role-arn=ASSUME-ROLE-ARN
Role to assume
Expand Down
4 changes: 3 additions & 1 deletion ecs/deploy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module github.com/hamstah/awstools/ecs/deploy
go 1.15

require (
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/aws/aws-sdk-go v1.36.26
github.com/hamstah/awstools/common v0.0.0-20210118215703-d25f588bb9cc
github.com/hamstah/awstools/common v0.0.0-20211029134316-66655c4eb9ec
github.com/stretchr/testify v1.7.0 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)
12 changes: 8 additions & 4 deletions ecs/deploy/go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20201120081800-1786d5ef83d4 h1:EBTWhcAX7rNQ80RLwLCpHZBBrJuzallFHnF+yMXo928=
github.com/alecthomas/units v0.0.0-20201120081800-1786d5ef83d4/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
github.com/aws/aws-sdk-go v1.36.26 h1:710u7Q1xpbzpigh/RPPUXwr/5X/VwCxTXSeam8icgos=
github.com/aws/aws-sdk-go v1.36.26/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hamstah/awstools/common v0.0.0-20210118215703-d25f588bb9cc h1:1nTMDTHVWQOpd40iGoo5st/zIZ5Vmhw1Lp05onK4X+k=
github.com/hamstah/awstools/common v0.0.0-20210118215703-d25f588bb9cc/go.mod h1:sjnaHCl0SbkwMEFX1KZCI4/nDudyX0/C0Cn6S0TW1B4=
github.com/hamstah/awstools/common v0.0.0-20211029134316-66655c4eb9ec h1:GlByN8QLS3GEIV+ZN/8CCjLTykq5FWVyHymyciImMcQ=
github.com/hamstah/awstools/common v0.0.0-20211029134316-66655c4eb9ec/go.mod h1:sjnaHCl0SbkwMEFX1KZCI4/nDudyX0/C0Cn6S0TW1B4=
github.com/hamstah/paranoidhttp v0.0.0-20181219172138-e4e152213bcf h1:G92XzCQoU3u+ypDaf+gByF3SslDCYs0UwiRxSm9ZqcM=
github.com/hamstah/paranoidhttp v0.0.0-20181219172138-e4e152213bcf/go.mod h1:QcKbW0F9WT4Lsy+eVf6c9iehxM+6LMvYITjqWLZzpNQ=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
Expand All @@ -23,8 +24,9 @@ github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
Expand All @@ -49,3 +51,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 8 additions & 0 deletions ecs/deploy/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
Expand All @@ -21,6 +22,7 @@ var (
images = kingpin.Flag("image", "Change the images to the new ones. Format is container_name=image. Can be repeated.").StringMap()
timeout = kingpin.Flag("timeout", "Timeout when waiting for services to update").Default("300s").Duration()
taskJSON = kingpin.Flag("task-json", "Path to a JSON file with the task definition to use").String()
taskVariables = kingpin.Flag("task-variables", "Variables to be replaced in the task definition").StringMap()
overwriteAccountIDs = kingpin.Flag("overwrite-account-ids", "Overwrite account IDs in role ARN with the caller account ID").Default("false").Bool()
)

Expand All @@ -45,6 +47,12 @@ func main() {
b, err := ioutil.ReadFile(*taskJSON)
common.FatalOnError(err)

if taskVariables != nil {
for k, v := range *taskVariables {
b = bytes.ReplaceAll(b, []byte(fmt.Sprintf("${%s}", k)), []byte(v))
}
}

taskDefinition = &ecs.TaskDefinition{}
err = json.Unmarshal(b, taskDefinition)
common.FatalOnError(err)
Expand Down

0 comments on commit 398ada1

Please sign in to comment.