Skip to content

Commit

Permalink
Merge pull request #1 from abicky/upgrade-go-and-packages
Browse files Browse the repository at this point in the history
Upgrade Go and Packages
  • Loading branch information
abicky authored Oct 30, 2024
2 parents fd4a182 + cdccb4e commit 4a89a15
Show file tree
Hide file tree
Showing 36 changed files with 1,275 additions and 33,550 deletions.
26 changes: 11 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@ jobs:
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.15
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
go-version-file: go.mod

- run: go install go.uber.org/mock/mockgen@latest

# `go test` uses only a high-confidence subset of go vet, so execute also `go vet`
- run: go vet ./...
- run: make vet

- run: go fmt ./... && git diff --exit-code -- ':!go.sum'

Expand All @@ -38,19 +34,19 @@ jobs:
needs: test
if: contains(github.ref, 'tags/v')
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Check the version
run: grep -qr "version = \"$(git tag --points-at HEAD | sed 's/^v//')\"" cmd

- run: git fetch --prune --unshallow
- uses: actions/setup-go@v1
- uses: actions/setup-go@v5
with:
go-version: 1.15
- uses: goreleaser/goreleaser-action@v1
go-version-file: go.mod
- uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --rm-dist
args: release --clean
env:
# Use a custom token instead of GITHUB_TOKEN for the homebrew tap
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/CREDITS
/bin
/dist
mocks.go
19 changes: 11 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
version: 2

before:
hooks:
- go mod download
- env GO111MODULE=off GOBIN=/tmp/bin go get github.com/Songmu/gocredits/cmd/gocredits
- /tmp/bin/gocredits -w .
- go install github.com/Songmu/gocredits/cmd/gocredits@latest
- gocredits -w .
builds:
- env:
- CGO_ENABLED=0
goos:
- darwin
- linux
- windows
flags:
- -trimpath
ldflags:
- -s -w -X github.com/abicky/ecsmec/cmd.revision={{.ShortCommit}}
archives:
- # Exclude the version to download the latest version via https://github.com/abicky/ecsmec/releases/latest/download/$archive_name
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
- # Exclude the version from the default name_template to download the latest version via https://github.com/abicky/ecsmec/releases/latest/download/$archive_name
name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}'
files:
- LICENSE
- README.md
Expand All @@ -24,18 +27,18 @@ archives:
format: zip
wrap_in_directory: true
brews:
- tap:
- repository:
owner: abicky
name: homebrew-tools
homepage: "https://github.com/abicky/ecsmec"
description: "A CLI tool for Amazon ECS that provides some commands to execute bothersome operations"
folder: Formula
directory: Formula
test: |
system "#{bin}/ecsmec --version"
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
version_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
Expand Down
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
NAME := ecsmec
SRCS := $(shell find . -type f -name '*.go' -not -name '*_test.go')
SRCS := $(shell find . -type f -name '*.go' -not -name '*_test.go' -not -path './internal/testing/*')
MOCKS := internal/testing/capacitymock/mocks.go internal/testing/servicemock/mocks.go

all: bin/$(NAME)

Expand All @@ -8,12 +9,21 @@ bin/$(NAME): $(SRCS)

.PHONY: clean
clean:
rm -rf bin/$(NAME)
rm -rf bin/$(NAME) $(MOCKS)

.PHONY: install
install:
go install -ldflags "-s -w -X github.com/abicky/ecsmec/cmd.revision=$(shell git rev-parse --short HEAD)"

.PHONY: test
test:
test: $(MOCKS)
go test -v ./...

.PHONY: vet
vet: $(MOCKS)
go vet ./...

$(MOCKS): $(SRCS)
go generate ./...
# mockgen doesn't update timestamps if the generated code doesn't change
touch $(MOCKS)
50 changes: 29 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,36 @@ This tool enables you to do such operations easily.

Download the binary archive from the [releases page](https://github.com/abicky/ecsmec/releases), unpack it, and move the executable "ecsmec" to a directory in your path (e.g. `/usr/local/bin`).

For example, you can install the latest binary on macOS by the following commands:
For example, you can install the latest binary on a Mac with Apple silicon by the following commands:

```
curl -LO https://github.com/abicky/ecsmec/releases/latest/download/ecsmec_darwin_amd64.tar.gz
tar xvf ecsmec_darwin_amd64.tar.gz
mv ecsmec_darwin_amd64/ecsmec /usr/local/bin/
```sh
curl -LO https://github.com/abicky/ecsmec/releases/latest/download/ecsmec_darwin_arm64.tar.gz
tar xvf ecsmec_darwin_arm64.tar.gz
mv ecsmec_darwin_arm64/ecsmec /usr/local/bin/
```

If you download the archive via a browser on macOS Catalina or later, you may receive the message "“ecsmec” cannot be opened because the developer cannot be verified."
In such a case, you need to delete the attribute "com.apple.quarantine" like below:

```
```sh
xattr -d com.apple.quarantine /path/to/ecsmec
```

### Install with Homebrew (macOS or Linux)

```
```sh
brew install abicky/tools/ecsmec
```

### Install from source

```
```sh
go get -u github.com:abicky/ecsmec
```

or

```
```sh
git clone https://github.com:abicky/ecsmec
cd ecsmec
make install
Expand All @@ -52,7 +52,7 @@ make install

### recreate-service

```
```console
$ ecsmec recreate-service --help
This command creates a new service from the specified service with overrides,
and after the new service becomes stable, it deletes the old one.
Expand Down Expand Up @@ -94,7 +94,6 @@ Global Flags:
```

The option "overrides" is in the same format as the [CreateService API](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_CreateService.html) parameter, except that the first letter of each field is uppercase.
Although the [UpdateService API](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_UpdateService.html) supports updating the task placement strategies and constraints, the feature is still in preview and the command helps you to update the task placement strategies and constraints safely.

This command does the following operations to recreate the specified service:

Expand All @@ -111,7 +110,7 @@ If the service name is overridden, the operations change as follow:

You need the following permissions to execute the command:

```
```json
{
"Version": "2012-10-17",
"Statement": [
Expand Down Expand Up @@ -141,6 +140,15 @@ You need the following permissions to execute the command:
],
"Resource": [
"arn:aws:ecs:<region>:<account-id>:service/<cluster>/*"
],
},
{
"Effect": "Allow",
"Action": [
"iam:PassRole"
],
"Resource": [
"arn:aws:iam::<account-id>:role/<role_for_volume_configurations>"
]
}
]
Expand All @@ -149,7 +157,7 @@ You need the following permissions to execute the command:

### reduce-cluster-capacity

```
```console
$ ecsmec reduce-cluster-capacity --help
This command reduces the capacity of the specified cluster safely
that belong to the auto scaling group or spot fleet request.
Expand Down Expand Up @@ -188,7 +196,7 @@ You need the following permissions to execute the command:

For a auto scaling group:

```
```json
{
"Version": "2012-10-17",
"Statement": [
Expand Down Expand Up @@ -253,7 +261,7 @@ For a auto scaling group:

For a spot fleet request:

```
```json
{
"Version": "2012-10-17",
"Statement": [
Expand Down Expand Up @@ -328,7 +336,7 @@ For a spot fleet request:

### replace-auto-scaling-group-instances

```
```console
$ ecsmec replace-auto-scaling-group-instances --help
This command replaces container instances that belong to the specified
auto scaling group and are launched before the time when this command
Expand Down Expand Up @@ -360,7 +368,7 @@ This command does the following operations to replace container instances:

You need the following permissions to execute the command:

```
```json
{
"Version": "2012-10-17",
"Statement": [
Expand Down Expand Up @@ -426,12 +434,12 @@ You need the following permissions to execute the command:
}
```

### terminate-spot-fleet-request-instances
### terminate-spot-fleet-instances

```
```console
$ ecsmec terminate-spot-fleet-instances --help
This command terminates all the container instances safely that belong
to the specified spot fleet request.
to the specified spot fleet request with state "cancelled".

Usage:
ecsmec terminate-spot-fleet-instances [flags]
Expand All @@ -455,7 +463,7 @@ This command does the following operations to terminate container instances:

You need the following permissions to execute the command:

```
```json
{
"Version": "2012-10-17",
"Statement": [
Expand Down
8 changes: 4 additions & 4 deletions cmd/recreateservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"strings"

"github.com/aws/aws-sdk-go/service/ecs"
"github.com/aws/aws-sdk-go-v2/service/ecs"
"github.com/spf13/cobra"

"github.com/abicky/ecsmec/internal/service"
Expand Down Expand Up @@ -64,12 +64,12 @@ func recreateService(cmd *cobra.Command, args []string) error {
return newRuntimeError("failed to parse \"overrides\": %w", err)
}

sess, err := newSession()
cfg, err := newConfig(cmd.Context())
if err != nil {
return newRuntimeError("failed to initialize a session: %w", err)
return newRuntimeError("failed to initialize configuration: %w", err)
}

if err := service.NewService(ecs.New(sess)).Recreate(cluster, serviceName, overrideDef); err != nil {
if err := service.NewService(ecs.NewFromConfig(cfg)).Recreate(cmd.Context(), cluster, serviceName, overrideDef); err != nil {
return newRuntimeError("failed to recreate the service: %w", err)
}
return nil
Expand Down
Loading

0 comments on commit 4a89a15

Please sign in to comment.