Skip to content

Commit 734d920

Browse files
committed
Docker build
1 parent 43f5ae2 commit 734d920

File tree

3 files changed

+93
-55
lines changed

3 files changed

+93
-55
lines changed

.github/workflows/ci.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}/ctmon-ingest
12+
13+
jobs:
14+
build-and-push:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Go
25+
uses: actions/setup-go@v4
26+
with:
27+
go-version: '1.23'
28+
29+
- name: Run tests
30+
run: go test -v ./...
31+
32+
- name: Log in to Container Registry
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ${{ env.REGISTRY }}
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Extract metadata
40+
id: meta
41+
uses: docker/metadata-action@v5
42+
with:
43+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
44+
tags: |
45+
type=ref,event=branch
46+
type=ref,event=pr
47+
type=sha
48+
type=raw,value=latest,enable={{is_default_branch}}
49+
50+
- name: Build and push Docker image
51+
uses: docker/build-push-action@v5
52+
with:
53+
context: .
54+
push: true
55+
tags: ${{ steps.meta.outputs.tags }}
56+
labels: ${{ steps.meta.outputs.labels }}
57+
target: ctmon_ingest

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Build stage
2+
FROM golang:1.23-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Install git for fetching dependencies
7+
RUN apk add --no-cache git
8+
9+
# Copy go mod files
10+
COPY go.mod go.sum ./
11+
12+
# Download dependencies
13+
RUN go mod download
14+
15+
# Copy source code
16+
COPY . .
17+
18+
# Build the binary
19+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ctmon-ingest ./cmd/ctmon-ingest
20+
21+
# Runtime stage
22+
FROM alpine:latest AS ctmon_ingest
23+
24+
# Install ca-certificates for HTTPS requests
25+
RUN apk --no-cache add ca-certificates
26+
27+
WORKDIR /root/
28+
29+
# Copy the binary from builder stage
30+
COPY --from=builder /app/ctmon-ingest .
31+
32+
# Expose port (if needed for health checks)
33+
EXPOSE 8080
34+
35+
# Run the binary
36+
CMD ["./ctmon-ingest"]

cmd/ctmon-ingest/main.go

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,6 @@ func (cb *CircuitBreaker) recordFailure() {
125125
}
126126
}
127127

128-
func isRetryableError(err error) bool {
129-
if err == nil {
130-
return false
131-
}
132-
// Check for network-related errors that are worth retrying
133-
errorStr := err.Error()
134-
return strings.Contains(errorStr, "timeout") ||
135-
strings.Contains(errorStr, "connection refused") ||
136-
strings.Contains(errorStr, "connection reset") ||
137-
strings.Contains(errorStr, "temporary failure") ||
138-
strings.Contains(errorStr, "i/o timeout") ||
139-
strings.Contains(errorStr, "network is unreachable") ||
140-
strings.Contains(errorStr, "context deadline exceeded") ||
141-
strings.HasPrefix(errorStr, "retryable http error ")
142-
}
143-
144-
func isRetryableHTTPStatus(statusCode int) bool {
145-
return statusCode >= 500 || statusCode == 429 || statusCode == 408
146-
}
147-
148128
func isEndOfLogError(err error) bool {
149129
if err == nil {
150130
return false
@@ -214,10 +194,6 @@ func fetchEntriesWithRetry(client *http.Client, logURL string, start, end int64)
214194
// This is end-of-log, don't retry but return special error type
215195
return nil, fmt.Errorf("end_of_log: %w", err)
216196
}
217-
if !isRetryableError(err) {
218-
log.Printf("Non-retryable error, giving up: %v", err)
219-
break
220-
}
221197

222198
// Calculate and apply backoff delay
223199
delay := calculateBackoffDelay(attempt)
@@ -250,9 +226,6 @@ func fetchEntries(client *http.Client, logURL string, start, end int64) (*GetEnt
250226

251227
if resp.StatusCode != http.StatusOK {
252228
bodyBytes, _ := io.ReadAll(resp.Body)
253-
if isRetryableHTTPStatus(resp.StatusCode) {
254-
return nil, fmt.Errorf("retryable http error %s: %s", resp.Status, string(bodyBytes))
255-
}
256229
return nil, fmt.Errorf("http request failed with status %s: %s", resp.Status, string(bodyBytes))
257230
}
258231

@@ -417,23 +390,6 @@ func initClickHouse() (*sql.DB, error) {
417390
return conn, nil
418391
}
419392

420-
func isRetryableDBError(err error) bool {
421-
if err == nil {
422-
return false
423-
}
424-
errorStr := err.Error()
425-
// ClickHouse specific retryable errors
426-
return strings.Contains(errorStr, "connection refused") ||
427-
strings.Contains(errorStr, "connection reset") ||
428-
strings.Contains(errorStr, "timeout") ||
429-
strings.Contains(errorStr, "network is unreachable") ||
430-
strings.Contains(errorStr, "broken pipe") ||
431-
strings.Contains(errorStr, "connection lost") ||
432-
strings.Contains(errorStr, "server is not ready") ||
433-
strings.Contains(errorStr, "too many connections") ||
434-
strings.Contains(errorStr, "context deadline exceeded")
435-
}
436-
437393
func boolToUint8(b bool) uint8 {
438394
if b {
439395
return 1
@@ -526,11 +482,6 @@ func ingestBatchWithRetry(db *sql.DB, batch []*CertificateDetails, cb *CircuitBr
526482
break
527483
}
528484

529-
if !isRetryableDBError(err) {
530-
log.Printf("Non-retryable database error, giving up: %v", err)
531-
break
532-
}
533-
534485
delay := calculateBackoffDelay(attempt)
535486
log.Printf("Retrying database batch operation in %v...", delay)
536487
time.Sleep(delay)
@@ -658,12 +609,6 @@ func getLatestLogIndexWithRetry(db *sql.DB, logID string, cb *CircuitBreaker) (i
658609
break
659610
}
660611

661-
// Check if error is retryable
662-
if !isRetryableDBError(err) {
663-
log.Printf("Non-retryable database error, giving up: %v", err)
664-
break
665-
}
666-
667612
// Calculate and apply backoff delay
668613
delay := calculateBackoffDelay(attempt)
669614
log.Printf("Retrying latest log index fetch in %v...", delay)

0 commit comments

Comments
 (0)