Skip to content

Commit

Permalink
Add version, add make build and dist
Browse files Browse the repository at this point in the history
  • Loading branch information
maorfr committed Oct 17, 2018
1 parent f0ee8a0 commit 9e2e765
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/*gitlab*
*.md
*.git
bin/
dist/
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
vendor/

examples/

bin/
bin/
dist/
13 changes: 3 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
FROM golang:1.10.3-alpine as builder
WORKDIR /go/src/github.com/maorfr/orca/
COPY . .

ARG DEP_VERSION=v0.5.0

RUN apk --no-cache add git \
&& wget -q -O $GOPATH/bin/dep https://github.com/golang/dep/releases/download/${DEP_VERSION}/dep-linux-amd64 \
&& chmod +x $GOPATH/bin/dep \
&& dep ensure \
&& for f in $(find test -type f -name "*.go"); do go test -v $f; done \
&& CGO_ENABLED=0 GOOS=linux go build -o orca cmd/orca.go
RUN apk --no-cache add git make \
&& make

FROM alpine:3.8
ARG HELM_VERSION=v2.11.0
Expand All @@ -24,7 +17,7 @@ ARG LINKERD_OS=linux
RUN wget -q https://github.com/linkerd/linkerd2/releases/download/${LINKERD_VERSION}/linkerd2-cli-${LINKERD_VERSION}-${LINKERD_OS} -O linkerd \
&& chmod +x linkerd \
&& mv linkerd /usr/local/bin/linkerd
COPY --from=builder /go/src/github.com/maorfr/orca/orca /usr/local/bin/orca
COPY --from=builder /go/src/github.com/maorfr/orca/bin/orca /usr/local/bin/orca
RUN addgroup -g 1001 -S orca \
&& adduser -u 1001 -D -S -G orca orca
USER orca
Expand Down
26 changes: 13 additions & 13 deletions Gopkg.lock

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

33 changes: 30 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
all: test build
HAS_DEP := $(shell command -v dep;)
DEP_VERSION := v0.5.0
TEST_FILES := $(shell find ./test -type f -name "*.go")
GIT_TAG := $(shell git describe --tags --always)
GIT_COMMIT := $(shell git rev-parse --short HEAD)
LDFLAGS := "-X main.GitTag=${GIT_TAG} -X main.GitCommit=${GIT_COMMIT}"
DIST := $(CURDIR)/dist

all: bootstrap test build

fmt:
go fmt ./pkg/... ./cmd/...
Expand All @@ -8,8 +16,27 @@ vet:

# Run tests
test: fmt vet
go test ./test/... ./pkg/... -coverprofile cover.out
for f in $(TEST_FILES); do go test -v $$f; done

# Build orca binary
build: fmt vet
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/orca cmd/orca.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags $(LDFLAGS) -o bin/orca cmd/orca.go

bootstrap:
ifndef HAS_DEP
wget -q -O $(GOPATH)/bin/dep https://github.com/golang/dep/releases/download/$(DEP_VERSION)/dep-linux-amd64
chmod +x $(GOPATH)/bin/dep
endif
dep ensure

dist:
mkdir -p $(DIST)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags $(LDFLAGS) -o orca cmd/orca.go
tar -zcvf $(DIST)/orca-linux-$(GIT_TAG).tgz orca
rm orca
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags $(LDFLAGS) -o orca cmd/orca.go
tar -zcvf $(DIST)/orca-macos-$(GIT_TAG).tgz orca
rm orca
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags $(LDFLAGS) -o orca.exe cmd/orca.go
tar -zcvf $(DIST)/orca-windows-$(GIT_TAG).tgz orca.exe
rm orca.exe
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ Orca is a simplifier. It focuses on the world around Kubernetes and CI\CD, but i
3. [helm](https://helm.sh/) (required for runtime)

### Install
```
wget -qO- https://github.com/maorfr/orca/releases/download/<TAG>/orca.tar.gz | sudo tar xvz -C /usr/local/bin

```
Download the latest release from the [Releases page](https://github.com/maorfr/orca/releases)

### Use it in your CI\CD processes
```
Expand All @@ -27,9 +25,7 @@ Docker hub repository: https://hub.docker.com/r/maorfr/orca
Orca uses dep as a dependency management tool.

```
go get -u github.com/golang/dep/cmd/dep
dep ensure
go build -o orca cmd/orca.go
make
```

## Commands
Expand Down
18 changes: 18 additions & 0 deletions cmd/orca.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"io"
"log"
"os"
Expand Down Expand Up @@ -35,6 +36,7 @@ Instead of writing scripts on top of scripts, Orca holds all the logic.
cmd.AddCommand(NewGetCmd(out))
cmd.AddCommand(NewPushCmd(out))
cmd.AddCommand(NewCreateCmd(out))
cmd.AddCommand(NewVersionCmd(out))

return cmd
}
Expand Down Expand Up @@ -119,3 +121,19 @@ func NewCreateCmd(out io.Writer) *cobra.Command {

return cmd
}

var GitTag, GitCommit string

// NewVersionCmd prints version information
func NewVersionCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Print version information",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Version %s (git-%s)\n", GitTag, GitCommit)
},
}

return cmd
}

0 comments on commit 9e2e765

Please sign in to comment.