Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dipjyotimetia committed Mar 29, 2024
1 parent 4f7c268 commit 920e27f
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 105 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
with:
go-version: '1.22'
- name: Run tests
run: make test
run: make test
- name: Compose down
run: docker-compose down --rmi all
- name: check logs
run: docker compose logs -t -f event-stream
18 changes: 17 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Build stage
FROM golang:1.22.1-bullseye as builder

LABEL author="Dipjyoti Metia"
LABEL version="1.0"

ENV CGO_ENABLED=0
ENV GO111MODULE=on

Expand All @@ -14,14 +18,26 @@ COPY . .
RUN --mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 GOOS=linux go build -a -o ./server ./cmd

# Final stage
FROM debian:buster-slim

WORKDIR /app

RUN set -x && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates && \
rm -rf /var/lib/apt/lists/*

# Create a group and user
RUN groupadd -r app && useradd -r -g app app

# Change the ownership of the /app directory to our app user
RUN chown -R app:app /app

# Switch to 'app' user
USER app

COPY --from=builder /app/server /app/server

EXPOSE 8083

ENTRYPOINT ["/app/server"]
ENTRYPOINT ["/app/server"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Dipjyoti Metia
Copyright (c) 2024 Dipjyoti Metia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 4 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"fmt"
"log"
"os"
"os/signal"
Expand Down Expand Up @@ -57,8 +56,10 @@ func main() {
signal.Notify(c, os.Interrupt, syscall.SIGTERM) // When an interrupt or termination signal is sent, notify the channel

_ = <-c // This blocks the main thread until an interrupt is received
fmt.Println("Gracefully shutting down...")
_ = app.Shutdown()
log.Println("Gracefully shutting down...")
if err := app.Shutdown(); err != nil {
log.Printf("Error during shutdown: %v", err)
}

log.Println("Running cleanup tasks...")
cc.Close()
Expand Down
37 changes: 22 additions & 15 deletions docker/create_topics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
# Install curl
apt-get update && apt-get install -y curl

# Connect to kafka and create topics with schema
rpk --brokers kafka:29092 topic create expense-topic
rpk --brokers kafka:29092 topic create payment-topic
rpk --brokers kafka:29092 topic create transaction-topic

# Add schema to the Schema Registry
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data @/expense.json http://kafka:8081/subjects/expense-topic-value/versions
BROKER="kafka:29092"
SCHEMA_REGISTRY="http://kafka:8081/subjects"

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data @/payment.json http://kafka:8081/subjects/payment-topic-value/versions
# Connect to kafka and create topics with schema
for TOPIC in expense payment transaction
do
rpk --brokers $BROKER topic create ${TOPIC}-topic
if [ $? -ne 0 ]; then
echo "Failed to create topic ${TOPIC}-topic"
exit 1
fi

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data @/transaction.json http://kafka:8081/subjects/transaction-topic-value/versions
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data @/${TOPIC}.json $SCHEMA_REGISTRY/${TOPIC}-topic-value/versions
if [ $? -ne 0 ]; then
echo "Failed to add schema for ${TOPIC}-topic"
exit 1
fi

rpk --brokers kafka:29092 topic info expense-topic
rpk --brokers kafka:29092 topic info payment-topic
rpk --brokers kafka:29092 topic info transaction-topic
rpk --brokers $BROKER topic info ${TOPIC}-topic
if [ $? -ne 0 ]; then
echo "Failed to get info for ${TOPIC}-topic"
exit 1
fi
done
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ require (
github.com/goccy/go-json v0.10.2
github.com/gofiber/fiber/v2 v2.52.4
github.com/hamba/avro/v2 v2.20.1
github.com/linkedin/goavro/v2 v2.12.0
github.com/twmb/franz-go v1.16.1
github.com/twmb/franz-go/pkg/sr v0.0.0-20240307025822-351e7fae879c
)

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.7 // indirect
Expand All @@ -26,6 +24,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pierrec/lz4/v4 v4.1.19 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/stretchr/testify v1.7.5 // indirect
github.com/twmb/franz-go/pkg/kmsg v1.7.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM=
github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand All @@ -21,8 +18,6 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/linkedin/goavro/v2 v2.12.0 h1:rIQQSj8jdAUlKQh6DttK8wCRv4t4QO09g1C4aBWXslg=
github.com/linkedin/goavro/v2 v2.12.0/go.mod h1:KXx+erlq+RPlGSPmLF7xGo6SAbh8sCQ53x064+ioxhk=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand Down
76 changes: 0 additions & 76 deletions pkg/avro/avro.go

This file was deleted.

2 changes: 1 addition & 1 deletion script/certs-docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=
RUN cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=server server.json | cfssljson -bare server
RUN cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=client client.json | cfssljson -bare client

FROM debian:11-slim
FROM debian:12-slim

COPY --from=cfssl /app/*.pem /app/*.csr /certs/

Expand Down

0 comments on commit 920e27f

Please sign in to comment.