Skip to content

Commit

Permalink
Implement releases:
Browse files Browse the repository at this point in the history
- add GH Actions default/releases workflows: run lint/test on Default, build docker images and binary on Release.
- add goreleaser handler for releases events.
- add git tag into app version string.
- add Dockerfile.
- add docker related commands into README.
  • Loading branch information
lesovsky committed Dec 19, 2020
1 parent cab037a commit 9b2e96a
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 13 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Default

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run lint
run: make lint
- name: Run test
run: make test
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: Release

on:
push:
tags: [ v* ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run lint
run: make lint
- name: Run test
run: make test

build:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build image
run: make docker-build
- name: Log in to Docker Hub
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
- name: Push image to Docker Hub
run: make docker-push

goreleaser:
runs-on: ubuntu-latest
needs: [ test, build ]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-go@v2
with:
go-version: 1.15
- uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 15 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
builds:
- binary: noisia
goarch: [amd64]
goos:
- linux
archives:
- builds: [noisia]
changelog:
sort: asc
nfpms:
- vendor: noisia
homepage: https://github.com/lesovsky/noisia
maintainer: Alexey Lesovsky
description: Harmful workload generator for PostgreSQL
formats: [deb]
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# stage 1: build
FROM golang:1.15 as build
LABEL stage=intermediate
WORKDIR /app
COPY . .
RUN make build

# stage 2: scratch
FROM scratch as scratch
COPY --from=build /app/bin/noisia /bin/noisia
CMD ["noisia"]
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
APPNAME = noisia

TAG=$(shell git describe --tags |cut -d- -f1)
COMMIT=$(shell git rev-parse --short HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)

LDFLAGS = -a -installsuffix cgo -ldflags "-X main.appName=${APPNAME} -X main.gitCommit=${COMMIT} -X main.gitBranch=${BRANCH}"
LDFLAGS = -a -installsuffix cgo -ldflags "-X main.appName=${APPNAME} -X main.gitTag=${TAG} -X main.gitCommit=${COMMIT} -X main.gitBranch=${BRANCH}"

.PHONY: help clean lint test race build
.PHONY: help clean dep lint test build build-docker

.DEFAULT_GOAL := help

Expand All @@ -31,3 +32,12 @@ test: dep ## Run tests
build: dep ## Build
mkdir -p ./bin
CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} go build ${LDFLAGS} -o bin/${APPNAME} ./cmd

docker-build: ## Build docker image
docker build -t lesovsky/${APPNAME}:${TAG} .
docker image prune --force --filter label=stage=intermediate
docker tag lesovsky/${APPNAME}:${TAG} lesovsky/${APPNAME}:latest

docker-push: ## Push docker image to the registry
docker push lesovsky/${APPNAME}:${COMMIT}
docker push lesovsky/${APPNAME}:latest
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@
- `failed connections` - exhaust connections pool (other clients can't connect to Postgres)
- ...see built-in help for more runtime options.

#### Usage
Install `golang`, clone the repo and run `make build`. Check `bin/` directory for `noisia` executable.
#### Disclaimer

ATTENTION: USE ONLY FOR TESTING PURPOSES, DO NOT EXECUTE NOISIA AGAINST PRODUCTION, RECKLESS USAGE WILL CAUSE PROBLEMS.

DISCLAIMER: THIS SOFTWARE PROVIDED AS-IS WITH NO CARES AND GUARANTEES RELATED TO YOUR DATABASES. USE AT YOUR OWN RISK.


#### Installation and usage
Check out [releases](https://github.com/lesovsky/noisia/releases) page.

#### Using Docker
```shell script
docker pull lesovsky/noisia:latest
docker run --rm -ti lesovsky/noisia:latest noisia --help
```

#### Using in your own code
You can import `noisia` and use necessary workloads in your code. Always use contexts to avoid infinite run. See tiny example below:
Expand Down Expand Up @@ -44,14 +57,9 @@ func main() {
```

#### TODO/Ideas:
- sequential scans

#### Disclaimer

ATTENTION: USE ONLY FOR TESTING PURPOSES, DO NOT EXECUTE NOISIA AGAINST PRODUCTION, RECKLESS USAGE WILL CAUSE PROBLEMS.

DISCLAIMER: THIS SOFTWARE PROVIDED AS-IS WITH NO CARES AND GUARANTEES RELATED TO YOUR DATABASES. USE AT YOUR OWN RISK.
If you have any ideas, feel free to open a [discussion](https://github.com/lesovsky/noisia/discussions).

[ ] sequential scans

#### License
BSD-3. See [LICENSE](LICENSE) for more details.
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var (
appName, gitCommit, gitBranch string
appName, gitTag, gitCommit, gitBranch string
)

func main() {
Expand Down Expand Up @@ -47,7 +47,7 @@ func main() {
logger := zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}).Level(zerolog.InfoLevel).With().Timestamp().Logger()

if *showVersion {
fmt.Printf("%s %s-%s\n", appName, gitCommit, gitBranch)
fmt.Printf("%s %s %s-%s\n", appName, gitTag, gitCommit, gitBranch)
os.Exit(0)
}

Expand Down

0 comments on commit 9b2e96a

Please sign in to comment.