Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
- fixed send notification issue
- Docker file & Docker Compose file update
  • Loading branch information
saroar committed Jan 13, 2024
1 parent ba91362 commit a57ac9f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 31 deletions.
26 changes: 15 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ FROM swift:5.9-jammy as build
# Install OS updates
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
&& apt-get -q dist-upgrade -y\
&& rm -rf /var/lib/apt/lists/*
&& apt-get -q dist-upgrade -y \
&& apt-get install -y libjemalloc-dev

# Set up a build area
WORKDIR /build
Expand All @@ -23,18 +23,21 @@ RUN swift package resolve --skip-update \
# Copy entire repo into container
COPY . .

# Build everything, with optimizations
RUN swift build -c release --static-swift-stdlib \
# Workaround for https://github.com/apple/swift/pull/68669
# This can be removed as soon as 5.9.1 is released, but is harmless if left in.
-Xlinker -u -Xlinker _swift_backtrace_isThunkFunction
# Build everything, with optimizations, with static linking, and using jemalloc
# N.B.: The static version of jemalloc is incompatible with the static Swift runtime.
RUN swift build -c release \
--static-swift-stdlib \
-Xlinker -ljemalloc

# Switch to the staging area
WORKDIR /staging

# Copy main executable to staging area
RUN cp "$(swift build --package-path /build -c release --show-bin-path)/App" ./

# Copy static swift backtracer binary to staging area
RUN cp "/usr/libexec/swift/linux/swift-backtrace-static" ./

# Copy resources bundled by SPM to staging area
RUN find -L "$(swift build --package-path /build -c release --show-bin-path)/" -regex '.*\.resources$' -exec cp -Ra {} ./ \;

Expand All @@ -46,17 +49,18 @@ RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w
# ================================
# Run image
# ================================
FROM swift:5.9-jammy-slim
FROM ubuntu:jammy

# Make sure all system packages are up to date, and install only essential packages.
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
&& apt-get -q dist-upgrade -y \
&& apt-get -q install -y \
libcurl4 \
libjemalloc2 \
ca-certificates \
tzdata \

libcurl4 \
# If your app or its dependencies import FoundationNetworking, also install `libcurl4`.
# If your app or its dependencies import FoundationXML, also install `libxml2`.
# libxml2 \
&& rm -r /var/lib/apt/lists/*
Expand All @@ -72,7 +76,7 @@ COPY --from=build --chown=vapor:vapor /staging /app
COPY --from=build --chown=vapor:vapor /build/.build/release /app

# Provide configuration needed by the built-in crash reporter and some sensible default behaviors.
ENV SWIFT_ROOT=/usr SWIFT_BACKTRACE=enable=yes,sanitize=yes,threads=all,images=all,interactive=no
ENV SWIFT_BACKTRACE=enable=yes,sanitize=yes,threads=all,images=all,interactive=no,swift-backtrace=./swift-backtrace-static

# Ensure all further commands run as the vapor user
USER vapor:vapor
Expand Down
2 changes: 1 addition & 1 deletion Sources/App/Jobs/EmailJobMongoQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct EmailJobMongoQueue: RecurringTask {
typealias ExecutionContext = Application

// Ensures only one user engagement prompt exists per user
var uniqueTaskKey: String { vCodeAttempt.id!.hexString }
var uniqueTaskKey: String { vCodeAttempt.id!.hexString } ///: Fixed OPS so stupid please fixed me

// The amount of time we expect this task to take if it's very slow
// This is optional, and has a sensible default. Note; it will not be the task's actual deadline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public func authenticationHandler(
throw Abort(.internalServerError, reason: "Failed to retrieve attempt ID after saving.")
}


let emailPayload = EmailPayload(otpEmail, to: email)
let task = EmailJobMongoQueue(payload: emailPayload, vCodeAttempt: smsAttempt)

Expand Down
11 changes: 8 additions & 3 deletions Sources/App/Webbsockets/ChatClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ actor WebsocketClients {

} catch {
messageCreate.isDelivered = false
print("Send Msg to User: \(senderID) error: \(error)")
throw Abort(.notFound, reason: "Send Msg to User: \(senderID) error: \(error)")
}

}

@Sendable func send(message: MessageModel, req: Request, socket: WebSocket) async throws {
@Sendable
func send(message: MessageModel, req: Request, socket: WebSocket) async throws {
if !req.loggedIn {
logger.error("\(#line) Unauthorized send message")
throw Abort(.unauthorized)
Expand All @@ -80,7 +83,8 @@ actor WebsocketClients {
.get()
}

@Sendable private func sendNotificationToConversationMembers(
@Sendable
private func sendNotificationToConversationMembers(
msgItem: MessageItem,
senderID: ObjectId,
with req: Request
Expand Down Expand Up @@ -108,7 +112,8 @@ actor WebsocketClients {
.get()

else {
throw Abort(.notFound, reason: "User not found from \(#function)")
continue
// throw Abort(.notFound, reason: "User not found from \(#function)")
}

try await req.apns.send(
Expand Down
18 changes: 3 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ x-shared_environment: &shared_environment
REDIS_URL_PRODUCTION: '${REDIS_URL_PRODUCTION}'

services:
mongo:
addame_mongo:
image: mongo:latest
container_name: AddameMongoPro
container_name: addameMongoPro
environment:
- AUTH=yes
- MONGODB_ADMIN_USER='${MONGODB_ADMIN_USER}'
Expand Down Expand Up @@ -52,25 +52,13 @@ services:
- ./.env:/app/.env
- ./.env.production:/app/.env.production
depends_on:
- mongo
- addame_mongo
networks:
- addame_pro_gateway
restart: unless-stopped
env_file:
- ./.env

redis:
container_name: redisProAddame
image: 'bitnami/redis:5.0'
environment:
- ALLOW_EMPTY_PASSWORD=yes
- REDIS_DISABLE_COMMANDS=FLUSHDB,FLUSHALL
restart: unless-stopped
volumes:
- redis-persistence-production:/bitnami/redis/data
networks:
- addame_pro_gateway

volumes:
addameServer:
redis-persistence-production:
Expand Down

0 comments on commit a57ac9f

Please sign in to comment.