Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
awlawl committed Jul 22, 2022
2 parents 059ba8e + 2489506 commit 62f97f1
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 55 deletions.
34 changes: 0 additions & 34 deletions .circleci/config.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build and deploy
on:
push:
tags:
- '*'

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.16.15

- name: Run unit tests
run: make test

- name: Build for all platforms
run: make dist

- name: Push up a new pre-release
if: ${{ contains(github.ref,'pre')}}
env:
GITHUB_TOKEN: ${{ secrets.SECRET_GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: make prerelease

- name: Push up a new normal release
if: ${{ !contains(github.ref,'pre')}}
env:
GITHUB_TOKEN: ${{ secrets.SECRET_GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: make release
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ vendor
Dockerfile.build
fargate.yml
docker-compose.yml
develop
master
26 changes: 20 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.PHONY: mocks test build dist
.PHONY: mocks test build dist clean

PACKAGES := $(shell go list ./... | grep -v /mock)
BUILD_VERSION := $(shell git describe --tags)
AWS_DEFAULT_REGION := us-east-1

mocks:
go mod vendor
Expand All @@ -11,15 +12,28 @@ test:
go test -race -cover $(PACKAGES)

build:
go build -o bin/fargate main.go
make clean
go build -v

dist:
echo building ${BUILD_VERSION}
gox -osarch="darwin/amd64" -osarch="linux/386" -osarch="linux/amd64" -osarch="windows/amd64" \
-ldflags "-X main.version=${BUILD_VERSION}" -output "dist/ncd_{{.OS}}_{{.Arch}}"
GOOS=linux GOARCH=386 go build -ldflags "-X main.version=${BUILD_VERSION}" -o dist/ncd_linux_386
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=${BUILD_VERSION}" -o dist/ncd_linux_amd64
GOOS=linux GOARCH=arm64 go build -ldflags "-X main.version=${BUILD_VERSION}" -o dist/ncd_linux_arm64
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=${BUILD_VERSION}" -o dist/ncd_darwin_amd64
GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.version=${BUILD_VERSION}" -o dist/ncd_darwin_arm64
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=${BUILD_VERSION}" -o dist/ncd_windows_amd64.exe

prerelease:
ghr --prerelease -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} --replace `git describe --tags` dist/
gh release create ${BUILD_VERSION} --generate-notes --prerelease dist/*
aws s3 cp dist/ s3://get-fargate.turnerlabs.io/${BUILD_VERSION}/ --recursive --region ${AWS_DEFAULT_REGION}
echo ${BUILD_VERSION} > develop && aws s3 cp ./develop s3://get-fargate.turnerlabs.io/ --region ${AWS_DEFAULT_REGION}

release:
ghr -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} --replace `git describe --tags` dist/
gh release create ${BUILD_VERSION} --generate-notes dist/*
aws s3 cp dist/ s3://get-fargate.turnerlabs.io/${BUILD_VERSION}/ --recursive --region ${AWS_DEFAULT_REGION}
echo ${BUILD_VERSION} > master && aws s3 cp ./master s3://get-fargate.turnerlabs.io/ --region ${AWS_DEFAULT_REGION}

clean:
rm -f fargate
rm -rf dist
22 changes: 21 additions & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
const (
keyCluster = "cluster"
keyService = "service"
keyRegion = "region"
keyVerbose = "verbose"
keyNoColor = "nocolor"
keyTask = "task"
Expand All @@ -36,13 +37,33 @@ func initConfig(cmd *cobra.Command) {
//cli arg
initPFlag(keyCluster, cmd)
initPFlag(keyVerbose, cmd)
initPFlag(keyRegion, cmd)
initPFlag(keyNoColor, cmd)
}

func initPFlag(key string, cmd *cobra.Command) {
viper.BindPFlag(key, cmd.PersistentFlags().Lookup(key))
}

//region can come from fargate.yml, AWS_REGION, AWS_DEFAULT_REGION or --region
func getRegion() string {
result := viper.GetString(keyRegion)
if result == "" {
envAwsDefaultRegion := os.Getenv("AWS_DEFAULT_REGION")
envAwsRegion := os.Getenv("AWS_REGION")

if envAwsDefaultRegion != "" {
result = envAwsDefaultRegion
} else if envAwsRegion != "" {
result = envAwsRegion
} else {
result = defaultRegion
}
}

return result
}

//cluster can come from fargate.yml, FARGATE_CLUSTER envar, or --cluster cli arg
func getClusterName() string {
result := viper.GetString(keyCluster)
Expand Down Expand Up @@ -83,7 +104,6 @@ func getRuleName() string {
return result
}


func getVerbose() bool {
return viper.GetBool(keyVerbose)
}
Expand Down
13 changes: 1 addition & 12 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,7 @@ CloudWatch Logs, and Amazon Route 53 into an easy-to-use CLI.`,
}
}

envAwsDefaultRegion := os.Getenv("AWS_DEFAULT_REGION")
envAwsRegion := os.Getenv("AWS_REGION")

if region == "" {
if envAwsDefaultRegion != "" {
region = envAwsDefaultRegion
} else if envAwsRegion != "" {
region = envAwsRegion
} else {
region = defaultRegion
}
}
region = getRegion()

if err := validateRegion(region); err != nil {
console.IssueExit(err.Error())
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ require (
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.7.1
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
gopkg.in/yaml.v2 v2.3.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,9 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 h1:HyfiK1WMnHj5FXFXatD+Qs1A/xC2Run6RzeW1SyHxpc=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand All @@ -297,7 +298,6 @@ golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgw
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc h1:NCy3Ohtk6Iny5V/reW2Ktypo4zIpWBdRJ1uFMjBxdg8=
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
Expand Down

0 comments on commit 62f97f1

Please sign in to comment.