Skip to content

Commit 1a50497

Browse files
committed
puller container now working
1 parent 9651d3e commit 1a50497

File tree

11 files changed

+771
-237
lines changed

11 files changed

+771
-237
lines changed

utility_containers/event-puller/.env.example

+16-10
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@ AWS_ACCESS_KEY_ID=your-access-key-id
55
AWS_SECRET_ACCESS_KEY=your-secret-access-key
66

77
# Advanced SQS Configuration (Optional - defaults shown)
8-
# POLL_INTERVAL=100ms # Time between SQS polls
9-
# MAX_MESSAGES=10 # Maximum messages to process in one batch
10-
# NUM_WORKERS=5 # Number of concurrent workers
11-
# WS_BATCH_SIZE=100 # Number of messages to batch for websocket
8+
POLL_INTERVAL=100ms # Time between SQS polls (default: 100ms)
9+
MAX_MESSAGES=10 # Maximum messages per poll (default: 10, max: 10)
10+
NUM_WORKERS=5 # Number of concurrent SQS polling workers (default: 5)
11+
WS_BATCH_SIZE=100 # WebSocket message batch size (default: 100)
12+
BUFFER_SIZE=1000 # Message channel buffer size (default: 1000)
13+
MAX_RETRY_ATTEMPTS=5 # Maximum retry attempts for SQS operations (default: 5)
14+
INITIAL_RETRY_DELAY=100ms # Initial retry delay for exponential backoff (default: 100ms)
15+
MAX_RETRY_DELAY=5s # Maximum retry delay (default: 5s)
16+
SQS_VISIBILITY_TIMEOUT=30 # Visibility timeout for received messages (default: 30 seconds)
17+
SQS_WAIT_TIME=0 # SQS long polling wait time (default: 0, max: 20 seconds)
1218

1319
# Azure Cosmos DB Configuration (Optional)
14-
# COSMOS_ENDPOINT=https://your-cosmos-account.documents.azure.com:443/
15-
# COSMOS_KEY=your-cosmos-key
16-
# COSMOS_DATABASE=your-database-name
17-
# COSMOS_CONTAINER=your-container-name
18-
# COSMOS_BATCH_SIZE=100 # Number of messages to batch before writing to Cosmos
19-
# AZURE_REGION=eastus # Used for partitioning data in Cosmos DB
20+
COSMOS_ENDPOINT=https://your-cosmos-account.documents.azure.com:443/
21+
COSMOS_KEY=your-cosmos-key
22+
COSMOS_DATABASE=your-database-name
23+
COSMOS_CONTAINER=your-container-name
24+
COSMOS_BATCH_SIZE=100 # Number of messages to batch before writing to Cosmos
25+
AZURE_REGION=eastus # Used for partitioning data in Cosmos DB
+42-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
1-
FROM alpine:3.19
1+
# Build stage
2+
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
3+
4+
# Install build dependencies
5+
RUN apt-get update && apt-get install -y \
6+
git \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
# Set working directory
10+
WORKDIR /build
11+
12+
# Copy go mod and sum files
13+
COPY go.mod go.sum ./
14+
15+
# Download dependencies
16+
RUN go mod download
17+
18+
# Copy source code
19+
COPY . .
20+
21+
# Build the binary
22+
ARG TARGETPLATFORM
23+
ARG BUILDPLATFORM
24+
RUN echo "Building for $TARGETPLATFORM on $BUILDPLATFORM" && \
25+
case "$TARGETPLATFORM" in \
26+
linux/amd64) \
27+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o event-puller ;; \
28+
linux/arm64) \
29+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o event-puller ;; \
30+
esac
31+
32+
# Final stage
33+
FROM --platform=$TARGETPLATFORM alpine:3.19
234

335
# Install necessary dependencies
4-
RUN apk --no-cache add ca-certificates tzdata
36+
RUN apk --no-cache add ca-certificates tzdata file
537

638
# Create a non-root user and group
739
RUN addgroup -g 1000 appuser && \
@@ -10,15 +42,19 @@ RUN addgroup -g 1000 appuser && \
1042
# Set working directory
1143
WORKDIR /app
1244

13-
# Copy the pre-built binary
14-
COPY bin/event-puller .
45+
# Copy the binary from builder
46+
COPY --from=builder /build/event-puller .
1547

1648
# Copy static files - maintain backward compatibility
1749
COPY static/ ./static/
1850

1951
# Copy the Next.js dashboard if it exists
2052
COPY dashboard/out/ ./dashboard/out/
2153

54+
# Copy and set up the entrypoint script
55+
COPY entrypoint.sh .
56+
RUN chmod +x entrypoint.sh
57+
2258
# Set ownership
2359
RUN chown -R appuser:appuser /app
2460

@@ -28,5 +64,5 @@ USER appuser
2864
# Expose the web UI port
2965
EXPOSE 8080
3066

31-
# Run the application
32-
CMD ["./event-puller"]
67+
# Set the entrypoint
68+
ENTRYPOINT ["/app/entrypoint.sh"]

utility_containers/event-puller/README.md

+17-5
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ go build -o bin/event-puller
4242

4343
```bash
4444
# Pull the latest image
45-
docker pull bacalhauproject/event-puller:latest
45+
docker pull bacalhau-project/event-puller:latest
4646

4747
# Run with your environment variables
4848
docker run -p 8080:8080 \
4949
-e AWS_ACCESS_KEY_ID=your_key \
5050
-e AWS_SECRET_ACCESS_KEY=your_secret \
5151
-e AWS_REGION=your_region \
5252
-e SQS_QUEUE_URL=your_queue_url \
53-
bacalhauproject/event-puller:latest
53+
bacalhau-project/event-puller:latest
5454
```
5555

5656
## ⚙️ Configuration
@@ -66,6 +66,18 @@ AWS_SECRET_ACCESS_KEY=your_aws_secret_key
6666
AWS_REGION=us-east-1
6767
SQS_QUEUE_URL=https://sqs.us-east-1.amazonaws.com/123456789012/your-queue
6868
69+
# SQS Configuration Options
70+
POLL_INTERVAL=100ms # Time between SQS polls (default: 100ms)
71+
MAX_MESSAGES=10 # Maximum messages per poll (default: 10, max: 10)
72+
NUM_WORKERS=5 # Number of concurrent SQS polling workers (default: 5)
73+
WS_BATCH_SIZE=100 # WebSocket message batch size (default: 100)
74+
BUFFER_SIZE=1000 # Message channel buffer size (default: 1000)
75+
MAX_RETRY_ATTEMPTS=5 # Maximum retry attempts for SQS operations (default: 5)
76+
INITIAL_RETRY_DELAY=100ms # Initial retry delay for exponential backoff (default: 100ms)
77+
MAX_RETRY_DELAY=5s # Maximum retry delay (default: 5s)
78+
SQS_VISIBILITY_TIMEOUT=30 # Visibility timeout for received messages (default: 30 seconds)
79+
SQS_WAIT_TIME=0 # SQS long polling wait time (default: 0, max: 20 seconds)
80+
6981
# Optional Cosmos DB Variables
7082
COSMOS_ENDPOINT=https://your-account.documents.azure.com:443/
7183
COSMOS_KEY=your_cosmos_key
@@ -104,9 +116,9 @@ npm run build
104116

105117
**Solution**:
106118
- Ensure AWS credentials have `sqs:ReceiveMessage`, `sqs:DeleteMessage`, and `sqs:GetQueueAttributes` permissions
107-
- Increase `NUM_WORKERS` (line 35 in main.go) for higher throughput
108-
- Add exponential backoff for transient errors
109-
- Implement better error handling and retry logic
119+
- Increase `NUM_WORKERS` environment variable for higher throughput
120+
- Adjust `POLL_INTERVAL` or `SQS_WAIT_TIME` for better polling behavior
121+
- Adjust `MAX_RETRY_ATTEMPTS`, `INITIAL_RETRY_DELAY`, and `MAX_RETRY_DELAY` for better error handling
110122

111123
### Cosmos DB Integration Issues
112124

-3.88 MB
Binary file not shown.

utility_containers/event-puller/build.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ mkdir -p bin
3232
TIMESTAMP=$(date +%Y%m%d%H%M)
3333

3434
# Registry configuration
35-
REGISTRY="docker.io"
36-
ORGANIZATION="bacalhauproject"
35+
REGISTRY="ghcr.io"
36+
ORGANIZATION="bacalhau-project"
3737
IMAGE_NAME="event-puller"
3838
TAG="${REGISTRY}/${ORGANIZATION}/${IMAGE_NAME}:${TIMESTAMP}"
3939

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/sh
2+
3+
echo "🔍 Starting entrypoint script..."
4+
5+
# System information
6+
echo "📊 System Information:"
7+
echo " Architecture: $(uname -m)"
8+
echo " OS: $(uname -s)"
9+
echo " Kernel: $(uname -r)"
10+
echo " CPU Info: $(cat /proc/cpuinfo | grep "model name" | head -n1 | cut -d':' -f2 || echo "Not available")"
11+
12+
# Check if we're in the right directory
13+
echo "📂 Current directory: $(pwd)"
14+
echo "📂 Directory contents:"
15+
ls -la
16+
17+
# Check if the binary exists and is executable
18+
if [ ! -f "/app/event-puller" ]; then
19+
echo "❌ Error: Binary not found at /app/event-puller"
20+
exit 1
21+
fi
22+
23+
if [ ! -x "/app/event-puller" ]; then
24+
echo "❌ Error: Binary at /app/event-puller is not executable"
25+
exit 1
26+
fi
27+
28+
# Check binary architecture
29+
echo "🔍 Binary information:"
30+
file /app/event-puller
31+
32+
# Check if ENV_FILE is set
33+
if [ -z "$ENV_FILE" ]; then
34+
echo "❌ Error: ENV_FILE environment variable is not set"
35+
echo "Please set ENV_FILE to the path of your environment file"
36+
echo "Example: Set ENV_FILE=/app/.env when running the container"
37+
exit 1
38+
fi
39+
40+
echo "📄 ENV_FILE is set to: $ENV_FILE"
41+
42+
# Check if the env file exists
43+
if [ ! -f "$ENV_FILE" ]; then
44+
echo "❌ Error: Environment file not found at $ENV_FILE"
45+
echo "Please ensure the environment file exists and is mounted correctly"
46+
echo "The environment file should be mounted to the path specified in ENV_FILE"
47+
exit 1
48+
fi
49+
50+
echo "✅ Environment file found at $ENV_FILE"
51+
echo "📄 Environment file contents (excluding sensitive data):"
52+
grep -v "KEY\|SECRET\|PASSWORD" "$ENV_FILE" || true
53+
54+
# Display all environment variables (excluding sensitive data)
55+
echo "🌍 Environment variables (excluding sensitive data):"
56+
env | grep -v "KEY\|SECRET\|PASSWORD" || true
57+
58+
# Run the binary with additional debugging
59+
echo "🚀 Starting event-puller..."
60+
exec /app/event-puller

utility_containers/event-puller/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ module github.com/bacalhauproject/bacalhau-examples/utility_containers/event-pul
33
go 1.23.3
44

55
require (
6-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1
76
github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.3.0
87
github.com/aws/aws-sdk-go v1.55.5
98
github.com/charmbracelet/bubbles v0.20.0
109
github.com/charmbracelet/bubbletea v1.2.4
1110
github.com/gorilla/websocket v1.5.3
1211
github.com/joho/godotenv v1.5.1
12+
github.com/mattn/go-isatty v0.0.20
1313
)
1414

1515
require (
1616
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
17+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1 // indirect
1718
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
1819
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
1920
github.com/charmbracelet/lipgloss v1.0.0 // indirect
@@ -22,7 +23,6 @@ require (
2223
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
2324
github.com/jmespath/go-jmespath v0.4.0 // indirect
2425
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
25-
github.com/mattn/go-isatty v0.0.20 // indirect
2626
github.com/mattn/go-localereader v0.0.1 // indirect
2727
github.com/mattn/go-runewidth v0.0.16 // indirect
2828
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect

0 commit comments

Comments
 (0)