Skip to content

Commit b460718

Browse files
author
James Belchamber
committed
Refactoring Juicebox GCP Service
1 parent 1399d4f commit b460718

File tree

15 files changed

+446
-545
lines changed

15 files changed

+446
-545
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build and Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
build_and_publish:
14+
name: Build and Publish
15+
runs-on: ubuntu-latest
16+
17+
permissions:
18+
contents: read
19+
packages: write
20+
attestations: write
21+
id-token: write
22+
23+
steps:
24+
- name: Checkout Code
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Go
28+
uses: actions/setup-go@v5
29+
with:
30+
go-version: "1.24.4"
31+
check-latest: false
32+
33+
- name: Build Executable
34+
run: |
35+
go build ./cmd/jb-sw-realm
36+
37+
- name: Login to GitHub Container Registry
38+
uses: docker/login-action@v3
39+
with:
40+
registry: ${{ env.REGISTRY }}
41+
username: ${{ github.actor }}
42+
password: ${{ secrets.GITHUB_TOKEN }}
43+
44+
- name: Extract metadata (tags, labels) for Docker
45+
id: meta
46+
uses: docker/metadata-action@v5
47+
with:
48+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
49+
50+
- name: Build and push Docker image
51+
id: push
52+
uses: docker/build-push-action@v6
53+
with:
54+
context: .
55+
push: true
56+
tags: ${{ steps.meta.outputs.tags }}
57+
labels: ${{ steps.meta.outputs.labels }}
58+
59+
- name: Generate artifact attestation
60+
uses: actions/attest-build-provenance@v2
61+
with:
62+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
63+
subject-digest: ${{ steps.push.outputs.digest }}
64+
push-to-registry: true
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
name: CI
1+
name: Lint and Test
22

33
on:
44
pull_request: {}
5-
push:
6-
branches:
7-
- main
85
workflow_dispatch: {}
96

107
jobs:
@@ -13,18 +10,18 @@ jobs:
1310
runs-on: ubuntu-latest
1411
steps:
1512
- name: Checkout Code
16-
uses: actions/checkout@v3
13+
uses: actions/checkout@v4
1714

1815
- name: Set up Go
19-
uses: actions/setup-go@v3
16+
uses: actions/setup-go@v5
2017
with:
21-
go-version: '1.22.2'
18+
go-version: "1.24.4"
2219
check-latest: false
2320

2421
- name: Run revive
2522
run: |
2623
go install github.com/mgechev/revive@latest
27-
revive -config revive.toml -formatter friendly -set_exit_status ./...
24+
revive -config revive.toml -formatter friendly ./...
2825
2926
- name: Run staticcheck
3027
run: |

Dockerfile

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,13 @@
1-
FROM golang:1.22.2 as build-env
1+
FROM debian:latest
22

3-
WORKDIR /app
3+
RUN apt update && apt install -y ca-certificates
44

5-
COPY go.mod go.sum ./
6-
7-
RUN go mod download
8-
9-
COPY . .
10-
11-
RUN CGO_ENABLED=0 go build -o /jb-sw-realm ./cmd/jb-sw-realm
12-
13-
FROM debian:11-slim
14-
15-
RUN apt-get update && apt-get install -y curl supervisor
16-
17-
WORKDIR /otel
18-
19-
RUN curl -LO https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.77.0/otelcol-contrib_0.77.0_linux_amd64.tar.gz \
20-
&& tar -xzvf otelcol-contrib_0.77.0_linux_amd64.tar.gz \
21-
&& mv otelcol-contrib /usr/local/bin/otelcol-contrib \
22-
&& rm -rf /otel
23-
24-
COPY otel-collector-config.yaml /etc/otelcol-contrib/config.yaml
25-
26-
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
27-
28-
COPY --from=build-env /jb-sw-realm /usr/local/bin/jb-sw-realm
5+
COPY jb-sw-realm /usr/local/bin/jb-sw-realm
296

307
ENV PORT 8080
318

329
EXPOSE 8080
3310

3411
HEALTHCHECK CMD curl --fail "http://localhost:8080" || exit 1
3512

36-
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
13+
ENTRYPOINT ["/usr/local/bin/jb-sw-realm"]

gcp/run.tf

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,18 @@ resource "google_cloud_run_v2_service" "juicebox" {
1010
template {
1111
timeout = "300s"
1212
service_account = google_service_account.service_account.email
13+
volumes {
14+
name = "otel-config"
15+
secret {
16+
secret = google_secret_manager_secret.opentelemetry_configuration.secret_id
17+
items {
18+
version = "latest"
19+
path = "config.yaml"
20+
}
21+
}
22+
}
1323
containers {
14-
name = "juicebox-1"
24+
name = "jb-sw-realms"
1525
ports {
1626
name = "http1"
1727
container_port = 8080
@@ -49,6 +59,10 @@ resource "google_cloud_run_v2_service" "juicebox" {
4959
name = "REALM_ID"
5060
value = var.realm_id
5161
}
62+
env {
63+
name = "OPENTELEMETRY_ENDPOINT"
64+
value = "localhost:4317"
65+
}
5266
dynamic "env" {
5367
for_each = var.juicebox_vars
5468
content {
@@ -57,6 +71,27 @@ resource "google_cloud_run_v2_service" "juicebox" {
5771
}
5872
}
5973
}
74+
containers {
75+
name = "otel-collector"
76+
resources {
77+
limits = {
78+
cpu = "1"
79+
memory = "512Mi"
80+
}
81+
}
82+
image = "${var.otelcol_image_url}:${var.otelcol_image_version}"
83+
volume_mounts {
84+
name = "otel-config"
85+
mount_path = "/etc/otelcol-contrib/"
86+
}
87+
dynamic "env" {
88+
for_each = var.otelcol_vars
89+
content {
90+
name = env.key
91+
value = env.value
92+
}
93+
}
94+
}
6095
}
6196
}
6297

@@ -68,6 +103,22 @@ resource "google_project_iam_binding" "logs_writer_binding" {
68103
]
69104
}
70105

106+
resource "google_project_iam_binding" "metrics_writer_binding" {
107+
project = var.project_id
108+
role = "roles/monitoring.metricWriter"
109+
members = [
110+
"serviceAccount:${google_service_account.service_account.email}"
111+
]
112+
}
113+
114+
resource "google_project_iam_binding" "cloud_trace_agent_binding" {
115+
project = var.project_id
116+
role = "roles/cloudtrace.agent"
117+
members = [
118+
"serviceAccount:${google_service_account.service_account.email}"
119+
]
120+
}
121+
71122
resource "google_cloud_run_v2_service_iam_binding" "allow_unauthenticated_users" {
72123
project = var.project_id
73124
name = google_cloud_run_v2_service.juicebox.name

gcp/secret-manager.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,25 @@ resource "google_secret_manager_secret_iam_binding" "access" {
2121
"serviceAccount:${google_service_account.service_account.email}"
2222
]
2323
}
24+
25+
resource "google_secret_manager_secret" "opentelemetry_configuration" {
26+
secret_id = "jb-sw-otel-config"
27+
replication {
28+
auto {}
29+
}
30+
}
31+
32+
resource "google_secret_manager_secret_version" "opentelemetry_configuration" {
33+
secret = google_secret_manager_secret.opentelemetry_configuration.id
34+
secret_data = base64decode(var.otelcol_config_b64)
35+
}
36+
37+
resource "google_secret_manager_secret_iam_binding" "opentelemetry_configuration" {
38+
for_each = var.tenant_secrets
39+
secret_id = google_secret_manager_secret.opentelemetry_configuration.id
40+
role = "roles/secretmanager.secretAccessor"
41+
42+
members = [
43+
"serviceAccount:${google_service_account.service_account.email}"
44+
]
45+
}

gcp/variables.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,26 @@ variable "juicebox_vars" {
3838
type = map(string)
3939
default = {}
4040
}
41+
42+
variable "otelcol_image_url" {
43+
description = "The url of the opentelemetry collector docker image"
44+
type = string
45+
}
46+
47+
variable "otelcol_image_version" {
48+
description = "The version of the opentelemetry collector docker image"
49+
type = string
50+
}
51+
52+
variable "otelcol_config_b64" {
53+
description = "A configuration file for the OpenTelemetry Collector, encoded in base64"
54+
type = string
55+
default = "cmVjZWl2ZXJzOgogIG90bHA6CiAgICBwcm90b2NvbHM6CiAgICAgIGdycGM6CiAgICAgICAgZW5kcG9pbnQ6IGxvY2FsaG9zdDo0MzE3CiAgaG9zdG1ldHJpY3M6CiAgICBjb2xsZWN0aW9uX2ludGVydmFsOiAxMHMKICAgIHNjcmFwZXJzOgogICAgICBwYWdpbmc6CiAgICAgICAgbWV0cmljczoKICAgICAgICAgIHN5c3RlbS5wYWdpbmcudXRpbGl6YXRpb246CiAgICAgICAgICAgIGVuYWJsZWQ6IHRydWUKICAgICAgY3B1OgogICAgICAgIG1ldHJpY3M6CiAgICAgICAgICBzeXN0ZW0uY3B1LnV0aWxpemF0aW9uOgogICAgICAgICAgICBlbmFibGVkOiB0cnVlCiAgICAgIGRpc2s6CiAgICAgIGZpbGVzeXN0ZW06CiAgICAgICAgbWV0cmljczoKICAgICAgICAgIHN5c3RlbS5maWxlc3lzdGVtLnV0aWxpemF0aW9uOgogICAgICAgICAgICBlbmFibGVkOiB0cnVlCiAgICAgIGxvYWQ6CiAgICAgIG1lbW9yeToKICAgICAgbmV0d29yazoKICAgICAgcHJvY2Vzc2VzOgoKcHJvY2Vzc29yczoKICBiYXRjaDoKICAgIHNlbmRfYmF0Y2hfbWF4X3NpemU6IDEwMAogICAgc2VuZF9iYXRjaF9zaXplOiAxMAogICAgdGltZW91dDogMTBzCiAgYXR0cmlidXRlcy9kZDoKICAgIGFjdGlvbnM6CiAgICAgIC0ga2V5OiBlbnYKICAgICAgICBhY3Rpb246IGluc2VydAogICAgICAgIHZhbHVlOiAke2VudjpERF9FTlZfTkFNRX0KCmV4cG9ydGVyczoKICBkYXRhZG9nOgogICAgYXBpOgogICAgICBzaXRlOiAke2VudjpERF9TSVRFfQogICAgICBrZXk6ICR7ZW52OkREX0FQSV9LRVl9CiAgICBob3N0X21ldGFkYXRhOgogICAgICB0YWdzOgogICAgICAgIC0gcmVhbG06JHtlbnY6UkVBTE1fSUR9CgpzZXJ2aWNlOgogIHBpcGVsaW5lczoKICAgIG1ldHJpY3M6CiAgICAgIHJlY2VpdmVyczogW2hvc3RtZXRyaWNzLCBvdGxwXQogICAgICBwcm9jZXNzb3JzOiBbYXR0cmlidXRlcy9kZCxiYXRjaF0KICAgICAgZXhwb3J0ZXJzOiBbZGF0YWRvZ10KICAgIHRyYWNlczoKICAgICAgcmVjZWl2ZXJzOiBbb3RscF0KICAgICAgcHJvY2Vzc29yczogW2F0dHJpYnV0ZXMvZGQsYmF0Y2hdCiAgICAgIGV4cG9ydGVyczogW2RhdGFkb2ddCiAgICBsb2dzOgogICAgICByZWNlaXZlcnM6IFtvdGxwXQogICAgICBwcm9jZXNzb3JzOiBbYXR0cmlidXRlcy9kZCxiYXRjaF0KICAgICAgZXhwb3J0ZXJzOiBbZGF0YWRvZ10K"
56+
# This is a base64 representation of ../otel-collector-config.yaml
57+
}
58+
59+
variable "otelcol_vars" {
60+
description = "Environment variables for the juicebox container"
61+
type = map(string)
62+
default = {}
63+
}

0 commit comments

Comments
 (0)