Skip to content

Commit 5fb530c

Browse files
author
Cosmin Cojocar
authored
Merge pull request #219 from ccojocar/goreleaser
Use the goreleaser tool to perform releases
2 parents 5ba6475 + a8edd07 commit 5fb530c

File tree

6 files changed

+85
-39
lines changed

6 files changed

+85
-39
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
_obj
99
_test
1010
vendor
11+
dist
1112

1213
# Architecture specific extensions/prefixes
1314
*.[568vq]

.goreleaser.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
builds:
2+
- main : ./cmd/gosec/
3+
binary: gosec
4+
goos:
5+
- darwin
6+
- linux
7+
- windows
8+
goarch:
9+
- amd64
10+
ldflags: -X main.Version={{.Version}} -X main.GitTag={{.Tag}} -X main.BuildDate={{.Date}}
11+
env:
12+
- CGO_ENABLED=0
13+
14+
archive:
15+
files:
16+
- README.md
17+
- LICENSE.txt

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM golang:1.9.4-alpine3.7
22

33
ENV BIN=gosec
44

5-
COPY build/*-linux-amd64 /go/bin/$BIN
5+
COPY dist/linux_amd64/$BIN /go/bin/$BIN
66
COPY docker-entrypoint.sh /usr/local/bin
77

88
ENTRYPOINT ["docker-entrypoint.sh"]

Gopkg.lock

+38-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

+14-18
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,44 @@
11
GIT_TAG?= $(shell git describe --always --tags)
2-
BUILD_DATE = $(shell date +%Y-%m-%d)
32
BIN = gosec
4-
BUILD_CMD = go build -ldflags "-X main.Version=${VERSION} -X main.GitTag=${GIT_TAG} -X main.BuildDate=${BUILD_DATE}" -o build/$(BIN)-$(VERSION)-$${GOOS}-$${GOARCH} ./cmd/gosec/ &
53
FMT_CMD = $(gofmt -s -l -w $(find . -type f -name '*.go' -not -path './vendor/*') | tee /dev/stderr)
64
IMAGE_REPO = docker.io
75

86
default:
97
$(MAKE) bootstrap
108
$(MAKE) build
119

10+
bootstrap:
11+
dep ensure
12+
1213
test: bootstrap
1314
test -z '$(FMT_CMD)'
1415
go vet $(go list ./... | grep -v /vendor/)
1516
golint -set_exit_status $(shell go list ./... | grep -v vendor)
1617
gosec ./...
1718
ginkgo -r -v
18-
bootstrap:
19-
dep ensure
19+
2020
build:
2121
go build -o $(BIN) ./cmd/gosec/
22+
2223
clean:
23-
rm -rf build vendor
24+
rm -rf build vendor dist
2425
rm -f release image bootstrap $(BIN)
26+
2527
release: bootstrap
26-
ifndef VERSION
27-
$(error VERSION flag is not set. Run 'make release VERSION=<YOUR VERSION>'.)
28-
endif
29-
@echo "Running build command..."
30-
bash -c '\
31-
export GOOS=linux; export GOARCH=amd64; export CGO_ENABLED=0; $(BUILD_CMD) \
32-
wait \
33-
'
34-
touch release
28+
@echo "Releasing the gosec binary..."
29+
goreleaser release
3530

3631
image: release
3732
@echo "Building the Docker image..."
38-
docker build -t $(IMAGE_REPO)/$(BIN):$(VERSION) .
39-
docker tag $(IMAGE_REPO)/$(BIN):$(VERSION) $(IMAGE_REPO)/$(BIN):latest
33+
docker build -t $(IMAGE_REPO)/$(BIN):$(GIT_TAG) .
34+
docker tag $(IMAGE_REPO)/$(BIN):$(GIT_TAG) $(IMAGE_REPO)/$(BIN):latest
4035
touch image
4136

4237
image-push: image
4338
@echo "Pushing the Docker image..."
44-
docker push $(IMAGE_REPO)/$(BIN):$(VERSION)
39+
40+
docker push $(IMAGE_REPO)/$(BIN):$(GIT_TAG)
4541
docker push $(IMAGE_REPO)/$(BIN):latest
4642

47-
.PHONY: test build clean image-push
43+
.PHONY: test build clean release image image-push
4844

README.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -143,34 +143,35 @@ make test
143143

144144
#### Release Build
145145

146-
gosec can be released as follows:
146+
Make sure you have installed the [goreleaser](https://github.com/goreleaser/goreleaser) tool and then you can release gosec as follows:
147+
git tag 1.0.0
148+
export GITHUB_TOKEN=<YOUR GITHUB TOKEN>
149+
make release
147150

148-
```bash
149-
make release VERSION=2.0.0
150-
```
151-
152-
The released version of the tool is available in the `build` folder. The build information should be displayed in the usage text.
151+
The released version of the tool is available in the `dist` folder. The build information should be displayed in the usage text.
153152

154153
```
155-
./build/gosec-2.0.0-linux-amd64 -h
156-
154+
./dist/darwin_amd64/gosec -h
157155
gosec - Golang security checker
158156
159157
gosec analyzes Go source code to look for common programming mistakes that
160158
can lead to security problems.
161159
162-
VERSION: 2.0.0
163-
GIT TAG: 96489ff
164-
BUILD DATE: 2018-02-21
165-
160+
VERSION: 1.0.0
161+
GIT TAG: 1.0.0
162+
BUILD DATE: 2018-04-27T12:41:38Z
166163
```
167164

165+
Note that all released archives are also uploaded to GitHub.
166+
168167
#### Docker image
169168

170169
You can execute a release and build the docker image as follows:
171170

172171
```
173-
make image VERSION=2.0.0
172+
git tag <VERSION>
173+
export GITHUB_TOKEN=<Your GitHub token>
174+
make image
174175
```
175176

176177
Now you can run the gosec tool in a container against your local workspace:

0 commit comments

Comments
 (0)