Skip to content

Commit

Permalink
Merge branch 'ugol:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ram-pi authored Aug 18, 2024
2 parents f50114f + 37970bc commit 3d7f560
Show file tree
Hide file tree
Showing 56 changed files with 1,866 additions and 598 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM golang AS builder
MAINTAINER Ugo Landini <[email protected]>

ARG VERSION=0.3.9
ARG GOVERSION=$(go version)
ARG USER=$(id -u -n)
ARG TIME=$(date)

Expand All @@ -12,7 +13,7 @@ COPY . .
RUN go install github.com/actgardner/gogen-avro/v10/cmd/...@latest
RUN go generate pkg/generator/generate.go
RUN go get -u -d -v
RUN CGO_ENABLED=1 GOOS=linux go build -tags static_all -v -ldflags="-X 'github.com/ugol/jr/pkg/cmd.Version=${VERSION}' -X 'github.com/ugol/jr/pkg/cmd.BuildUser=${USER}' -X 'github.com/ugol/jr/pkg/cmd.BuildTime=${TIME}'" -o build/jr jr.go
RUN CGO_ENABLED=1 GOOS=linux go build -tags static_all -v -ldflags="-X 'github.com/ugol/jr/pkg/cmd.Version=${VERSION}' -X 'github.com/ugol/jr/pkg/cmd.GoVersion=${GOVERSION}' -X 'github.com/ugol/jr/pkg/cmd.BuildUser=${USER}' -X 'github.com/ugol/jr/pkg/cmd.BuildTime=${TIME}'" -o build/jr jr.go

FROM registry.access.redhat.com/ubi9/ubi-micro

Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM golang:1.22-alpine AS builder
MAINTAINER Ugo Landini <[email protected]>

ARG VERSION=0.3.9
ARG GOVERSION=$(go version)
ARG USER=$(id -u -n)
ARG TIME=$(date)

Expand All @@ -23,7 +24,7 @@ WORKDIR /go/src/github.com/ugol/jr
COPY . .

RUN go get -u -d -v
RUN CGO_ENABLED=1 GOOS=linux go build -tags musl -v -ldflags="-X 'github.com/ugol/jr/cmd.Version=${VERSION}' -X 'github.com/ugol/jr/cmd.BuildUser=${USER}' -X 'github.com/ugol/jr/cmd.BuildTime=${TIME}'" -o build/jr jr.go
RUN CGO_ENABLED=1 GOOS=linux go build -tags musl -v -ldflags="-X 'github.com/ugol/jr/cmd.Version=${VERSION}' 'github.com/ugol/jr/pkg/cmd.GoVersion=${GOVERSION}' -X 'github.com/ugol/jr/cmd.BuildUser=${USER}' -X 'github.com/ugol/jr/cmd.BuildTime=${TIME}'" -o build/jr jr.go

FROM alpine
COPY --from=builder /etc/passwd /etc/passwd
Expand Down
40 changes: 40 additions & 0 deletions Dockerfile.scratch
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM golang:1.22-alpine AS builder
MAINTAINER Ugo Landini <[email protected]>

ARG VERSION=0.3.9
ARG GOVERSION=$(go version)
ARG USER=$(id -u -n)
ARG TIME=$(date)

RUN apk update \
&& apk add --no-cache git ca-certificates \
&& apk add --update gcc musl-dev libssl3 librdkafka-dev pkgconf \
&& update-ca-certificates

RUN adduser \
--disabled-password \
--gecos "" \
--home "/home/jr" \
--shell "/bin/sh" \
--uid "100001" \
"jr-user"

WORKDIR /go/src/github.com/ugol/jr
COPY . .

RUN go get -u -d -v
RUN CGO_ENABLED=1 GOOS=linux go build \
-tags musl -v \
-ldflags="-X 'github.com/ugol/jr/cmd.Version=${VERSION}' 'github.com/ugol/jr/pkg/cmd.GoVersion=${GOVERSION}' -X 'github.com/ugol/jr/cmd.BuildUser=${USER}' -X 'github.com/ugol/jr/cmd.BuildTime=${TIME}' -linkmode external -w -s -extldflags '-static'" \
-a -o build/jr jr.go

FROM scratch
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/src/github.com/ugol/jr/templates/ /home/jr/.jr/templates/
COPY --from=builder /go/src/github.com/ugol/jr/config/ /home/jr/.jr/
COPY --from=builder /go/src/github.com/ugol/jr/pkg/producers/kafka/*.examples /home/jr/.jr/kafka/
COPY --from=builder /go/src/github.com/ugol/jr/build/jr /bin/jr

USER jr-user:jr-user
64 changes: 60 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,58 @@
VERSION=0.3.9
GOVERSION=$(shell go version)
USER=$(shell id -u -n)
TIME=$(shell date)
JR_HOME=jr

ifndef XDG_DATA_DIRS
ifeq ($(OS), Windows_NT)
detectedOS := Windows
else
detectedOS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
endif

ifeq ($(detectedOS), Darwin)
JR_SYSTEM_DIR="$(HOME)/Library/Application Support"
endif
ifeq ($(detectedOS), Linux)
JR_SYSTEM_DIR="$(HOME)/.config"
endif
ifeq ($(detectedOS), Windows_NT)
JR_SYSTEM_DIR="$(LOCALAPPDATA)"
endif
else
JR_SYSTEM_DIR=$(XDG_DATA_DIRS)
endif

ifndef XDG_DATA_HOME
ifeq ($(OS), Windows_NT)
detectedOS := Windows
else
detectedOS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
endif

ifeq ($(detectedOS), Darwin)
JR_USER_DIR="$(HOME)/.local/share"
endif
ifeq ($(detectedOS), Linux)
JR_USER_DIR="$(HOME)/.local/share"
endif
ifeq ($(detectedOS), Windows_NT)
JR_USER_DIR="$(LOCALAPPDATA)" //@TODO
endif
else
JR_USER_DIR=$(XDG_DATA_HOME)
endif

hello:
@echo "JR,the JSON Random Generator"
@echo " Version: $(VERSION)"
@echo " Go Version: $(GOVERSION)"
@echo " Build User: $(USER)"
@echo " Build Time: $(TIME)"
@echo " Detected OS: $(detectedOS)"
@echo " JR System Dir: $(JR_SYSTEM_DIR)"
@echo " JR User Dir: $(JR_USER_DIR)"

install-gogen:
go install github.com/actgardner/gogen-avro/v10/cmd/...@latest
Expand All @@ -14,7 +63,11 @@ generate:

compile:
@echo "Compiling"
go build -v -ldflags="-X 'github.com/ugol/jr/pkg/cmd.Version=$(VERSION)' -X 'github.com/ugol/jr/pkg/cmd.BuildUser=$(USER)' -X 'github.com/ugol/jr/pkg/cmd.BuildTime=$(TIME)'" -o build/jr jr.go
go build -v -ldflags="-X 'github.com/ugol/jr/pkg/cmd.Version=$(VERSION)' \
-X 'github.com/ugol/jr/pkg/cmd.GoVersion=$(GOVERSION)' \
-X 'github.com/ugol/jr/pkg/cmd.BuildUser=$(USER)' \
-X 'github.com/ugol/jr/pkg/cmd.BuildTime=$(TIME)'" \
-o build/jr jr.go

run: compile
./build/jr
Expand Down Expand Up @@ -45,13 +98,16 @@ help: hello
@echo ''

copy_templates:
mkdir -p ~/.jr/kafka && cp -r templates ~/.jr/ && cp -r pkg/producers/kafka/*.properties.example ~/.jr/kafka/
mkdir -p $(JR_SYSTEM_DIR)/$(JR_HOME)/kafka && \
cp -r templates $(JR_SYSTEM_DIR)/$(JR_HOME) && \
cp -r pkg/producers/kafka/*.properties.example $(JR_SYSTEM_DIR)/$(JR_HOME)/kafka/

copy_config:
mkdir -p ~/.jr && cp config/* ~/.jr/
mkdir -p $(JR_SYSTEM_DIR)/$(JR_HOME) && \
cp config/* $(JR_SYSTEM_DIR)/$(JR_HOME)/

install:
install build/jr /usr/local/bin

all: hello install-gogen generate compile
all_offline: hello generate compile
all_offline: hello generate compile
14 changes: 0 additions & 14 deletions README-use-emitter-templates.md

This file was deleted.

18 changes: 13 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ JR is a CLI program that helps you to stream quality random data for your applic
![Build](https://github.com/ugol/jr/actions/workflows/go-mac.yml/badge.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Go Reference](https://pkg.go.dev/badge/github.com/ugol/jr.svg)](https://pkg.go.dev/github.com/ugol/jr)
[![Docker](https://img.shields.io/badge/docker-latest-blue.svg)](https://hub.docker.com/r/ugol/jr)
[![Docker](https://img.shields.io/badge/docker-latest-blue.svg)](https://hub.docker.com/r/jrndio/jr)

![JR-simple](https://user-images.githubusercontent.com/89472/229626362-70ddc95d-1090-4746-a20a-fbffba4193cd.gif)

Expand Down Expand Up @@ -50,10 +50,10 @@ JR is very straightforward to use. Here are some examples:
```bash
jr template list
````
Templates are in the directory `$JR_HOME/templates`. JR_HOME defaults to `~/.jr` and can be changed to a different dir, for example:
Templates are in the directory `$JR_SYSTEM_DIR/templates`. JR_SYSTEM_DIR defaults to `$XDG_CONFIGDIR` and can be changed to a different dir, for example:

```bash
JR_HOME=~/jrconfig/ jr template list
JR_SYSTEM_DIR=~/jrconfig/ jr template list
````
Templates with parsing issues are showed in <font color='red'>red</font>, Templates with no parsing issues are showed in <font color='green'>green</font>
Expand All @@ -74,11 +74,11 @@ jr run net_device
### Using Docker
You can also use a [![Docker](https://img.shields.io/badge/docker-latest-blue.svg)](https://hub.docker.com/r/ugol/jr)
You can also use a [![Docker](https://img.shields.io/badge/docker-latest-blue.svg)](https://hub.docker.com/r/jrndio/jr)
image if you prefer.
```bash
docker run -it ugol/jr:latest jr run net_device
docker run -it jrndio/jr:latest jr run net_device
```
### Other options for templates
Expand Down Expand Up @@ -141,3 +141,11 @@ jr run net_device -n 2 -f 100ms -d 1m --kcat | jq
parse error: Expected value before ',' at line 1, column 5
```
## Distributed Testing
JR can be run as a distributed data generation.
At the moment the following testing tools are supported:
- [k6](./k6/exec/)
- [locust](./locust/)
8 changes: 8 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
v0.3.9
- added key calculation directly from the template value
- added distributed JR with Locust and K6
- new Docker image from scratch
- added several GUI features
- added http producer
-

v0.3.8
- moved to librdkafka 2.5.0
- added inject function
Expand Down
61 changes: 56 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ go 1.22.4
require (
cloud.google.com/go/storage v1.43.0
github.com/actgardner/gogen-avro/v10 v10.2.1
github.com/adrg/xdg v0.5.0
github.com/aws/aws-sdk-go v1.54.14
github.com/confluentinc/confluent-kafka-go/v2 v2.5.0
github.com/elastic/go-elasticsearch/v8 v8.14.0
github.com/go-chi/chi/v5 v5.1.0
github.com/go-resty/resty/v2 v2.14.0
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/gorilla/sessions v1.3.0
github.com/jarcoal/httpmock v1.3.1
github.com/redis/go-redis/v9 v9.5.3
github.com/rs/zerolog v1.33.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/squeeze69/generacodicefiscale v1.0.5
Expand All @@ -24,25 +30,71 @@ require (
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.8 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 // indirect
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.1.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1 // indirect
github.com/aws/aws-sdk-go-v2 v1.26.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.10 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.10 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect
github.com/aws/aws-sdk-go-v2/service/kms v1.30.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.4 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cenkalti/backoff/v3 v3.0.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang-jwt/jwt/v5 v5.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.5 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/hamba/avro/v2 v2.20.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/vault/api v1.12.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/tink-crypto/tink-go-gcpkms/v2 v2.1.0 // indirect
github.com/tink-crypto/tink-go-hcvault/v2 v2.1.0 // indirect
github.com/tink-crypto/tink-go/v2 v2.1.0 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
Expand All @@ -55,12 +107,12 @@ require (
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/time v0.6.0 // indirect
google.golang.org/api v0.187.0 // indirect
google.golang.org/genproto v0.0.0-20240624140628-dc46fd24d27d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect
Expand All @@ -74,7 +126,6 @@ require (
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/heetch/avro v0.4.5 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.12.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand All @@ -86,7 +137,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/squeeze69/codicefiscale v1.0.4 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/sys v0.22.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 3d7f560

Please sign in to comment.