Skip to content

Commit c25ff83

Browse files
committed
created Dockerfile and Makefile for replayer
1 parent 9bf8214 commit c25ff83

4 files changed

Lines changed: 92 additions & 1 deletion

File tree

Dockerfile.replayer

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Build stage
2+
FROM devopsworks/golang-upx:1.15 AS builder
3+
ENV GO111MODULE=on \
4+
CGO_ENABLED=0 \
5+
GOOS=linux \
6+
GOARCH=amd64
7+
COPY . /app
8+
WORKDIR /app/cmd/slowql-replayer
9+
RUN make build && \
10+
strip ./out/bin/slowql-replayer && \
11+
/usr/local/bin/upx -9 ./out/bin/slowql-replayer
12+
13+
# Run stage
14+
FROM gcr.io/distroless/base-debian10
15+
COPY --from=builder /app/cmd/slowql-replayer/out/bin /app
16+
COPY --from=builder /app/slowquery.log /app
17+
WORKDIR /app
18+
ENTRYPOINT ["./slowql-replayer"]

cmd/slowql-replayer/Makefile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
GOCMD=go
3+
GOTEST=$(GOCMD) test
4+
GOVET=$(GOCMD) vet
5+
BINARY_NAME=slowql-replayer
6+
BUILD_DIR=./out/bin/
7+
BUILD_ROOT=./out
8+
9+
GREEN := $(shell tput -Txterm setaf 2)
10+
YELLOW := $(shell tput -Txterm setaf 3)
11+
WHITE := $(shell tput -Txterm setaf 7)
12+
RESET := $(shell tput -Txterm sgr0)
13+
14+
.PHONY: all build clean
15+
16+
all: help
17+
18+
## Build:
19+
build: ## Build the Go project
20+
mkdir -p ./out/bin
21+
GO111MODULE=on $(GOCMD) build -o $(BUILD_DIR)$(BINARY_NAME) .
22+
@echo "${GREEN}[*]${RESET} ${BINARY_NAME} successfully built in ${YELLOW}${BUILD_DIR}${BINARY_NAME}${RESET}"
23+
24+
clean: ## Clean all the files and binaries generated by the Makefile
25+
rm -rf $(BUILD_ROOT)
26+
rm -f ./profile.cov
27+
28+
## Test:
29+
test: ## Run the tests of the project
30+
$(GOTEST) -v -race ./...
31+
32+
coverage: ## Run the tests of the project and export the coverage
33+
$(GOTEST) -cover -covermode=count -coverprofile=profile.cov ./...
34+
$(GOCMD) tool cover -func profile.cov
35+
36+
## Help:
37+
help: ## Show this help
38+
@echo ''
39+
@echo 'Usage:'
40+
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
41+
@echo ''
42+
@echo 'Targets:'
43+
@awk 'BEGIN {FS = ":.*?## "} { \
44+
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
45+
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
46+
}' $(MAKEFILE_LIST)
47+

cmd/slowql-replayer/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,26 @@ A tool to replay queries from a slow query log file.
44

55
## Installation
66

7+
There is multiple ways to get `slowql-replayer`.
8+
9+
### By using `go install`
10+
711
```
812
$ go install github.com/devops-works/slowql/cmd/slowql-replayer
913
```
1014

15+
### By cloning the repo and building it
16+
17+
```
18+
$ git clone https://github.com/devops-works/slowql
19+
$ cd slowql/cmd/slowql-replayer
20+
$ make build
21+
```
22+
23+
### By downloading the pre-built binary
24+
25+
You can find the latest version in the [releases](https://github.com/devops-works/slowql/releases)
26+
1127
## Usage
1228

1329
```
@@ -73,6 +89,16 @@ Statistics
7389
└─ Replayer speed: -0.0064%
7490
```
7591

92+
## Docker
93+
94+
Build the image (you need to be at the root of the repo):
95+
96+
```
97+
$ docker build -f Dockerfile.replayer -t slowql-replayer
98+
...
99+
$ docker run --rm -it slowql-replayer [OPTIONS]
100+
```
101+
76102
### Adjustments
77103

78104
#### Speed

cmd/slowql-replayer/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func main() {
7070

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

0 commit comments

Comments
 (0)