Skip to content

Commit ab96be4

Browse files
committed
feature: support dockerized app
1 parent 8b2d717 commit ab96be4

File tree

10 files changed

+220
-508
lines changed

10 files changed

+220
-508
lines changed

Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# multistage docker build
2+
FROM messense/rust-musl-cross:aarch64-musl as builder
3+
ENV SQLX_OFFLINE=true
4+
WORKDIR /app
5+
6+
# Install protoc
7+
RUN apt-get update && apt-get install -y protobuf-compiler
8+
# update rust toolchain
9+
RUN rustup update
10+
11+
# copy relevant source code
12+
COPY ./chat ./chat
13+
COPY ./protos ./protos
14+
15+
# build and show build result
16+
RUN cd chat && cargo build --release --target aarch64-unknown-linux-musl
17+
RUN ls /app/chat/target/aarch64-unknown-linux-musl/release
18+
19+
# final stage
20+
FROM alpine:3.20
21+
22+
WORKDIR /app
23+
24+
# Create a non-root user and group
25+
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
26+
27+
# Set permissions for /app
28+
RUN chown -R appuser:appgroup /app
29+
30+
# Switch to the non-root user
31+
USER appuser
32+
33+
ARG APP_NAME
34+
ARG APP_PORT
35+
36+
COPY --from=builder /app/chat/target/aarch64-unknown-linux-musl/release/$APP_NAME /app/$APP_NAME
37+
38+
EXPOSE $APP_PORT

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
DOCKER=podman
2+
PWD=$(shell pwd)
3+
4+
5+
build-docker:
6+
$(DOCKER) build -t chat-server:latest --build-arg APP_NAME=chat-server --build-arg APP_PORT=6688 .
7+
$(DOCKER) build -t notify-server:latest --build-arg APP_NAME=notify-server --build-arg APP_PORT=6687 .
8+
$(DOCKER) build -t bot-server:latest --build-arg APP_NAME=bot --build-arg APP_PORT=6686 .
9+
$(DOCKER) build -t analytics-server:latest --build-arg APP_NAME=analytics-server --build-arg APP_PORT=6690 .
10+
11+
run-docker: kill-dockers
12+
$(DOCKER) run --entrypoint /app/chat-server --env OPENAI_API_KEY=$(OPENAI_API_KEY) --name chat -d -p 6688:6688 --mount type=bind,source=$(PWD)/fixtures/chat.yml,target=/app/chat.yml,readonly localhost/chat-server:latest
13+
$(DOCKER) run --entrypoint /app/notify-server --name notify -d -p 6687:6687 --mount type=bind,source=$(PWD)/fixtures/notify.yml,target=/app/notify.yml,readonly localhost/notify-server:latest
14+
$(DOCKER) run --entrypoint /app/bot --env OPENAI_API_KEY=$(OPENAI_API_KEY) --name bot -d -p 6686:6686 --mount type=bind,source=$(PWD)/fixtures/bot.yml,target=/app/bot.yml,readonly localhost/bot-server:latest
15+
$(DOCKER) run --entrypoint /app/analytics-server --name analytics -d -p 6690:6690 --mount type=bind,source=$(PWD)/fixtures/analytics.yml,target=/app/analytics.yml,readonly localhost/analytics-server:latest
16+
17+
kill-dockers:
18+
@$(DOCKER) kill $(shell $(DOCKER) ps -aq) || true
19+
@$(DOCKER) container prune -f

chatapp/buf.gen.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ inputs:
44
- directory: ../protos
55
plugins:
66
- local: protoc-gen-es
7-
opt: target=ts
7+
opt: target=js
88
out: src/gen

chatapp/src/gen/messages_pb.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// @generated by protoc-gen-es v2.2.0 with parameter "target=js"
2+
// @generated from file messages.proto (package analytics, syntax proto3)
3+
/* eslint-disable */
4+
5+
import { enumDesc, fileDesc, messageDesc, tsEnum } from "@bufbuild/protobuf/codegenv1";
6+
7+
/**
8+
* Describes the file messages.proto.
9+
*/
10+
export const file_messages = /*@__PURE__*/
11+
fileDesc("Cg5tZXNzYWdlcy5wcm90bxIJYW5hbHl0aWNzIr0ECg5BbmFseXRpY3NFdmVudBIoCgdjb250ZXh0GAEgASgLMhcuYW5hbHl0aWNzLkV2ZW50Q29udGV4dBItCglhcHBfc3RhcnQYCCABKAsyGC5hbmFseXRpY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FAoMd29ya3NwYWNlX2lkGAEgASgJIlQKEE1lc3NhZ2VTZW50RXZlbnQSDwoHY2hhdF9pZBgBIAEoCRIMCgR0eXBlGAIgASgJEgwKBHNpemUYAyABKAUSEwoLdG90YWxfZmlsZXMYBCABKAUiIgoPQ2hhdEpvaW5lZEV2ZW50Eg8KB2NoYXRfaWQYASABKAkiIAoNQ2hhdExlZnRFdmVudBIPCgdjaGF0X2lkGAEgASgJIisKD05hdmlnYXRpb25FdmVudBIMCgRmcm9tGAEgASgJEgoKAnRvGAIgASgJItkBCgxFdmVudENvbnRleHQSEQoJY2xpZW50X2lkGAEgASgJEhMKC2FwcF92ZXJzaW9uGAIgASgJEiUKBnN5c3RlbRgDIAEoCzIVLmFuYWx5dGljcy5TeXN0ZW1JbmZvEg8KB3VzZXJfaWQYBCABKAkSCgoCaXAYBSABKAkSEgoKdXNlcl9hZ2VudBgGIAEoCRIjCgNnZW8YByABKAsyFi5hbmFseXRpY3MuR2VvTG9jYXRpb24SEQoJY2xpZW50X3RzGAggASgDEhEKCXNlcnZlcl90cxgJIAEoAyJICgpTeXN0ZW1JbmZvEgoKAm9zGAEgASgJEgwKBGFyY2gYAiABKAkSDgoGbG9jYWxlGAMgASgJEhAKCHRpbWV6b25lGAQgASgJIjwKC0dlb0xvY2F0aW9uEg8KB2NvdW50cnkYASABKAkSDgoGcmVnaW9uGAIgASgJEgwKBGNpdHkYAyABKAliBnByb3RvMw");
12+
13+
/**
14+
* Describes the message analytics.AnalyticsEvent.
15+
* Use `create(AnalyticsEventSchema)` to create a new message.
16+
*/
17+
export const AnalyticsEventSchema = /*@__PURE__*/
18+
messageDesc(file_messages, 0);
19+
20+
/**
21+
* Describes the message analytics.AppStartEvent.
22+
* Use `create(AppStartEventSchema)` to create a new message.
23+
*/
24+
export const AppStartEventSchema = /*@__PURE__*/
25+
messageDesc(file_messages, 1);
26+
27+
/**
28+
* Describes the message analytics.AppExitEvent.
29+
* Use `create(AppExitEventSchema)` to create a new message.
30+
*/
31+
export const AppExitEventSchema = /*@__PURE__*/
32+
messageDesc(file_messages, 2);
33+
34+
/**
35+
* Describes the enum analytics.AppExitEvent.ExitCode.
36+
*/
37+
export const AppExitEvent_ExitCodeSchema = /*@__PURE__*/
38+
enumDesc(file_messages, 2, 0);
39+
40+
/**
41+
* @generated from enum analytics.AppExitEvent.ExitCode
42+
*/
43+
export const AppExitEvent_ExitCode = /*@__PURE__*/
44+
tsEnum(AppExitEvent_ExitCodeSchema);
45+
46+
/**
47+
* Describes the message analytics.UserLoginEvent.
48+
* Use `create(UserLoginEventSchema)` to create a new message.
49+
*/
50+
export const UserLoginEventSchema = /*@__PURE__*/
51+
messageDesc(file_messages, 3);
52+
53+
/**
54+
* Describes the message analytics.UserLogoutEvent.
55+
* Use `create(UserLogoutEventSchema)` to create a new message.
56+
*/
57+
export const UserLogoutEventSchema = /*@__PURE__*/
58+
messageDesc(file_messages, 4);
59+
60+
/**
61+
* Describes the message analytics.UserRegisterEvent.
62+
* Use `create(UserRegisterEventSchema)` to create a new message.
63+
*/
64+
export const UserRegisterEventSchema = /*@__PURE__*/
65+
messageDesc(file_messages, 5);
66+
67+
/**
68+
* Describes the message analytics.ChatCreatedEvent.
69+
* Use `create(ChatCreatedEventSchema)` to create a new message.
70+
*/
71+
export const ChatCreatedEventSchema = /*@__PURE__*/
72+
messageDesc(file_messages, 6);
73+
74+
/**
75+
* Describes the message analytics.MessageSentEvent.
76+
* Use `create(MessageSentEventSchema)` to create a new message.
77+
*/
78+
export const MessageSentEventSchema = /*@__PURE__*/
79+
messageDesc(file_messages, 7);
80+
81+
/**
82+
* Describes the message analytics.ChatJoinedEvent.
83+
* Use `create(ChatJoinedEventSchema)` to create a new message.
84+
*/
85+
export const ChatJoinedEventSchema = /*@__PURE__*/
86+
messageDesc(file_messages, 8);
87+
88+
/**
89+
* Describes the message analytics.ChatLeftEvent.
90+
* Use `create(ChatLeftEventSchema)` to create a new message.
91+
*/
92+
export const ChatLeftEventSchema = /*@__PURE__*/
93+
messageDesc(file_messages, 9);
94+
95+
/**
96+
* Describes the message analytics.NavigationEvent.
97+
* Use `create(NavigationEventSchema)` to create a new message.
98+
*/
99+
export const NavigationEventSchema = /*@__PURE__*/
100+
messageDesc(file_messages, 10);
101+
102+
/**
103+
* Describes the message analytics.EventContext.
104+
* Use `create(EventContextSchema)` to create a new message.
105+
*/
106+
export const EventContextSchema = /*@__PURE__*/
107+
messageDesc(file_messages, 11);
108+
109+
/**
110+
* Describes the message analytics.SystemInfo.
111+
* Use `create(SystemInfoSchema)` to create a new message.
112+
*/
113+
export const SystemInfoSchema = /*@__PURE__*/
114+
messageDesc(file_messages, 12);
115+
116+
/**
117+
* Describes the message analytics.GeoLocation.
118+
* Use `create(GeoLocationSchema)` to create a new message.
119+
*/
120+
export const GeoLocationSchema = /*@__PURE__*/
121+
messageDesc(file_messages, 13);

0 commit comments

Comments
 (0)