Skip to content

Commit 0a501a5

Browse files
authored
Merge branch 'develop' into feat/reconcliation-of-branches
2 parents d5c292c + 685501f commit 0a501a5

File tree

8 files changed

+450
-10
lines changed

8 files changed

+450
-10
lines changed
Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
name: Staging Deployment
2+
3+
on:
4+
push:
5+
branches:
6+
- introduce-monitoring
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
branches: ["develop"]
10+
11+
permissions:
12+
contents: write
13+
packages: write
14+
15+
env:
16+
REGISTRY: ghcr.io
17+
18+
jobs:
19+
build-and-push:
20+
runs-on: ${{ matrix.runner }}
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
include:
25+
# Backend EE
26+
- service: backend-ee
27+
image_name: ${{ github.repository }}/digger-backend-ee
28+
dockerfile: Dockerfile_backend_ee
29+
context: .
30+
depot_project: kcld4zgwzx
31+
runner: ubuntu-latest
32+
33+
# Drift
34+
- service: drift
35+
image_name: ${{ github.repository }}/drift
36+
dockerfile: Dockerfile_drift
37+
context: .
38+
depot_project: f11hp4hlmg
39+
runner: ubuntu-latest
40+
41+
# Projects Refresh
42+
- service: projects-refresh
43+
image_name: ${{ github.repository }}/projects-refresh-service
44+
dockerfile: Dockerfile_bg_projects_refresh
45+
context: .
46+
depot_project: "p9zgmm1k3n"
47+
runner: ubuntu-latest
48+
49+
# UI
50+
- service: ui
51+
image_name: ${{ github.repository }}/taco-ui
52+
dockerfile: Dockerfile_ui
53+
context: .
54+
depot_project: n4w66j9g6t
55+
runner: ubuntu-larger
56+
57+
# Taco Statesman
58+
- service: taco-statesman
59+
image_name: ${{ github.repository }}/taco-statesman
60+
dockerfile: Dockerfile_statesman
61+
context: ./taco
62+
depot_project: q63j2g84tp
63+
runner: ubuntu-latest
64+
65+
# Taco Token Service
66+
- service: taco-token-service
67+
image_name: ${{ github.repository }}/taco-token-service
68+
dockerfile: Dockerfile_token_service
69+
context: ./taco
70+
depot_project: q63j2g84tp
71+
runner: ubuntu-latest
72+
73+
steps:
74+
- uses: actions/checkout@v4
75+
with:
76+
fetch-depth: 0
77+
78+
- name: Generate staging tag
79+
id: tag
80+
run: |
81+
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
82+
STAGING_TAG="staging-${SHORT_SHA}"
83+
echo "tag=${STAGING_TAG}" >> $GITHUB_OUTPUT
84+
echo "Generated staging tag: ${STAGING_TAG}"
85+
86+
- name: Set up Docker Buildx
87+
uses: docker/setup-buildx-action@v3
88+
89+
- name: Log in to Container Registry
90+
uses: docker/login-action@v3
91+
with:
92+
registry: ${{ env.REGISTRY }}
93+
username: ${{ github.actor }}
94+
password: ${{ secrets.GITHUB_TOKEN }}
95+
96+
- name: Extract metadata
97+
id: docker-meta
98+
uses: docker/metadata-action@v5
99+
with:
100+
images: ${{ env.REGISTRY }}/${{ matrix.image_name }}
101+
tags: |
102+
type=raw,value=${{ steps.tag.outputs.tag }}
103+
type=raw,value=${{ steps.tag.outputs.tag }}-${{ matrix.service }}
104+
105+
- name: Setup Depot
106+
if: matrix.depot_project != ''
107+
uses: depot/setup-action@v1
108+
109+
- name: Build and push Docker image (Depot)
110+
if: matrix.depot_project != ''
111+
uses: depot/build-push-action@v1
112+
with:
113+
project: ${{ matrix.depot_project }}
114+
token: ${{ secrets.DEPOT_TOKEN }}
115+
context: ${{ matrix.context }}
116+
file: ${{ matrix.context }}/${{ matrix.dockerfile }}
117+
push: true
118+
platforms: linux/amd64,linux/arm64
119+
tags: ${{ steps.docker-meta.outputs.tags }}
120+
labels: ${{ steps.docker-meta.outputs.labels }}
121+
build-args: |
122+
COMMIT_SHA=${{ github.sha }}
123+
VERSION=${{ steps.tag.outputs.tag }}
124+
125+
- name: Build and push Docker image (Standard)
126+
if: matrix.depot_project == ''
127+
uses: docker/build-push-action@v5
128+
with:
129+
context: ${{ matrix.context }}
130+
file: ${{ matrix.context }}/${{ matrix.dockerfile }}
131+
push: true
132+
platforms: linux/amd64,linux/arm64
133+
tags: ${{ steps.docker-meta.outputs.tags }}
134+
labels: ${{ steps.docker-meta.outputs.labels }}
135+
build-args: |
136+
COMMIT_SHA=${{ github.sha }}
137+
VERSION=${{ steps.tag.outputs.tag }}
138+
139+
- name: Output image info
140+
run: |
141+
echo "✅ Built and pushed: ${{ env.REGISTRY }}/${{ matrix.image_name }}:${{ steps.tag.outputs.tag }}"
142+
echo "Service: ${{ matrix.service }}"
143+
echo "Tag: ${{ steps.tag.outputs.tag }}"
144+
echo "Commit: ${{ github.sha }}"
145+
echo "PR: #${{ github.event.pull_request.number }}"
146+
147+
update-helm-chart:
148+
needs: build-and-push
149+
runs-on: ubuntu-latest
150+
if: success()
151+
steps:
152+
- name: Generate staging tag
153+
id: tag
154+
run: |
155+
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
156+
STAGING_TAG="staging-${SHORT_SHA}"
157+
echo "tag=${STAGING_TAG}" >> $GITHUB_OUTPUT
158+
echo "Generated staging tag: ${STAGING_TAG}"
159+
160+
- name: Checkout helm charts repo
161+
uses: actions/checkout@v4
162+
with:
163+
repository: diggerhq/opentaco-helm-charts
164+
token: ${{ secrets.HELM_CHARTS_PAT }}
165+
ref: main
166+
167+
- name: Install yq
168+
run: |
169+
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
170+
sudo chmod +x /usr/local/bin/yq
171+
172+
- name: Update values-staging.yaml
173+
run: |
174+
STAGING_TAG="${{ steps.tag.outputs.tag }}"
175+
VALUES_FILE="opentaco/values-staging.yaml"
176+
177+
if [ ! -f "$VALUES_FILE" ]; then
178+
echo "Error: $VALUES_FILE not found"
179+
exit 1
180+
fi
181+
182+
echo "Updating values-staging.yaml with staging tag: ${STAGING_TAG}"
183+
184+
# Update all service image tags
185+
yq eval ".taco-orchestrator.digger.image.tag = \"${STAGING_TAG}\"" -i "$VALUES_FILE"
186+
yq eval ".taco-drift.drift.image.tag = \"${STAGING_TAG}\"" -i "$VALUES_FILE"
187+
yq eval ".taco-ui.ui.image.tag = \"${STAGING_TAG}\"" -i "$VALUES_FILE"
188+
yq eval ".taco-statesman.taco.image.tag = \"${STAGING_TAG}\"" -i "$VALUES_FILE"
189+
yq eval ".taco-token-service.tokenService.image.tag = \"${STAGING_TAG}\"" -i "$VALUES_FILE"
190+
191+
echo "Updated successfully!"
192+
echo "---"
193+
echo "Updated tags:"
194+
yq eval ".taco-orchestrator.digger.image.tag" "$VALUES_FILE"
195+
yq eval ".taco-drift.drift.image.tag" "$VALUES_FILE"
196+
yq eval ".taco-ui.ui.image.tag" "$VALUES_FILE"
197+
yq eval ".taco-statesman.taco.image.tag" "$VALUES_FILE"
198+
yq eval ".taco-token-service.tokenService.image.tag" "$VALUES_FILE"
199+
200+
- name: Commit and push changes
201+
run: |
202+
git config user.name "github-actions[bot]"
203+
git config user.email "github-actions[bot]@users.noreply.github.com"
204+
205+
STAGING_TAG="${{ steps.tag.outputs.tag }}"
206+
PR_NUMBER="${{ github.event.pull_request.number }}"
207+
COMMIT="${{ github.sha }}"
208+
209+
git add opentaco/values-staging.yaml
210+
211+
if git diff --staged --quiet; then
212+
echo "No changes to commit"
213+
exit 0
214+
fi
215+
216+
# Create commit message
217+
git commit -m "chore(staging): update all services to ${STAGING_TAG}" \
218+
-m "Automated update from staging deployment." \
219+
-m "" \
220+
-m "PR: #${PR_NUMBER}" \
221+
-m "Commit: ${COMMIT}" \
222+
-m "Staging Tag: ${STAGING_TAG}"
223+
224+
git push
225+
226+
echo "✅ Successfully updated helm chart values-staging.yaml with ${STAGING_TAG}"
227+
228+
summary:
229+
needs: [build-and-push, update-helm-chart]
230+
runs-on: ubuntu-latest
231+
if: always()
232+
steps:
233+
- name: Deployment Summary
234+
run: |
235+
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
236+
STAGING_TAG="staging-${SHORT_SHA}"
237+
238+
echo "## 🚀 Staging Deployment Summary" >> $GITHUB_STEP_SUMMARY
239+
echo "" >> $GITHUB_STEP_SUMMARY
240+
echo "**PR:** #${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY
241+
echo "**Commit:** \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
242+
echo "**Staging Tag:** \`${STAGING_TAG}\`" >> $GITHUB_STEP_SUMMARY
243+
echo "" >> $GITHUB_STEP_SUMMARY
244+
echo "### Built Images" >> $GITHUB_STEP_SUMMARY
245+
echo "" >> $GITHUB_STEP_SUMMARY
246+
echo "| Service | Image |" >> $GITHUB_STEP_SUMMARY
247+
echo "|---------|-------|" >> $GITHUB_STEP_SUMMARY
248+
echo "| Backend EE | \`ghcr.io/${{ github.repository }}/digger-backend-ee:${STAGING_TAG}\` |" >> $GITHUB_STEP_SUMMARY
249+
echo "| Drift | \`ghcr.io/${{ github.repository }}/drift:${STAGING_TAG}\` |" >> $GITHUB_STEP_SUMMARY
250+
echo "| Projects Refresh | \`ghcr.io/${{ github.repository }}/projects-refresh-service:${STAGING_TAG}\` |" >> $GITHUB_STEP_SUMMARY
251+
echo "| UI | \`ghcr.io/${{ github.repository }}/taco-ui:${STAGING_TAG}\` |" >> $GITHUB_STEP_SUMMARY
252+
echo "| Taco Statesman | \`ghcr.io/${{ github.repository }}/taco-statesman:${STAGING_TAG}\` |" >> $GITHUB_STEP_SUMMARY
253+
echo "| Taco Token Service | \`ghcr.io/${{ github.repository }}/taco-token-service:${STAGING_TAG}\` |" >> $GITHUB_STEP_SUMMARY
254+
echo "" >> $GITHUB_STEP_SUMMARY
255+
echo "### Pull Images" >> $GITHUB_STEP_SUMMARY
256+
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
257+
echo "docker pull ghcr.io/${{ github.repository }}/digger-backend-ee:${STAGING_TAG}" >> $GITHUB_STEP_SUMMARY
258+
echo "docker pull ghcr.io/${{ github.repository }}/drift:${STAGING_TAG}" >> $GITHUB_STEP_SUMMARY
259+
echo "docker pull ghcr.io/${{ github.repository }}/projects-refresh-service:${STAGING_TAG}" >> $GITHUB_STEP_SUMMARY
260+
echo "docker pull ghcr.io/${{ github.repository }}/taco-ui:${STAGING_TAG}" >> $GITHUB_STEP_SUMMARY
261+
echo "docker pull ghcr.io/${{ github.repository }}/taco-statesman:${STAGING_TAG}" >> $GITHUB_STEP_SUMMARY
262+
echo "docker pull ghcr.io/${{ github.repository }}/taco-token-service:${STAGING_TAG}" >> $GITHUB_STEP_SUMMARY
263+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
264+
echo "" >> $GITHUB_STEP_SUMMARY
265+
echo "### Helm Chart Updated ✅" >> $GITHUB_STEP_SUMMARY
266+
echo "The helm chart \`values-staging.yaml\` has been automatically updated in the [opentaco-helm-charts](https://github.com/diggerhq/opentaco-helm-charts) repository with tag \`${STAGING_TAG}\`." >> $GITHUB_STEP_SUMMARY
267+

Dockerfile_ui

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ RUN --mount=type=cache,target=/root/.npm \
3838
# Bring in built assets and server entry from builder
3939
COPY --from=builder /app/dist ./dist
4040
COPY --from=builder /app/server-start.js ./
41+
COPY --from=builder /app/request-logging.js ./
4142

4243
EXPOSE 3030
4344

backend/controllers/github.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,12 @@ func (d DiggerController) GithubAppWebHook(c *gin.Context) {
7474
slog.Error("Failed to handle installation deleted event", "error", err)
7575
}
7676
} else if *event.Action == "created" || *event.Action == "unsuspended" || *event.Action == "new_permissions_accepted" {
77-
if err := handleInstallationUpsertEvent(c.Request.Context(), gh, event, appId64); err != nil {
77+
// Use background context so work continues after HTTP response
78+
if err := handleInstallationUpsertEvent(context.Background(), gh, event, appId64); err != nil {
7879
slog.Error("Failed to handle installation upsert event", "error", err)
79-
c.String(http.StatusAccepted, "Failed to handle webhook event.")
80-
return
8180
}
8281
}
8382
}(c.Request.Context())
84-
8583
case *github.InstallationRepositoriesEvent:
8684
slog.Info("Processing InstallationRepositoriesEvent",
8785
"action", event.GetAction(),

taco/Dockerfile_token_service

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ WORKDIR /go/src/github.com/diggerhq/digger/taco
77

88
# Copy go.mod/go.sum first for better layer caching
99
COPY cmd/token_service/go.mod cmd/token_service/go.sum ./cmd/token_service/
10+
COPY internal/go.mod internal/go.sum ./internal/
1011
RUN cd cmd/token_service && go mod download
1112

1213
# Copy source code

ui/request-logging.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { unsealData } from 'iron-session';
2+
import { decodeJwt } from 'jose';
3+
4+
// Request logging utilities
5+
export async function extractUserInfoFromRequest(req) {
6+
try {
7+
const cookieName = process.env.WORKOS_COOKIE_NAME || 'wos-session';
8+
const cookiePassword = process.env.WORKOS_COOKIE_PASSWORD;
9+
10+
if (!cookiePassword) {
11+
return { userId: 'anonymous', orgId: 'anonymous' };
12+
}
13+
14+
const cookieHeader = req.headers?.cookie || req.getHeader?.('cookie');
15+
if (!cookieHeader) {
16+
return { userId: 'anonymous', orgId: 'anonymous' };
17+
}
18+
19+
const cookies = cookieHeader.split(';').reduce((acc, cookie) => {
20+
const [key, value] = cookie.trim().split('=');
21+
acc[key] = decodeURIComponent(value);
22+
return acc;
23+
}, {});
24+
25+
const sessionCookie = cookies[cookieName];
26+
if (!sessionCookie) {
27+
return { userId: 'anonymous', orgId: 'anonymous' };
28+
}
29+
30+
const session = await unsealData(sessionCookie, {
31+
password: cookiePassword,
32+
});
33+
34+
if (!session?.user?.id || !session?.accessToken) {
35+
return { userId: 'anonymous', orgId: 'anonymous' };
36+
}
37+
38+
// Decode JWT to get organization ID
39+
let orgId = 'anonymous';
40+
try {
41+
const decoded = decodeJwt(session.accessToken);
42+
orgId = decoded.org_id || 'anonymous';
43+
} catch (error) {
44+
// If JWT decode fails, just use anonymous
45+
}
46+
47+
return { userId: session.user.id, orgId };
48+
} catch (error) {
49+
return { userId: 'anonymous', orgId: 'anonymous' };
50+
}
51+
}
52+
53+
export function logRequestInit(method, path, requestId, userId, orgId) {
54+
console.log(JSON.stringify({
55+
event: 'request_initialized',
56+
method,
57+
path,
58+
requestId,
59+
userId,
60+
orgId,
61+
}));
62+
}
63+
64+
export function logResponse(method, path, requestId, latency, statusCode) {
65+
console.log(JSON.stringify({
66+
event: 'response_sent',
67+
method,
68+
path,
69+
requestId,
70+
latency,
71+
statusCode,
72+
}));
73+
}
74+

0 commit comments

Comments
 (0)