Skip to content

Commit

Permalink
Add arm64 support for M1 Mac, replace golint (#46)
Browse files Browse the repository at this point in the history
* ignore vscode files

* bump version of gomock for arm

* add arm64 as supported release arch

* add go-version file for asdf and goenv users

* update versions referenced in contributing docs

* remove second param in DoAndReturn - breaking change introduced by latest gomock with arm support

* remove golint for now

* add arm64 to sopstoolinstall script

* an attempt and more verbose install docs

* golangci-lint support

* fix golangci-lint in travis

* lint: remove trailing newline

* fmt sprintf not needed for multiline string

* use less stutter in class naming

* rename test helper without underscore

* use shorter name for os wrap instance

* smaller oswrap instance name

* remove redundant return statement

* add new archive step with arch, add id, specify in brewfile

* use golangci-lint tap to install latest

* update style doc for golangcilint

* more arch additions

* also have to add to installer

* add binary based on goreleaser builds

* add note about docker build for linuxamd64

* add note about releases

* Update README.md

Co-authored-by: Justin Hart <onyxraven@users.noreply.github.com>

* accidentally an L

Co-authored-by: Justin Hart <justin@ibotta.com>
Co-authored-by: Justin Hart <onyxraven@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 7, 2022
1 parent e81c19d commit 7c1722a
Show file tree
Hide file tree
Showing 22 changed files with 147 additions and 121 deletions.
2 changes: 0 additions & 2 deletions .codeclimate.yml
@@ -1,7 +1,5 @@
---
engines:
golint:
enabled: true
gofmt:
enabled: true
govet:
Expand Down
87 changes: 52 additions & 35 deletions .github/CONTRIBUTING.md
Expand Up @@ -2,66 +2,83 @@

## Getting Started

## Layout

This is a single top-level namespace filled with packages. Each directory is potentially a package. Binary builds are done on packages with a main subpackage.

## Building Locally
## Install Golang

### Go Version
### Using asdf-vm
We utilize a `.go-version` file that can be used by [asdf-vm](https://github.com/kennyp/asdf-golang) like so:

Requires Go `>= 1.14`.
```bash
cd /path/to/sopstool/repository/
asdf plugin add golang
asdf install golang
```

1. Install go (currently 1.14)
### Using goenv

You may want to use a version manager.
[goenv](https://github.com/syndbg/goenv) will prefer the `GOENV_VERSION` environment variable first before looking for the `.go-version` file when [determining which Golang version](https://github.com/syndbg/goenv/blob/master/HOW_IT_WORKS.md#choosing-the-go-version) to install. If you do not have this set (`echo $GOENV_VERSION` is empty), install like so:

- [asdf](https://github.com/kennyp/asdf-golang)
```bash
cd /path/to/sopstool/repository/
goenv install
```

```sh
asdf install golang 1.14
# use global to update default go version. local set just for current directory
asdf local golang 1.14
```
### Using gimme
[gimme](https://github.com/travis-ci/gimme) uses `eval` in a simple way:

- [goenv](https://github.com/syndbg/goenv) is another option.
```bash
eval "$(gimme 1.17)"
```

```sh
goenv install 1.14
go version
# go version go1.14 darwin/amd64
```
### From the developers

- [gimme](https://github.com/travis-ci/gimme)
You can download and install the Golang [directly from the website](https://go.dev/dl/).

1. Install gomock
### Additional Go Libraries

```sh
go get -u github.com/golang/mock/gomock && go install github.com/golang/mock/mockgen
```
Install [gomock](https://github.com/golang/mock)

```sh
go get -u github.com/golang/mock/gomock && go install github.com/golang/mock/mockgen
```

### Build
Install [golangci-lint](https://golangci-lint.run/)

With go 1.11+ and addition of [Modules](https://github.com/golang/go/wiki/Modules), go projects can be located outside the GOPATH.
```sh
brew tap golangci/tap
brew install golangci/tap/golangci-lint
```

## Build

If you are having issues review [faq](https://github.com/golang/go/wiki/Modules#faqs--most-common)
With Go 1.11+ and addition of [Modules](https://github.com/golang/go/wiki/Modules), Go projects can be located outside the `$GOPATH`.

If generate has already run, then it does not need to run again.
If you are having issues, review the [FAQ](https://github.com/golang/go/wiki/Modules#faqs--most-common).

If `generate` has already run, then it does not need to run again.

```sh
go build
go fmt ./...
golint ./...
```

### Unit Test
## Unit Tests

Each module is unit tested, and passes all tests.

```sh
go test ./...
```

## Linting

`golangci-lint` runs several popular Go linters quickly:

```sh
golangci-lint run
```

## Releasing

This project uses [GoReleaser](https://goreleaser.com/) for builds and releases. Doing the tag/release below triggers the appropriate actions.
Expand All @@ -70,25 +87,25 @@ This project uses [GoReleaser](https://goreleaser.com/) for builds and releases.

You can preview the package changes by running `scripts/release-preview`. This will show a summary of changes since the last release.

1. Prepare the release
1. Prepare the release:

```sh
git checkout master && git pull
```

Commit and tag with the intended version bump
Commit and tag with the intended version bump:

```sh
git commit -am "Tagging release $VERSION" && git tag v$VERSION
```

for example:
For example:

```sh
git commit -am "Tagging release 0.1.1" && git tag v0.1.1
```

Then push the tag and commit to github
Then push the tag and commit to Github:

```sh
git push && git push --tags # or git push --follow-tags but YMMV
Expand Down Expand Up @@ -133,4 +150,4 @@ Document all public APIs to help users understand the module at a glance. Also c

### Style

Clean up style warnings thrown by gofmt/golint (configured at the base of this repository). These will be marked as build failures in CI. Also consider using 'gofmt' to automatically clean up your code style while conforming to the configuration.
Clean up style warnings thrown by gofmt/golangci-lint (configured at the base of this repository in `.golangci.yml`). These will be marked as build failures in CI. Also consider using these tools to automatically clean up your code style while conforming to the configuration.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@ sopstool
c.out
*.cover
.idea
.vscode
1 change: 1 addition & 0 deletions .go-version
@@ -0,0 +1 @@
1.17
20 changes: 20 additions & 0 deletions .golangci.yml
@@ -0,0 +1,20 @@
run:
timeout: 2m

linters:
disable-all: true
enable:
# defaults
- govet
- staticcheck
- gosimple
- typecheck
- revive
# additional
- goimports
- gosec
- misspell
- whitespace

output:
format: colored-line-number
28 changes: 22 additions & 6 deletions .goreleaser.yml
Expand Up @@ -7,12 +7,12 @@ builds:
- darwin
- linux
goarch:
# sops is only available for amd64
- amd64
- arm64

archives:
- id: zips
name_template: "{{ .ProjectName }}_{{ .Os }}"
- id: newzips
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"

checksum:
# You can change the name of the checksums file.
Expand All @@ -26,7 +26,12 @@ checksum:
name_template: "{{ .ProjectName }}_checksums.txt"

nfpms:
- file_name_template: "{{ .ProjectName }}_{{ .Os }}"
- id: default
# You can change the file name of the package.
#
# Default: `{{ .PackageName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}`
file_name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
# file_name_template: "{{ .ProjectName }}_{{ .Os }}"
vendor: Ibotta
homepage: https://github.com/Ibotta/sopstool
maintainer: Ibotta <oss@ibotta.com>
Expand All @@ -41,7 +46,9 @@ nfpms:
- sops

brews:
- tap:
- ids:
- newzips
tap:
# Repo to push the tap
owner: Ibotta
name: homebrew-public
Expand Down Expand Up @@ -90,7 +97,8 @@ blobs:
folder: "{{ .ProjectName }}"

dockers:
- goos: linux
- id: amd64image
goos: linux
# GOARCH of the built binary that should be used.
goarch: amd64
# GOARM of the built binary that should be used.
Expand All @@ -102,6 +110,14 @@ dockers:
image_templates:
- "ibotta/{{ .ProjectName }}:latest"
- "ibotta/{{ .ProjectName }}:{{ .Version }}"
- "ibotta/{{ .ProjectName }}:{{ .Tag }}"
- "ibotta/{{ .ProjectName }}:v{{ .Major }}"
- "ibotta/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}"
- "ibotta/{{ .ProjectName }}:latest-amd64"
- "ibotta/{{ .ProjectName }}:{{ .Version }}-amd64"
- "ibotta/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "ibotta/{{ .ProjectName }}:v{{ .Major }}-amd64"
- "ibotta/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}-amd64"
# Skips the docker push. Could be useful if you also do draft releases.
# If set to auto, the release will not be pushed to the docker repository
# in case there is an indicator for prerelease in the tag e.g. v1.0.0-rc1
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -45,14 +45,14 @@ cache:
- "$HOME/gopath/pkg/mod"

before_script:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.45.2
- go mod download && go build

script:
# See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
- 'golangci-lint run'
- 'if [ "$TRAVIS_PULL_REQUEST" = "true" ]; then bash go test ./...; fi'
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./scripts/coverage_test; fi'

after_script:
- goreleaser --snapshot --skip-publish --rm-dist

deploy:
Expand Down
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -6,6 +6,9 @@ sopstool is a multi-file wrapper around [sops](https://github.com/mozilla/sops).

sopstool provides functionality to manage multiple secret files at once, and even use as an entrypoint to decrypt at startup, for container images. Much of this behavior is inspired by the great [blackbox project](https://github.com/StackExchange/blackbox).

## 1.0.0 Release and Breaking Changes
1.0.0 release of `sopstool` introduces M1 / darwin-arm64 support. We also want to match build artifacts produced by GoReleaser to what `sops` produces. Therefore, this version introduces a breaking change where we no longer produce artifacts like `sopstool_linux.(deb|rpm|tar.gz)` and `sopstool_darwin.tar.gz`. Instead, you'll see artifacts like `sopstool_darwin_(arm64|amd64)_(deb|rpm|tar.gz)` and `sopstool_linux_(arm64|amd64)_(deb|rpm|tar.gz)` in future releases.

## Installation

The most direct install uses a shell script hosted in this repository. This script will install the latest sops (if the command does not exist) and sopstool to `./bin` by default.
Expand All @@ -27,6 +30,8 @@ curl https://raw.githubusercontent.com/Ibotta/sopstool/master/install.sh | SOPS_

### Docker

**Note**: We currently only build a docker image for [Linux - amd64](.goreleaser.yml#L100).

To use sopstool in your docker container, you can use the direct install method above, but since Docker 1.13, there is a better way by using build stages!

In your Dockerfile:
Expand Down
1 change: 0 additions & 1 deletion cmd/clean.go
Expand Up @@ -39,7 +39,6 @@ func CleanCommand(cmd *cobra.Command, args []string) error {
return err
}
}

}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Expand Up @@ -30,9 +30,9 @@ var encrypter filecrypt.FileCrypt = filecrypt.SopsCryptInstance()
var RootCmd = &cobra.Command{
Use: "sopstool",
Short: "Wrapper around sops for multiple files",
Long: fmt.Sprintf(`sopstool
Long: `sopstool
sops wrapper supporting multiple files and helper commands.`),
sops wrapper supporting multiple files and helper commands.`,
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
2 changes: 1 addition & 1 deletion filecrypt/sops.go
Expand Up @@ -12,7 +12,7 @@ type sopsCrypt struct {

var sops = sopsCrypt{
execWrap: oswrap.ExecWrapInstance(),
osWrap: oswrap.OsWrapInstance(),
osWrap: oswrap.Instance(),
}

// SopsCryptInstance gets an instance of the sops wrapper
Expand Down
8 changes: 0 additions & 8 deletions filecrypt/sops_test.go
Expand Up @@ -25,7 +25,6 @@ func TestEncryptFile(t *testing.T) {
}

sops.execWrap = origEw
return
})
}

Expand All @@ -46,7 +45,6 @@ func TestDecryptFile(t *testing.T) {
}

sops.execWrap = origEw
return
})
t.Run("run dec returns error", func(t *testing.T) {
ctrl := gomock.NewController(t)
Expand All @@ -63,7 +61,6 @@ func TestDecryptFile(t *testing.T) {
}

sops.execWrap = origEw
return
})
}

Expand All @@ -84,7 +81,6 @@ func TestDecryptFilePrint(t *testing.T) {
}

sops.execWrap = origEw
return
})
}

Expand All @@ -105,7 +101,6 @@ func TestRemoveFile(t *testing.T) {
}

sops.osWrap = origOw
return
})
}

Expand All @@ -126,7 +121,6 @@ func TestRemoveCryptFile(t *testing.T) {
}

sops.osWrap = origOw
return
})
}

Expand All @@ -146,7 +140,6 @@ func TestRotateFile(t *testing.T) {
}

sops.execWrap = origEw
return
})
}

Expand All @@ -166,6 +159,5 @@ func TestEditFile(t *testing.T) {
}

sops.execWrap = origEw
return
})
}
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -3,7 +3,7 @@ module github.com/Ibotta/sopstool
go 1.17

require (
github.com/golang/mock v1.5.0
github.com/golang/mock v1.6.0
github.com/mozilla-services/yaml v0.0.0-20201007153854-c369669a6625
github.com/spf13/cobra v1.2.1
)
Expand Down

0 comments on commit 7c1722a

Please sign in to comment.