Skip to content

Commit

Permalink
Version CLI (#23)
Browse files Browse the repository at this point in the history
- client version command
- registry version endpoint
- Set release docker build version from git tag on make
- Generate proto
- Remove unused vertical align from success template
- bump version to 0.0.10
- Update Makefile tags
  • Loading branch information
BruceMacD authored Jul 12, 2021
1 parent 0bdadc7 commit 9ef9b31
Show file tree
Hide file tree
Showing 13 changed files with 351 additions and 129 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ env:
project_name: infra
builds:
- id: infra
ldflags:
- -s -w -X github.com/infrahq/infra/internal/version.Version={{ .Version }}
binary: infra
main: ./main.go
goos:
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ RUN apt-get update && \
ln -s /usr/bin/aarch64-linux-gnu-gcc /usr/bin/arm64-linux-gnu-gcc && \
ln -s /usr/bin/x86_64-linux-gnu-gcc /usr/bin/amd64-linux-gnu-gcc
ARG TARGETARCH
ARG BUILDVERSION=development
WORKDIR /go/src/github.com/infrahq/infra
COPY . .
RUN CGO_ENABLED=1 GOOS=linux GOARCH=$TARGETARCH CC=$TARGETARCH-linux-gnu-gcc go build -ldflags '-linkmode external -w -extldflags "-static"' .
RUN CGO_ENABLED=1 GOOS=linux GOARCH=$TARGETARCH CC=$TARGETARCH-linux-gnu-gcc go build -ldflags '-s -w -X github.com/infrahq/infra/internal/version.Version='"$BUILDVERSION"' -linkmode external -w -extldflags "-static"' .

FROM alpine
COPY --from=builder /go/src/github.com/infrahq/infra/infra /bin/infra
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ release:
goreleaser release -f .goreleaser.yml --rm-dist

release/docker:
docker buildx build --push --platform linux/amd64,linux/arm64 . -t infrahq/infra:$(tag:v%=%) -t infrahq/infra
docker buildx build --push --platform linux/amd64,linux/arm64 --build-arg BUILDVERSION=$(tag:v%=%) . -t infrahq/infra:$(tag:v%=%) -t infrahq/infra

release/helm:
make helm
Expand Down
4 changes: 2 additions & 2 deletions helm/charts/infra/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: infra
description: Infra
type: application
version: 0.0.9
appVersion: "0.0.9"
version: 0.0.10
appVersion: "0.0.10"
4 changes: 2 additions & 2 deletions helm/charts/infra/charts/engine/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: engine
description: Infra Engine
type: application
version: 0.0.9
appVersion: "0.0.9"
version: 0.0.10
appVersion: "0.0.10"
34 changes: 34 additions & 0 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"strconv"
"strings"
"syscall"
"text/tabwriter"
"time"

survey "github.com/AlecAivazis/survey/v2"
Expand All @@ -28,6 +29,7 @@ import (
"github.com/infrahq/infra/internal/generate"
"github.com/infrahq/infra/internal/registry"
v1 "github.com/infrahq/infra/internal/v1"
"github.com/infrahq/infra/internal/version"
"github.com/mitchellh/go-homedir"
"github.com/muesli/termenv"
"github.com/olekukonko/tablewriter"
Expand Down Expand Up @@ -975,6 +977,36 @@ func newEngineCmd() *cobra.Command {
return cmd
}

var versionCmd = &cobra.Command{
Use: "version",
Aliases: []string{"v"},
Short: "Display the Infra build version",
RunE: func(cmd *cobra.Command, args []string) error {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.AlignRight)
fmt.Fprintln(w)
fmt.Fprintln(w, "Client:\t", version.Version)

client, err := clientFromConfig()
if err != nil {
return err
}

// Note that we use the client to get this version, but it is in fact the server version
res, err := client.Version(context.Background(), &emptypb.Empty{})
if err != nil {
fmt.Fprintln(w, blue("✕")+" Could not retrieve registry version")
w.Flush()
return err
}

fmt.Fprintln(w, "Registry:\t", res.Version)
fmt.Fprintln(w)
w.Flush()

return nil
},
}

var credsCmd = &cobra.Command{
Use: "creds",
Short: "Generate credentials",
Expand Down Expand Up @@ -1107,6 +1139,8 @@ func NewRootCmd() (*cobra.Command, error) {
rootCmd.AddCommand(registryCmd)
rootCmd.AddCommand(newEngineCmd())

rootCmd.AddCommand(versionCmd)

// Hidden commands
rootCmd.AddCommand(credsCmd)
rootCmd.AddCommand(clientCmd)
Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/pages/success.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@
object,
svg,
video {
display: block;
vertical-align: middle
display: block
}

img,
Expand Down
5 changes: 5 additions & 0 deletions internal/registry/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/infrahq/infra/internal/generate"
"github.com/infrahq/infra/internal/okta"
v1 "github.com/infrahq/infra/internal/v1"
"github.com/infrahq/infra/internal/version"
"golang.org/x/crypto/bcrypt"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -649,3 +650,7 @@ func (v *V1Server) Status(ctx context.Context, in *emptypb.Empty) (*v1.StatusRes

return &v1.StatusResponse{Admin: count > 0}, nil
}

func (v *V1Server) Version(ctx context.Context, in *emptypb.Empty) (*v1.VersionResponse, error) {
return &v1.VersionResponse{Version: version.Version}, nil
}
310 changes: 189 additions & 121 deletions internal/v1/v1.pb.go

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions internal/v1/v1.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions internal/v1/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ service V1 {
rpc Logout(google.protobuf.Empty) returns (google.protobuf.Empty) {}
rpc Signup(SignupRequest) returns (LoginResponse) {}
rpc Status(google.protobuf.Empty) returns (StatusResponse) {}
rpc Version(google.protobuf.Empty) returns (VersionResponse) {}
}

enum SourceType {
Expand Down Expand Up @@ -195,3 +196,7 @@ message SignupRequest {
message StatusResponse {
bool admin = 1;
}

message VersionResponse {
string version = 1;
}
36 changes: 36 additions & 0 deletions internal/v1/v1_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package version

// Version is set on build
// Release build version is the git tag (set in the .goreleaser ldflags and the Dockerfile BUILDVERSION arg)
var Version = "development"

0 comments on commit 9ef9b31

Please sign in to comment.