-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(devnet): continuous integration gssmr
devnet on AWS ECS
#2096
Merged
Merged
Changes from 9 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
e2a0bf6
squashed changes
timwu20 e1aaaff
update Dockerfile
timwu20 fa5b38a
update local devnet
timwu20 00e8ade
update README
timwu20 c75e9f4
fix lint
timwu20 61346b0
update flag
timwu20 0800918
update authorities to include bob and charlie
timwu20 464028d
add scale down step
timwu20 e13c1de
update working directory
timwu20 e2f0d6c
use serviceScaler type
timwu20 22d8f21
fix imports
timwu20 934fdf3
unit tests for serviceScaler
timwu20 1b2a212
use go 1.17 on gha
timwu20 8d7ae45
fix scale-down workflow
timwu20 17a2483
update mocks
timwu20 96103f9
add licenses
timwu20 a26b1d4
Update devnet/README.md
timwu20 714dba3
cr feedback
timwu20 c1b4a6c
Merge branch 'tim/ecs_devnet' of github.com:ChainSafe/gossamer into t…
timwu20 9085af0
use submodule
timwu20 060c2d1
cr feedback
timwu20 369550a
cr feedback
timwu20 221b857
fix test?
timwu20 ce366c4
fix update step in dockerfiles
timwu20 8b1c990
Update devnet/README.md
timwu20 2964b76
cr feedback
timwu20 4ea06da
Merge branch 'tim/ecs_devnet' of github.com:ChainSafe/gossamer into t…
timwu20 c182365
update workflow
timwu20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: devnet | ||
on: | ||
push: | ||
branches: | ||
- devnet | ||
- tim/ecs_devnet | ||
|
||
jobs: | ||
update: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: us-east-2 | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Build, tag, and push alice image to Amazon ECR | ||
id: build-alice | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
ECR_REPOSITORY: gssmr-devnet-alice | ||
IMAGE_TAG: ${{ github.sha }} | ||
DD_API_KEY: ${{ secrets.DD_API_KEY }} | ||
run: | | ||
docker build -f=devnet/alice.Dockerfile . --progress=plain -t=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t=$ECR_REGISTRY/$ECR_REPOSITORY:latest --build-arg DD_API_KEY=$DD_API_KEY --build-arg METRICS_NAMESPACE=gossamer.ecs.devnet | ||
timwu20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest | ||
|
||
- name: Build, tag, and push bob image to Amazon ECR | ||
id: build-bob | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
ECR_REPOSITORY: gssmr-devnet-bob | ||
IMAGE_TAG: ${{ github.sha }} | ||
DD_API_KEY: ${{ secrets.DD_API_KEY }} | ||
run: | | ||
docker build -f=devnet/bob.Dockerfile . --progress=plain -t=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t=$ECR_REGISTRY/$ECR_REPOSITORY:latest --build-arg key=bob --build-arg DD_API_KEY=$DD_API_KEY --build-arg METRICS_NAMESPACE=gossamer.ecs.devnet | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest | ||
|
||
- name: Build, tag, and push charlie image to Amazon ECR | ||
id: build-charlie | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
ECR_REPOSITORY: gssmr-devnet-charlie | ||
IMAGE_TAG: ${{ github.sha }} | ||
DD_API_KEY: ${{ secrets.DD_API_KEY }} | ||
run: | | ||
docker build -f=devnet/bob.Dockerfile . --progress=plain -t=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t=$ECR_REGISTRY/$ECR_REPOSITORY:latest --build-arg key=charlie --build-arg DD_API_KEY=$DD_API_KEY --build-arg METRICS_NAMESPACE=gossamer.ecs.devnet | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest | ||
|
||
- name: Scale down existing Bob and Charlie | ||
id: scale-down | ||
working-directory: ./devnet | ||
run: | | ||
go run cmd/scale-down-ecs-service/main.go -c gssmr-ecs -s="gssmr-ecs-(Charlie|Bob)Service-.+$" | ||
|
||
- name: docker compose up | ||
id: docker-compose-up | ||
working-directory: ./devnet/gssmr-ecs | ||
run: | | ||
curl -L https://raw.githubusercontent.com/docker/compose-cli/main/scripts/install/install_linux.sh | sh | ||
qdm12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
docker context create ecs gssmr-ecs --from-env | ||
docker context use gssmr-ecs | ||
docker compose up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
*.key | ||
!test-key.key | ||
!test-key-password.key | ||
!devnet/alice.node.key | ||
*.wasm | ||
|
||
test_data | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
93ce444331ced4d2f7bfb8296267544e20c2591dbf310c7ea3af672f2879cf8fa999ca3052b725123c2939085e3158dba26624fcfd05c361b1adcc8b27785e35 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"regexp" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/ecs" | ||
"github.com/jessevdk/go-flags" | ||
) | ||
|
||
var ( | ||
svc *ecs.ECS | ||
) | ||
|
||
func init() { | ||
sess := session.Must(session.NewSessionWithOptions(session.Options{ | ||
SharedConfigState: session.SharedConfigEnable, | ||
})) | ||
svc = ecs.New(sess) | ||
} | ||
timwu20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func findServiceArns(ctx context.Context, cluster, serviceRegex string) (serviceArns []*string, err error) { | ||
r, err := regexp.Compile(serviceRegex) | ||
if err != nil { | ||
return | ||
} | ||
|
||
var lsi = &ecs.ListServicesInput{ | ||
Cluster: &cluster, | ||
} | ||
for { | ||
var lso *ecs.ListServicesOutput | ||
lso, err = svc.ListServicesWithContext(ctx, lsi) | ||
if err != nil { | ||
return | ||
} | ||
for _, arn := range lso.ServiceArns { | ||
if r.MatchString(*arn) { | ||
serviceArns = append(serviceArns, arn) | ||
} | ||
} | ||
if lso.NextToken != nil { | ||
lsi.NextToken = lso.NextToken | ||
} else { | ||
break | ||
} | ||
timwu20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return | ||
} | ||
|
||
func updateServices(ctx context.Context, cluster string, serviceArns []*string) (err error) { | ||
timwu20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for _, serviceArn := range serviceArns { | ||
_, err = svc.UpdateServiceWithContext(ctx, &ecs.UpdateServiceInput{ | ||
Cluster: &cluster, | ||
Service: serviceArn, | ||
DesiredCount: aws.Int64(0), | ||
}) | ||
if err != nil { | ||
return | ||
} | ||
} | ||
return | ||
} | ||
|
||
func waitForRunningCount(ctx context.Context, cluster string, serviceArns []*string) (err error) { | ||
ticker := time.NewTicker(time.Second * 5) | ||
timwu20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
main: | ||
timwu20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for { | ||
select { | ||
case <-ticker.C: | ||
var dso *ecs.DescribeServicesOutput | ||
dso, err = svc.DescribeServicesWithContext(ctx, &ecs.DescribeServicesInput{ | ||
Cluster: &cluster, | ||
Services: serviceArns, | ||
}) | ||
if err != nil { | ||
break main | ||
} | ||
scaledDown := make(map[string]bool) | ||
for _, service := range dso.Services { | ||
if service.RunningCount != nil && *service.RunningCount == 0 { | ||
scaledDown[*service.ServiceArn] = true | ||
} | ||
} | ||
if len(scaledDown) == len(serviceArns) { | ||
break main | ||
} | ||
case <-ctx.Done(): | ||
err = fmt.Errorf("aborting waiting, received done from context") | ||
timwu20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
break main | ||
} | ||
} | ||
return | ||
} | ||
|
||
func scaleServices(ctx context.Context, cluster string, servicesRegex string) (err error) { | ||
serviceArns, err := findServiceArns(ctx, cluster, servicesRegex) | ||
if err != nil { | ||
return | ||
} | ||
|
||
err = updateServices(ctx, cluster, serviceArns) | ||
if err != nil { | ||
return | ||
} | ||
|
||
err = waitForRunningCount(ctx, cluster, serviceArns) | ||
return | ||
timwu20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
type options struct { | ||
ServicesRegex string `short:"s" long:"services" description:"regex query used to match against AWS service names" required:"true"` //nolint:lll | ||
Cluster string `short:"c" long:"cluster" description:"ECS cluster name, must be exact match"` | ||
} | ||
|
||
func main() { | ||
sigs := make(chan os.Signal, 1) | ||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
var opts options | ||
_, err := flags.Parse(&opts) | ||
if err != nil { | ||
log.Panic(err) | ||
} | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
done := make(chan error) | ||
go func() { | ||
err = scaleServices(ctx, opts.Cluster, opts.ServicesRegex) | ||
done <- err | ||
timwu20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}() | ||
|
||
for { | ||
select { | ||
case err := <-done: | ||
if err != nil { | ||
log.Panic(err) | ||
qdm12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
// happy path | ||
timwu20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
case <-sigs: | ||
cancel() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use |
||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove this branch as a last commit to this branch?