Skip to content

Commit 15cf731

Browse files
committed
Start docker builds
1 parent ae8dc2a commit 15cf731

File tree

5 files changed

+111
-8
lines changed

5 files changed

+111
-8
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-and-push:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Docker Buildx
17+
uses: docker/setup-buildx-action@v1
18+
19+
- name: Login to Docker Hub
20+
uses: docker/login-action@v1
21+
with:
22+
username: ${{ secrets.DOCKER_USERNAME }}
23+
password: ${{ secrets.DOCKER_PASSWORD }}
24+
25+
- name: Build and push Docker image
26+
uses: docker/build-push-action@v2
27+
with:
28+
context: .
29+
file: ./Dockerfile
30+
push: true
31+
tags: ${{ secrets.DOCKER_USERNAME }}/fleet-telemetry-consumer:latest
32+
33+
34+
35+
name: Build and Push Docker Image
36+
37+
on:
38+
push:
39+
branches:
40+
- "**" # Triggers on all branches
41+
tags:
42+
- "v*.*.*" # Triggers on tag push for versioned tags (e.g., v1.0.0)
43+
44+
jobs:
45+
build:
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Checkout code
49+
uses: actions/checkout@v3
50+
51+
- name: Set up Docker Buildx
52+
uses: docker/setup-buildx-action@v2
53+
54+
- name: Log in to Quay.io
55+
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login quay.io -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
56+
57+
- name: Get tag or commit SHA
58+
id: vars
59+
run: |
60+
if [ "${{ github.event_name }}" = "push" ] && [ -n "${{ github.ref_name }}" ]; then
61+
echo "image_tag=${{ github.ref_name }}" >> $GITHUB_ENV
62+
else
63+
echo "image_tag=${{ github.sha }}" >> $GITHUB_ENV
64+
fi
65+
66+
- name: Build Docker Image
67+
run: make build
68+
69+
- name: Tag Docker Image
70+
run: docker tag fleet-telemetry-consumer quay.io/rajsinghcpre/fleet-telemetry-consumer:${{ env.image_tag }}
71+
72+
- name: Push Docker Image
73+
run: docker push quay.io/rajsinghcpre/fleet-telemetry-consumer:${{ env.image_tag }}

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM golang:1.22.5-bullseye as build
2+
WORKDIR /go/src/fleet-telemetry-consumer
3+
COPY . .
4+
RUN go build -o /go/bin/fleet-telemetry-consumer
5+
6+
FROM gcr.io/distroless/cc-debian11
7+
WORKDIR /
8+
COPY --from=build /go/bin/fleet-telemetry-consumer /
9+
CMD ["/fleet-telemetry-consumer", "-config", "/etc/fleet-telemetry-consumer/config.json"]

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build:
2+
docker build . --platform linux/amd64 --no-cache

examples/consumer_config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"bootstrap.servers": "10.0.100.12:31769",
3+
"group.id": "fleet-telemetry-consumer-group",
4+
"auto.offset.reset": "earliest"
5+
}

main.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,36 @@ package main
22

33
import (
44
"encoding/json"
5+
"flag"
56
"fmt"
7+
"os"
68
"log"
7-
89
"github.com/confluentinc/confluent-kafka-go/kafka"
910
"google.golang.org/protobuf/proto"
10-
11-
// Import your generated protobuf package here
1211
"github.com/teslamotors/fleet-telemetry/protos"
1312
)
1413

1514
func main() {
16-
// Set up the Kafka consumer configuration
17-
config := kafka.ConfigMap{
18-
"bootstrap.servers": "10.0.100.12:31769", // Replace with your broker address
19-
"group.id": "fleet-telemetry-consumer-group",
20-
"auto.offset.reset": "earliest",
15+
// Define a command-line flag for the configuration file path
16+
configFilePath := flag.String("config", "config.json", "Path to the JSON configuration file")
17+
flag.Parse()
18+
19+
// Read the configuration file
20+
configFile, err := os.ReadFile(*configFilePath)
21+
if err != nil {
22+
log.Fatalf("Failed to read configuration file: %s", err)
23+
}
24+
25+
// Parse the JSON configuration file
26+
var configMap map[string]interface{}
27+
if err := json.Unmarshal(configFile, &configMap); err != nil {
28+
log.Fatalf("Failed to parse configuration file: %s", err)
29+
}
30+
31+
// Convert the map to kafka.ConfigMap
32+
config := kafka.ConfigMap{}
33+
for key, value := range configMap {
34+
config[key] = value
2135
}
2236

2337
// Create the consumer

0 commit comments

Comments
 (0)