Skip to content

Commit

Permalink
Add compression level CLI option (#84)
Browse files Browse the repository at this point in the history
* Add a new CLI option to specify the compression level

Fixes #72

- Refactor Makefile
- Remove test script in favor of Makefile
- Automate usage generation
- Upgrade Golangci-lint

* Update CONTRIBUTING docs

* Migrate to structured logging

* Upgrade to go 1.13

* Remove clutter from error messages

* Update CHANGELOG, README and dependencies

* Upgrade goreleaser

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
  • Loading branch information
kakkoyun authored Nov 4, 2019
1 parent 899b1d6 commit 50833a8
Show file tree
Hide file tree
Showing 33 changed files with 549 additions and 275 deletions.
22 changes: 11 additions & 11 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ steps:

- name: build
pull: true
image: golang:1.11-alpine
image: golang:1.13-alpine
commands:
- apk add --update make git
- make drone-cache

- name: test
pull: true
image: golang:1.11-alpine
image: golang:1.13-alpine
commands:
- go test -v -mod=vendor -cover ./...
environment:
Expand All @@ -42,17 +42,17 @@ steps:
- name: testcache
path: /drone/src/testcache/cache

- name: analyze
- name: lint
pull: true
image: golang:1.11-alpine
image: golang:1.13-alpine
commands:
- "wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.14.0"
- "wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.21.0"
- ./bin/golangci-lint run -v --enable-all -D gochecknoglobals
environment:
CGO_ENABLED: 0

- name: release-snapshot-dev
image: goreleaser/goreleaser:v0.109
image: goreleaser/goreleaser:v0.120
commands:
- apk add --update make upx
- goreleaser release --rm-dist --snapshot
Expand Down Expand Up @@ -149,7 +149,7 @@ steps:
path: /tmp/cache

- name: release-snapshot
image: goreleaser/goreleaser:v0.109
image: goreleaser/goreleaser:v0.120
commands:
- apk add --update make upx
- goreleaser release --rm-dist --snapshot
Expand Down Expand Up @@ -264,14 +264,14 @@ steps:

- name: build-after
pull: true
image: golang:1.11-alpine
image: golang:1.13-alpine
commands:
- apk add --update make git
- make drone-cache

- name: test-after
pull: true
image: golang:1.11-alpine
image: golang:1.13-alpine
commands:
- go test -v -mod=vendor -cover ./...
environment:
Expand Down Expand Up @@ -328,10 +328,10 @@ steps:
- git fetch --tags

- name: release
image: goreleaser/goreleaser:v0.109
image: goreleaser/goreleaser:v0.120
commands:
- apk add --update make upx
- goreleaser release
- make release
environment:
GITHUB_TOKEN:
from_secret: github_token
Expand Down
1 change: 1 addition & 0 deletions .errcheck_excludes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(github.com/go-kit/kit/log.Logger).Log
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ target
bin
testcache
backup
tmp
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,14 @@ run:
deadline: 1m
tests: false
modules-download-mode: vendor

linters:
enable-all: true
disable:
- gochecknoglobals

linters-settings:
errcheck:
exclude: .errcheck_excludes
lll:
line-length: 120
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
before:
hooks:
- make clean
- make fetch-dependencies
- make vendor
dist: target/dist
builds:
- env:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

[#84](https://github.com/meltwater/drone-cache/pull/84) Adds compression level option.
[#77](https://github.com/meltwater/drone-cache/pull/77) Adds a new CLI hidden flag to be used for tests.
[#68](https://github.com/meltwater/drone-cache/pull/68) Introduces new storage backend, sFTP.

Expand Down
20 changes: 11 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ the requirements below.
## Pull Request Process

0. Check out [Pull Request Checklist](#pull-request-checklist), ensure you have fulfilled each step.
1. Ensure any install or build dependencies are removed before the end of the layer when doing a
1. Check out [Uber Style Guide](https://github.com/uber-go/guide/blob/master/style.md), project tries to follow it, ensure you have fulfilled it as much as possible.
2. Ensure any install or build dependencies are removed before the end of the layer when doing a
build.
2. Please ensure the [README](README.md) and [DOCS](./DOCS.md) are up-to-date with details of changes to the command-line interface,
3. Please ensure the [README](README.md) and [DOCS](./DOCS.md) are up-to-date with details of changes to the command-line interface,
this includes new environment variables, exposed ports, useful file locations and container parameters.
3. **PLEASE ENSURE YOU DO NOT INTRODUCE BREAKING CHANGES.**
4. **PLEASE ENSURE BUG FIXES AND NEW FEATURES INCLUDE TESTS.**
5. You may merge the Pull Request in once you have the sign-off of one other maintainer/code owner,
4. **PLEASE ENSURE YOU DO NOT INTRODUCE BREAKING CHANGES.**
5. **PLEASE ENSURE BUG FIXES AND NEW FEATURES INCLUDE TESTS.**
6. You may merge the Pull Request in once you have the sign-off of one other maintainer/code owner,
or if you do not have permission to do that, you may request the second reviewer to merge it for you.

## Pull Request Checklist
Expand All @@ -43,12 +44,13 @@ the requirements below.
*Only concerns maintainers/code owners*

0. **PLEASE DO NOT INTRODUCE BREAKING CHANGES**
1. Increase the version numbers in any examples files and the README.md to the new version that this
1. Execute `make README.md`. This will update [usage](README.md#usage) section of [README.md](README.md) with latest CLI options
2. Increase the version numbers in any examples files and the README.md to the new version that this
release would represent. The versioning scheme we use is [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/meltwater/drone-cache/tags).

2. Ensure [CHANGELOG](CHANGELOG.md) is up-to-date with new version changes.
3. Update version references.
4. Create a tag on master. Any changes on master will trigger a release with given tag and `latest tag.
3. Ensure [CHANGELOG](CHANGELOG.md) is up-to-date with new version changes.
4. Update version references.
5. Create a tag on master. Any changes on master will trigger a release with given tag and `latest tag.

```console
$ git tag -am 'vX.X.X'
Expand Down
10 changes: 5 additions & 5 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ steps:
- 'vendor'

- name: build
image: golang:1.11-alpine
image: golang:1.13-alpine
pull: true
commands:
- apk add --update make git
Expand Down Expand Up @@ -160,7 +160,7 @@ steps:
path: /tmp/cache

- name: build
image: golang:1.11-alpine
image: golang:1.13-alpine
pull: true
commands:
- apk add --update make git
Expand Down Expand Up @@ -212,7 +212,7 @@ steps:
- 'vendor'

- name: build
image: golang:1.11-alpine
image: golang:1.13-alpine
pull: true
commands:
- apk add --update make git
Expand Down Expand Up @@ -260,7 +260,7 @@ steps:
- 'vendor'

- name: build
image: golang:1.11-alpine
image: golang:1.13-alpine
pull: true
commands:
- apk add --update make git
Expand Down Expand Up @@ -299,7 +299,7 @@ steps:
debug: true

- name: build
image: golang:1.11-alpine
image: golang:1.13-alpine
pull: true
commands:
- apk add --update make git
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.11-alpine AS builder
FROM golang:1.13-alpine AS builder
RUN apk add --update --no-cache ca-certificates tzdata && update-ca-certificates

RUN echo "[WARNING] Make sure you have run 'goreleaser release', before 'docker build'!"
Expand Down
94 changes: 72 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,114 @@ VERSION := $(strip $(shell [ -d .git ] && git describe --always --tags --dirty))
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%S%Z")
VCS_REF := $(strip $(shell [ -d .git ] && git rev-parse --short HEAD))

GO_PACKAGES=$(shell go list ./... | grep -v -E '/vendor/|/test')
GO_FILES:=$(shell find . -name \*.go -print)
GOPATH:=$(firstword $(subst :, ,$(shell go env GOPATH)))

GOLANGCI_LINT_VERSION=v1.21.0
GOLANGCI_LINT_BIN=$(GOPATH)/bin/golangci-lint
EMBEDMD_BIN=$(GOPATH)/bin/embedmd
GOTEST_BIN=$(GOPATH)/bin/gotest

.PHONY: default all
default: drone-cache
all: drone-cache

drone-cache: fetch-dependencies main.go $(wildcard *.go) $(wildcard */*.go)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=vendor -a -ldflags '-s -w' -o $@ .
drone-cache: vendor main.go $(wildcard *.go) $(wildcard */*.go)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=vendor -a -ldflags '-s -w -X main.version=$(VERSION)' -o $@ .

build: fetch-dependencies main.go $(wildcard *.go) $(wildcard */*.go)
go build -mod=vendor -a -ldflags '-s -w' -o drone-cache .
.PHONY: build
build: vendor main.go $(wildcard *.go) $(wildcard */*.go)
go build -mod=vendor -a -ldflags '-s -w -X main.version=$(VERSION)' -o drone-cache .

release:
.PHONY: release
release: build
goreleaser release --rm-dist

.PHONY: snapshot
snapshot:
goreleaser release --skip-publish --rm-dist --snapshot

.PHONY: clean
clean:
rm -f drone-cache
rm -rf target

.PHONY: default all clean release snapshot
tmp/help.txt: clean build
mkdir -p tmp
./drone-cache --help &> tmp/help.txt

fetch-dependencies:
@go mod vendor -v
README.md: tmp/help.txt
embedmd -w README.md

.PHONY: fetch-dependencies
tmp/docs.txt: clean build
mkdir -p tmp
# ./drone-cache --help &> tmp/help.txt
@echo "IMPLEMENT ME"

build-compressed: drone-cache
@upx drone-cache
DOCS.md: tmp/docs.txt
embedmd -w DOCS.md

.PHONY: vendor
vendor:
@go mod tidy
@go mod vendor -v

.PHONY: build-compressed
.PHONY: compress
compress: drone-cache
@upx drone-cache

docker-build: release Dockerfile
.PHONY: container
container: release Dockerfile
@docker build --build-arg BUILD_DATE="$(BUILD_DATE)" \
--build-arg VERSION="$(VERSION)" \
--build-arg VCS_REF="$(VCS_REF)" \
--build-arg DOCKERFILE_PATH="/Dockerfile" \
-t meltwater/drone-cache:latest .

docker-build-dev: snapshot Dockerfile
.PHONY: container-dev
container-dev: snapshot Dockerfile
@docker build --build-arg BUILD_DATE="$(BUILD_DATE)" \
--build-arg VERSION="$(VERSION)" \
--build-arg VCS_REF="$(VCS_REF)" \
--build-arg DOCKERFILE_PATH="/Dockerfile" \
--no-cache \
-t meltwater/drone-cache:dev .

docker-push: docker-build
.PHONY: container-push
container-push: container
docker push meltwater/drone-cache:latest

docker-push-dev: docker-build-dev
.PHONY: container-push-dev
container-push-dev: container-dev
docker push meltwater/drone-cache:dev

.PHONY: docker-build docker-push
.PHONY: test
test: $(GOTEST_BIN)
docker-compose up -d
mkdir -p ./testcache/cache
gotest -race -short -cover ./...

.PHONY: lint
lint: $(GOLANGCI_LINT_BIN)
# Check .golangci.yml for configuration
$(GOLANGCI_LINT_BIN) run -v --enable-all -c .golangci.yml

.PHONY: fix
fix: $(GOLANGCI_LINT_BIN) format
$(GOLANGCI_LINT_BIN) run --fix --enable-all -c .golangci.yml

.PHONY: format
format:
@gofmt -w -s $(GO_FILES)

test:
./test
$(GOTEST_BIN):
GO111MODULE=off go get -u github.com/rakyll/gotest

analyze:
golangci-lint run -v --enable-all -D gochecknoglobals
$(EMBEDMD_BIN):
GO111MODULE=off go get -u github.com/campoy/embedmd

.PHONY: test analyze
$(GOLANGCI_LINT_BIN):
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCI_LINT_VERSION)/install.sh \
| sed -e '/install -d/d' \
| sh -s -- -b $(GOPATH)/bin $(GOLANGCI_LINT_VERSION)
Loading

0 comments on commit 50833a8

Please sign in to comment.