Skip to content
Merged
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
30 changes: 27 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENERS: INTERNAL://0.0.0.0:29092,EXTERNAL://0.0.0.0:9092
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:29092,EXTERNAL://localhost:9092
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:29092,EXTERNAL://kafka:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
Expand All @@ -41,8 +41,32 @@ services:
- app-network
restart: unless-stopped

volumes:
minio-data:
transcode:
build: ./transcode
container_name: transcode
depends_on:
- kafka
env_file:
- ./back/.env.default
environment:
- KAFKA_BOOTSTRAP=kafka:29092
networks:
- app-network
restart: unless-stopped
sns-bridge:
build: ./sns-bridge
container_name: sns-bridge
depends_on:
- kafka
environment:
- KAFKA_BOOTSTRAP=kafka:29092
- KAFKA_TOPIC=s3-events
- SNS_PORT=5000
ports:
- "5001:5000"
networks:
- app-network
restart: on-failure

networks:
app-network:
Expand Down
10 changes: 10 additions & 0 deletions sns-bridge/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.11-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY app.py .

CMD ["python", "app.py"]
39 changes: 39 additions & 0 deletions sns-bridge/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from flask import Flask, request, jsonify
from kafka import KafkaProducer
import json
import os

app = Flask(__name__)

KAFKA_BOOTSTRAP = os.getenv("KAFKA_BOOTSTRAP", "kafka:29092")
KAFKA_TOPIC = os.getenv("KAFKA_TOPIC", "s3-events")

producer = KafkaProducer(
bootstrap_servers=[KAFKA_BOOTSTRAP],
value_serializer=lambda v: json.dumps(v).encode("utf-8")
)

@app.route("/sns", methods=["POST"])
def sns_listener():
data = request.get_json(force=True)

# SNS ์ธ์ฆ ์š”์ฒญ (SubscriptionConfirmation)
if "Type" in data and data["Type"] == "SubscriptionConfirmation":
print("SNS SubscriptionConfirmation received")
print(f"Confirm URL: {data['SubscribeURL']}")
return jsonify({"message": "Subscription confirmation received"}), 200

# ์‹ค์ œ S3 ์ด๋ฒคํŠธ ๋ฉ”์‹œ์ง€
if "Type" in data and data["Type"] == "Notification":
message = json.loads(data["Message"])
print(f"๐Ÿ“ฆ Received S3 event: {json.dumps(message, indent=2)}")
producer.send(KAFKA_TOPIC, message)
producer.flush()
return jsonify({"status": "sent to kafka"}), 200

return jsonify({"status": "ignored"}), 200


if __name__ == "__main__":
port = int(os.getenv("SNS_PORT", 5000))
app.run(host="0.0.0.0", port=port)
2 changes: 2 additions & 0 deletions sns-bridge/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==3.0.3
kafka-python==2.0.2
5 changes: 1 addition & 4 deletions Dockerfile โ†’ transcode/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY consumer.py .

ENV KAFKA_TOPIC=s3-events
ENV KAFKA_BOOTSTRAP=kafka:9092
ENV MINIO_ENDPOINT=http://minio:9000
ENV MINIO_ACCESS_KEY=minioadmin
ENV MINIO_SECRET_KEY=minioadmin
ENV KAFKA_BOOTSTRAP=kafka:29092
ENV DOWNLOAD_DIR=/downloads

VOLUME ["/downloads"]
Expand Down
File renamed without changes.
File renamed without changes.