Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add draft of leaf to operator mode #71

Draft
wants to merge 10 commits into
base: mirror-across-leafs
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions cmd/nbe/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,22 @@ func (r *ComposeRunner) Run(imageTag string) error {
exampleDir := filepath.Dir(clientDir)
lang := filepath.Base(example)

composeFile := filepath.Join(exampleDir, "docker-compose.yaml")
// Check client directory first, fallback to example directory, finally the defaults.
composeFile := filepath.Join(clientDir, "docker-compose.yaml")
if _, err := os.Stat(composeFile); err != nil {
if os.IsNotExist(err) {
if !os.IsNotExist(err) {
return err
}
composeFile = filepath.Join(exampleDir, "docker-compose.yaml")
if _, err := os.Stat(composeFile); err != nil {
if !os.IsNotExist(err) {
return err
}
if r.Cluster {
composeFile = filepath.Join(r.Repo, "docker", "docker-compose.cluster.yaml")
} else {
composeFile = filepath.Join(r.Repo, "docker", "docker-compose.yaml")
}
} else {
return err
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/nbe/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bruth/nats-by-example/cmd/nbe

go 1.18
go 1.19

require (
github.com/alecthomas/chroma v0.10.0
Expand Down
3 changes: 3 additions & 0 deletions cmd/nbe/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ func readClientDir(path, name string) (*Client, error) {
defer f.Close()

blocks, source, err := parseReader(lang, f)
if err != nil {
return nil, err
}
x.Language = lang
x.MainFile = mainFile
x.Blocks = blocks
Expand Down
38 changes: 36 additions & 2 deletions cmd/nbe/recording.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package main

import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
)

Expand Down Expand Up @@ -35,13 +38,18 @@ func generateRecording(repo, example string, recreate bool) error {

name := strings.TrimPrefix(example, "examples/")

tempFile, _ := ioutil.TempFile("", "")
tempName := tempFile.Name()
tempFile.Close()
defer os.Remove(tempName)

// Generate the recording using the pre-built image.
c := exec.Command(
"asciinema", "rec",
"--overwrite",
"--command", fmt.Sprintf("nbe run --no-ansi=true --quiet --image=%s %s", image, name),
"--title", fmt.Sprintf("NATS by Example: %s", name),
castFile,
tempName,
)

c.Stdout = os.Stdout
Expand All @@ -51,9 +59,17 @@ func generateRecording(repo, example string, recreate bool) error {
if err != nil {
return fmt.Errorf("asciinema rec: %w", err)
}

contents, err := ioutil.ReadFile(tempName)
if err != nil {
return err
}

contents = removeComposeLines(contents)

ioutil.WriteFile(castFile, contents, 0644)
}

// TODO: remove container startup prefix...
c := exec.Command(
"asciinema", "cat",
castFile,
Expand All @@ -65,3 +81,21 @@ func generateRecording(repo, example string, recreate bool) error {

return ioutil.WriteFile(outputFile, output, 0644)
}

func removeComposeLines(output []byte) []byte {
re := regexp.MustCompile(`"(Network|Container)\s+[^\s]+\s+(Creating|Created|Starting|Started)`)

buf := bytes.NewBuffer(nil)
sc := bufio.NewScanner(bytes.NewReader(output))

for sc.Scan() {
line := sc.Bytes()

if re.Find(line) == nil {
buf.Write(line)
buf.WriteByte('\n')
}
}

return buf.Bytes()
}
9 changes: 7 additions & 2 deletions docker/cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
FROM natsio/nats-box:0.13.0
FROM natsio/nats-box:0.13.2

RUN apk add bash curl

COPY --from=nats:2.9.8 /nats-server /usr/local/bin/

COPY . .

CMD ["main.sh"]
ENTRYPOINT ["bash"]

CMD ["main.sh"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.9'
services:
app:
image: ${IMAGE_TAG}
image: ${IMAGE_TAG}
2 changes: 1 addition & 1 deletion docker/deno/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM denoland/deno:1.23.3
FROM denoland/deno:1.28.2

COPY . .

Expand Down
16 changes: 3 additions & 13 deletions docker/docker-compose.cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.9'
services:
nats1:
image: docker.io/nats:2.9.0
image: docker.io/nats:2.9.8
command:
- "--debug"
- "--name=nats1"
Expand All @@ -10,12 +10,9 @@ services:
- "--routes=nats-route://nats1:6222,nats-route://nats2:6222,nats-route://nats3:6222"
- "--http_port=8222"
- "--js"
ports:
- "14222:4222"
- "18222:8222"

nats2:
image: docker.io/nats:2.9.0
image: docker.io/nats:2.9.8
command:
- "--debug"
- "--name=nats2"
Expand All @@ -24,12 +21,9 @@ services:
- "--routes=nats-route://nats1:6222,nats-route://nats2:6222,nats-route://nats3:6222"
- "--http_port=8222"
- "--js"
ports:
- "24222:4222"
- "28222:8222"

nats3:
image: docker.io/nats:2.9.0
image: docker.io/nats:2.9.8
command:
- "--debug"
- "--name=nats3"
Expand All @@ -38,9 +32,6 @@ services:
- "--routes=nats-route://nats1:6222,nats-route://nats2:6222,nats-route://nats3:6222"
- "--http_port=8222"
- "--js"
ports:
- "34222:4222"
- "38222:8222"

app:
image: ${IMAGE_TAG}
Expand All @@ -50,4 +41,3 @@ services:
- nats1
- nats2
- nats3

5 changes: 1 addition & 4 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
version: '3.9'
services:
nats:
image: docker.io/nats:2.9.0
image: docker.io/nats:2.9.8
command:
- "--debug"
- "--http_port=8222"
- "--js"
ports:
- "14222:4222"
- "18222:8222"

app:
image: ${IMAGE_TAG}
Expand Down
2 changes: 1 addition & 1 deletion docker/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18-alpine AS build
FROM golang:1.19-alpine AS build

WORKDIR /opt/app

Expand Down
11 changes: 4 additions & 7 deletions docker/go/go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
module github.com/ConnectEverything/nats-by-example/go

go 1.18

require github.com/nats-io/nats.go v1.16.0
go 1.19

require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/nats-io/nats-server/v2 v2.8.4 // indirect
github.com/nats-io/jwt/v2 v2.3.0 // indirect
github.com/nats-io/nats.go v1.20.0 // indirect
github.com/nats-io/nkeys v0.3.0 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
google.golang.org/protobuf v1.28.0 // indirect
golang.org/x/crypto v0.3.0 // indirect
)
26 changes: 6 additions & 20 deletions docker/go/go.sum
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/klauspost/compress v1.14.4 h1:eijASRJcobkVtSt81Olfh7JX43osYLwy5krOJo6YEu4=
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
github.com/nats-io/jwt/v2 v2.2.1-0.20220330180145-442af02fd36a h1:lem6QCvxR0Y28gth9P+wV2K/zYUUAkJ+55U8cpS0p5I=
github.com/nats-io/nats-server/v2 v2.8.4 h1:0jQzze1T9mECg8YZEl8+WYUXb9JKluJfCBriPUtluB4=
github.com/nats-io/nats-server/v2 v2.8.4/go.mod h1:8zZa+Al3WsESfmgSs98Fi06dRWLH5Bnq90m5bKD/eT4=
github.com/nats-io/nats.go v1.16.0 h1:zvLE7fGBQYW6MWaFaRdsgm9qT39PJDQoju+DS8KsO1g=
github.com/nats-io/nats.go v1.16.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
github.com/nats-io/jwt/v2 v2.3.0 h1:z2mA1a7tIf5ShggOFlR1oBPgd6hGqcDYsISxZByUzdI=
github.com/nats-io/jwt/v2 v2.3.0/go.mod h1:0tqz9Hlu6bCBFLWAASKhE5vUA4c24L9KPUUgvwumE/k=
github.com/nats-io/nats.go v1.20.0 h1:T8JJnQfVSdh1CzGiwAOv5hEobYCBho/0EupGznYw0oM=
github.com/nats-io/nats.go v1.20.0/go.mod h1:tLqubohF7t4z3du1QDPYJIQQyhb4wl6DhjxEajSI7UA=
github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38=
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220111092808-5a964db01320 h1:0jf+tOCoZ3LyutmCOWpVni1chK4VfFLhRsDK7MhqGRY=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 h1:GZokNIeuVkl3aZHJchRrr13WCsols02MLUcz1U9is6M=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
2 changes: 1 addition & 1 deletion docker/java/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM gradle:7.5.0-jdk8-jammy AS build
FROM gradle:7.5.1-jdk8-jammy AS build
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN mkdir -p src/main/java/example
Expand Down
2 changes: 1 addition & 1 deletion docker/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repositories {
}

dependencies {
implementation 'io.nats:jnats:2.15.5'
implementation 'io.nats:jnats:2.16.5'
}

apply plugin: 'java'
Expand Down
2 changes: 1 addition & 1 deletion docker/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:slim
FROM node:19.1.0-slim

WORKDIR /opt/app

Expand Down
2 changes: 1 addition & 1 deletion docker/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10
FROM python:3.10.8

COPY requirements.txt ./
RUN pip install -r requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion docker/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nats-py[nkeys]==2.1.4
nats-py[nkeys]==2.2.0
2 changes: 1 addition & 1 deletion docker/rust/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.62-slim AS build
FROM rust:1.65.0-slim AS build

WORKDIR /opt/app

Expand Down
Loading