Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
use goreleaser for building cli and plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaibuzgau committed Sep 17, 2021
1 parent 24ea868 commit 32b7d90
Show file tree
Hide file tree
Showing 21 changed files with 205 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@

/.ext
/bin
/dist
/cover.out
187 changes: 187 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
before:
hooks:

builds:
- id: cli
main: ./cmd/aserto-idp
binary: aserto-idp
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ignore:
- goos: windows
goarch: arm64
ldflags:
- -s
- -w
- -X github.com/aserto-dev/aserto-idp/pkg/version.ver={{.Version}}
- -X github.com/aserto-dev/aserto-idp/pkg/version.commit={{.ShortCommit}}
- -X github.com/aserto-dev/aserto-idp/pkg/version.date={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true

- id: aserto-idp-plugin-aserto
main: ./plugins/aserto/cmd/aserto-idp-plugin-aserto
binary: aserto-idp-plugin-aserto
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ignore:
- goos: windows
goarch: arm64
ldflags:
- -s
- -w
- -X github.com/aserto-dev/aserto-idp/plugins/aserto/pkg/config.ver={{.Version}}
- -X github.com/aserto-dev/aserto-idp/plugins/aserto/pkg/config.commit={{.ShortCommit}}
- -X github.com/aserto-dev/aserto-idp/plugins/aserto/pkg/config.date={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true

- id: aserto-idp-plugin-auth0
main: ./plugins/auth0/cmd/aserto-idp-plugin-auth0
binary: aserto-idp-plugin-auth0
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ignore:
- goos: windows
goarch: arm64
ldflags:
- -s
- -w
- -X github.com/aserto-dev/aserto-idp/plugins/auth0/pkg/config.ver={{.Version}}
- -X github.com/aserto-dev/aserto-idp/plugins/auth0/pkg/config.commit={{.ShortCommit}}
- -X github.com/aserto-dev/aserto-idp/plugins/auth0/pkg/config.date={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true

- id: aserto-idp-plugin-dummy
main: ./plugins/dummy/cmd/aserto-idp-plugin-dummy
binary: aserto-idp-plugin-dummy
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ignore:
- goos: windows
goarch: arm64
ldflags:
- -s
- -w
- -X github.com/aserto-dev/aserto-idp/plugins/dummy/pkg/config.ver={{.Version}}
- -X github.com/aserto-dev/aserto-idp/plugins/dummy/pkg/config.commit={{.ShortCommit}}
- -X github.com/aserto-dev/aserto-idp/plugins/dummy/pkg/config.date={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true

- id: aserto-idp-plugin-json
main: ./plugins/json/cmd/aserto-idp-plugin-json
binary: aserto-idp-plugin-json
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ignore:
- goos: windows
goarch: arm64
ldflags:
- -s
- -w
- -X github.com/aserto-dev/aserto-idp/plugins/json/pkg/config.ver={{.Version}}
- -X github.com/aserto-dev/aserto-idp/plugins/json/pkg/config.commit={{.ShortCommit}}
- -X github.com/aserto-dev/aserto-idp/plugins/json/pkg/config.date={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true

archives:
- format: zip
replacements:
darwin: darwin
linux: linux
windows: windows
amd64: x86_64
files:
- LICENSE
- README.md
name_template: "aserto-idp{{ .Version }}_{{ .Os }}_{{ .Arch }}"

checksum:
name_template: "checksums.txt"

snapshot:
name_template: "{{ .Tag }}"

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

release:
github:
owner: aserto-dev
name: aserto-idp

draft: false
prerelease: false
name_template: "aserto-idp {{.Tag}}"

brews:
- name: aserto-idp

tap:
owner: aserto-dev
name: aserto-tap
token: "{{ .Env.ASERTO_TAP }}"

url_template: "https://github.com/aserto-dev/aserto-idp/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
download_strategy: CustomGitHubPrivateRepositoryReleaseDownloadStrategy
custom_require: "lib/custom_download_strategy"

commit_author:
name: Aserto Bot
email: github-bot@aserto.com

homepage: "https://aserto.com/"

description: "aserto idp CLI for importing and exporting users to/from IDP providers."

license: "Apache License Version 2.0"

skip_upload: false

test: |
system "#{bin}/aserto-idp version"
install: |
bin.install "aserto-idp"
31 changes: 2 additions & 29 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
package main

import (
"fmt"
"os"
"runtime"
"time"

"github.com/aserto-dev/mage-loot/buf"
"github.com/aserto-dev/mage-loot/common"
"github.com/aserto-dev/mage-loot/deps"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/pkg/errors"
)

func init() {
Expand All @@ -38,17 +35,12 @@ func GenerateProto() error {

// Build builds all binaries in ./cmd.
func Build() error {
flags, err := ldflags()
if err != nil {
return err
}

return common.Build(flags...)
return common.BuildReleaser()
}

// Cleans the bin director
func Clean() error {
return os.RemoveAll("bin")
return os.RemoveAll("dist")
}

// BuildAll builds all binaries in ./cmd for
Expand Down Expand Up @@ -79,25 +71,6 @@ func All() error {
return nil
}

func ldflags() ([]string, error) {
commit, err := common.Commit()
if err != nil {
return nil, errors.Wrap(err, "failed to calculate git commit")
}
version, err := common.Version()
if err != nil {
return nil, errors.Wrap(err, "failed to calculate version")
}

date := time.Now().UTC().Format(time.RFC3339)

ldbase := "github.com/aserto-dev/aserto-idp/shared/version"
ldflags := fmt.Sprintf(`-X %s.ver=%s -X %s.commit=%s -X %s.date=%s`,
ldbase, version, ldbase, commit, ldbase, date)

return []string{"-ldflags", ldflags}, nil
}

func Run() error {
return sh.RunV("./bin/" + runtime.GOOS + "-" + runtime.GOARCH + "/aserto-idp")
}
4 changes: 3 additions & 1 deletion pkg/cc/cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ func (c *CC) Dispose() {
for _, provider := range c.providers {
provider.Kill()
}
c.defaultProvider.Kill()
if c.defaultProvider != nil {
c.defaultProvider.Kill()
}
}

// LoadConfig loads the plugin and logger config from a configuration file
Expand Down
6 changes: 2 additions & 4 deletions pkg/cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ func NewPlugin(provider provider.Provider, c *cc.CC) (*Plugin, error) {
return nil, err
}

if providerInfo.Build != nil {
c.Log.Warn().Msg("xxxxxx" + providerInfo.Build.Date + "Xxxxxx")
}

plugin.Name = provider.GetName()

c.Log.Info().Msgf("loaded plugin %s - version: %s, commit: %s", plugin.Name, providerInfo.Build.Version, providerInfo.Build.Commit)

for _, config := range providerInfo.Configs {
plugin.Plugins = append(plugin.Plugins, getFlagStruct(config.Name, config.Description, plugin.Name, config.Type))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/aserto-dev/aserto-idp/plugins/aserto/srv"
"github.com/aserto-dev/aserto-idp/plugins/aserto/pkg/srv"
"github.com/aserto-dev/aserto-idp/shared"
"github.com/aserto-dev/aserto-idp/shared/grpcplugin"
plugin "github.com/hashicorp/go-plugin"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/aserto-dev/aserto-idp/pkg/grpcc/authorizer"
"github.com/aserto-dev/aserto-idp/pkg/grpcc/directory"
"github.com/aserto-dev/aserto-idp/pkg/proto"
"github.com/aserto-dev/aserto-idp/plugins/aserto/config"
"github.com/aserto-dev/aserto-idp/plugins/aserto/pkg/config"
"github.com/aserto-dev/aserto-idp/shared/version"
api "github.com/aserto-dev/go-grpc/aserto/api/v1"
dir "github.com/aserto-dev/go-grpc/aserto/authorizer/directory/v1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/aserto-dev/aserto-idp/plugins/auth0/srv"
"github.com/aserto-dev/aserto-idp/plugins/auth0/pkg/srv"
"github.com/aserto-dev/aserto-idp/shared"
"github.com/aserto-dev/aserto-idp/shared/grpcplugin"
plugin "github.com/hashicorp/go-plugin"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package srv

import (
"github.com/aserto-dev/aserto-idp/plugins/auth0/config"
"github.com/aserto-dev/aserto-idp/plugins/auth0/pkg/config"
api "github.com/aserto-dev/go-grpc/aserto/api/v1"
"gopkg.in/auth0.v5/management"
)
Expand Down
2 changes: 1 addition & 1 deletion plugins/auth0/srv/srv.go → plugins/auth0/pkg/srv/srv.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"log"

"github.com/aserto-dev/aserto-idp/pkg/proto"
"github.com/aserto-dev/aserto-idp/plugins/auth0/config"
"github.com/aserto-dev/aserto-idp/plugins/auth0/pkg/config"
"github.com/aserto-dev/aserto-idp/shared/version"
api "github.com/aserto-dev/go-grpc/aserto/api/v1"
"github.com/pkg/errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"
"time"

"github.com/aserto-dev/aserto-idp/plugins/auth0/config"
"github.com/aserto-dev/aserto-idp/plugins/auth0/pkg/config"
api "github.com/aserto-dev/go-grpc/aserto/api/v1"
"gopkg.in/auth0.v5"
"gopkg.in/auth0.v5/management"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/aserto-dev/aserto-idp/plugins/dummy/srv"
"github.com/aserto-dev/aserto-idp/plugins/dummy/pkg/srv"
"github.com/aserto-dev/aserto-idp/shared"
"github.com/aserto-dev/aserto-idp/shared/grpcplugin"
plugin "github.com/hashicorp/go-plugin"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion plugins/dummy/srv/srv.go → plugins/dummy/pkg/srv/srv.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"

"github.com/aserto-dev/aserto-idp/pkg/proto"
"github.com/aserto-dev/aserto-idp/plugins/dummy/config"
"github.com/aserto-dev/aserto-idp/plugins/dummy/pkg/config"
"github.com/aserto-dev/aserto-idp/shared/version"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/aserto-dev/aserto-idp/plugins/json/srv"
"github.com/aserto-dev/aserto-idp/plugins/json/pkg/srv"
"github.com/aserto-dev/aserto-idp/shared"
"github.com/aserto-dev/aserto-idp/shared/grpcplugin"
plugin "github.com/hashicorp/go-plugin"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion plugins/json/srv/srv.go → plugins/json/pkg/srv/srv.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"os"

"github.com/aserto-dev/aserto-idp/pkg/proto"
"github.com/aserto-dev/aserto-idp/plugins/json/config"
"github.com/aserto-dev/aserto-idp/plugins/json/pkg/config"
"github.com/aserto-dev/aserto-idp/shared/pb"
"github.com/aserto-dev/aserto-idp/shared/version"
api "github.com/aserto-dev/go-grpc/aserto/api/v1"
Expand Down
File renamed without changes.

0 comments on commit 32b7d90

Please sign in to comment.