Skip to content

Commit

Permalink
created Dockerfile and Makefile for replayer
Browse files Browse the repository at this point in the history
  • Loading branch information
eze-kiel committed Apr 9, 2021
1 parent 9bf8214 commit c25ff83
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Dockerfile.replayer
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Build stage
FROM devopsworks/golang-upx:1.15 AS builder
ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
COPY . /app
WORKDIR /app/cmd/slowql-replayer
RUN make build && \
strip ./out/bin/slowql-replayer && \
/usr/local/bin/upx -9 ./out/bin/slowql-replayer

# Run stage
FROM gcr.io/distroless/base-debian10
COPY --from=builder /app/cmd/slowql-replayer/out/bin /app
COPY --from=builder /app/slowquery.log /app
WORKDIR /app
ENTRYPOINT ["./slowql-replayer"]
47 changes: 47 additions & 0 deletions cmd/slowql-replayer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

GOCMD=go
GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet
BINARY_NAME=slowql-replayer
BUILD_DIR=./out/bin/
BUILD_ROOT=./out

GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)

.PHONY: all build clean

all: help

## Build:
build: ## Build the Go project
mkdir -p ./out/bin
GO111MODULE=on $(GOCMD) build -o $(BUILD_DIR)$(BINARY_NAME) .
@echo "${GREEN}[*]${RESET} ${BINARY_NAME} successfully built in ${YELLOW}${BUILD_DIR}${BINARY_NAME}${RESET}"

clean: ## Clean all the files and binaries generated by the Makefile
rm -rf $(BUILD_ROOT)
rm -f ./profile.cov

## Test:
test: ## Run the tests of the project
$(GOTEST) -v -race ./...

coverage: ## Run the tests of the project and export the coverage
$(GOTEST) -cover -covermode=count -coverprofile=profile.cov ./...
$(GOCMD) tool cover -func profile.cov

## Help:
help: ## Show this help
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)

26 changes: 26 additions & 0 deletions cmd/slowql-replayer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@ A tool to replay queries from a slow query log file.

## Installation

There is multiple ways to get `slowql-replayer`.

### By using `go install`

```
$ go install github.com/devops-works/slowql/cmd/slowql-replayer
```

### By cloning the repo and building it

```
$ git clone https://github.com/devops-works/slowql
$ cd slowql/cmd/slowql-replayer
$ make build
```

### By downloading the pre-built binary

You can find the latest version in the [releases](https://github.com/devops-works/slowql/releases)

## Usage

```
Expand Down Expand Up @@ -73,6 +89,16 @@ Statistics
└─ Replayer speed: -0.0064%
```

## Docker

Build the image (you need to be at the root of the repo):

```
$ docker build -f Dockerfile.replayer -t slowql-replayer
...
$ docker run --rm -it slowql-replayer [OPTIONS]
```

### Adjustments

#### Speed
Expand Down
2 changes: 1 addition & 1 deletion cmd/slowql-replayer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {

flag.StringVar(&opt.user, "u", "", "User to use to connect to database")
flag.StringVar(&opt.host, "h", "", "Addres of the database, with IP and port")
flag.StringVar(&opt.file, "f", "", "Slow query log file to use")
flag.StringVar(&opt.file, "f", "./slowquery.log", "Slow query log file to use")
flag.StringVar(&opt.kind, "k", "", "Kind of the database (mysql, mariadb...)")
flag.StringVar(&opt.database, "db", "", "Name of the database to use")
flag.StringVar(&opt.loglvl, "l", "info", "Logging level")
Expand Down

0 comments on commit c25ff83

Please sign in to comment.