Skip to content

Commit a04d0db

Browse files
Merge pull request #93 from owlistic-notes/nats
Migrate Kafka producer/consumer to Nats
2 parents d56811f + d61a504 commit a04d0db

31 files changed

+420
-757
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ jobs:
7474
platform: [arm64, amd64]
7575
include:
7676
- platform: arm64
77-
suffix: ""
77+
suffix: "-arm64"
7878
- platform: amd64
79-
suffix: "-amd64"
79+
suffix: ""
8080
steps:
8181
- name: Checkout Code
8282
uses: actions/checkout@v4
@@ -163,9 +163,9 @@ jobs:
163163
platform: [arm64, amd64]
164164
include:
165165
- platform: arm64
166-
suffix: ""
166+
suffix: "-arm64"
167167
- platform: amd64
168-
suffix: "-amd64"
168+
suffix: ""
169169
steps:
170170
- name: Checkout Code
171171
uses: actions/checkout@v4

.github/workflows/pull_request.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ jobs:
5353
platform: [arm64, amd64]
5454
include:
5555
- platform: arm64
56-
suffix: ""
56+
suffix: "-arm64"
5757
- platform: amd64
58-
suffix: "-amd64"
58+
suffix: ""
5959
steps:
6060
# Checkout code
6161
- name: Checkout Code
@@ -173,9 +173,9 @@ jobs:
173173
platform: [arm64, amd64]
174174
include:
175175
- platform: arm64
176-
suffix: ""
176+
suffix: "-arm64"
177177
- platform: amd64
178-
suffix: "-amd64"
178+
suffix: ""
179179
steps:
180180
# Checkout code
181181
- name: Checkout Code

.github/workflows/release.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ jobs:
5050
platform: [arm64, amd64]
5151
include:
5252
- platform: arm64
53+
suffix: "-arm64"
54+
is_default: false
55+
- platform: amd64
5356
suffix: ""
5457
is_default: true
55-
- platform: amd64
56-
suffix: "-amd64"
57-
is_default: false
5858
steps:
5959
# Checkout code to get the commit SHA
6060
- name: Checkout Code
@@ -97,7 +97,7 @@ jobs:
9797
echo "Pushing version tag"
9898
docker push ${VERSION_TAG}
9999
100-
# Tag as latest only for the default platform (ARM64)
100+
# Tag as latest only for the default platform
101101
if [[ "${{ matrix.is_default }}" == "true" ]]; then
102102
LATEST_TAG="ghcr.io/${{ github.repository }}:latest"
103103
echo "Tagging as latest: ${LATEST_TAG}"
@@ -116,11 +116,11 @@ jobs:
116116
platform: [arm64, amd64]
117117
include:
118118
- platform: arm64
119+
suffix: "-arm64"
120+
is_default: false
121+
- platform: amd64
119122
suffix: ""
120123
is_default: true
121-
- platform: amd64
122-
suffix: "-amd64"
123-
is_default: false
124124
steps:
125125
# Checkout code to get the commit SHA
126126
- name: Checkout Code

docker-compose.yml

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@ version: '3.8'
22

33
services:
44
owlistic:
5-
image: ghcr.io/owlistic-notes/owlistic:0.1.0
6-
# build:
7-
# context: ./src/backend
8-
# dockerfile: Dockerfile
9-
# args:
10-
# TARGETARCH: ${TARGETARCH:-arm64}
5+
# image: ghcr.io/owlistic-notes/owlistic:0.1.0
6+
build:
7+
context: ./src/backend
8+
dockerfile: Dockerfile
9+
args:
10+
TARGETARCH: ${TARGETARCH:-arm64}
1111
ports:
1212
- "8080:8080"
1313
depends_on:
1414
- postgres
15-
- kafka
15+
- nats
1616
environment:
1717
- APP_ORIGINS=http://localhost*,http://owlistic*,http://owlistic-app*
18+
- BROKER_ADDRESS=nats:4222
1819
- DB_HOST=postgres
1920
- DB_PORT=5432
2021
- DB_USER=admin
2122
- DB_PASSWORD=admin
2223
- DB_NAME=postgres
23-
- KAFKA_BROKER=kafka:9092
2424
networks:
2525
- server
2626
- events
2727
- db
2828

2929
owlistic-app:
30-
image: ghcr.io/owlistic-notes/owlistic-app:0.1.0
31-
# build:
32-
# context: ./src/frontend
33-
# dockerfile: Dockerfile
34-
# args:
35-
# TARGETARCH: ${TARGETARCH:-arm64}
30+
# image: ghcr.io/owlistic-notes/owlistic-app:0.1.0
31+
build:
32+
context: ./src/frontend
33+
dockerfile: Dockerfile
34+
args:
35+
TARGETARCH: ${TARGETARCH:-arm64}
3636
ports:
3737
- "80:80"
3838
depends_on:
@@ -50,33 +50,25 @@ services:
5050
networks:
5151
- db
5252

53-
kafka:
54-
image: bitnami/kafka:3
55-
environment:
56-
KAFKA_BROKER_ID: 1
57-
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
58-
ALLOW_PLAINTEXT_LISTENER: yes
59-
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
60-
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
61-
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
62-
ports:
63-
- "9092:9092"
64-
depends_on:
65-
- zookeeper
66-
networks:
67-
- events
68-
69-
zookeeper:
70-
image: bitnami/zookeeper:3
71-
environment:
72-
ALLOW_ANONYMOUS_LOGIN: yes
53+
nats:
54+
image: nats
55+
command:
56+
- --http_port
57+
- "8222"
58+
- -js
59+
- -sd
60+
- /var/lib/nats/data
7361
ports:
74-
- "2181:2181"
62+
- "4222:4222"
63+
- "8222:8222"
64+
volumes:
65+
- nats_data:/var/lib/nats/data
7566
networks:
7667
- events
7768

7869
volumes:
7970
postgres_data:
71+
nats_data:
8072

8173
networks:
8274
server:

src/backend/Dockerfile

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ ARG TARGETARCH
66

77
# Install librdkafka for Kafka client dependencies with Alpine packages
88
RUN apk add --no-cache \
9-
gcc \
10-
musl-dev \
11-
cyrus-sasl-dev
9+
build-base \
10+
gcc
1211

1312
# Set the working directory inside the container
1413
WORKDIR /app
@@ -22,23 +21,15 @@ RUN go mod download
2221
# Copy the rest of the source code
2322
COPY . .
2423

25-
# Build the application with proper linking flags for librdkafka
26-
# Adding -tags musl and removing -m64 flag via CGO_CFLAGS
27-
RUN CGO_ENABLED=1 GO111MODULE=on CGO_LDFLAGS="-lsasl2" \
24+
# Build the application
25+
RUN CGO_ENABLED=1 GO111MODULE=on \
2826
GOOS=linux GOARCH=${TARGETARCH} \
29-
go build -v -tags musl -ldflags "-w -s" \
27+
go build -v \
3028
-o /app/owlistic ./cmd/main.go
3129

3230
# Use a minimal Alpine image for the final stage
3331
FROM --platform=linux/$TARGETARCH alpine:3.19
3432

35-
# Install runtime dependencies - adding more libraries that might be needed
36-
RUN apk add --no-cache \
37-
librdkafka \
38-
librdkafka-dev \
39-
ca-certificates \
40-
libc6-compat
41-
4233
# Set the working directory inside the container
4334
WORKDIR /app
4435

0 commit comments

Comments
 (0)