Skip to content

Commit

Permalink
Add posthog proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
domdomegg committed Apr 30, 2024
1 parent 8aaad25 commit 4f50604
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ We recommend most contributors learn how to:
- On macOS with Homebrew: `brew install docker`
- On Ubuntu Linux: [instructions](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-22-04)
5. Install and configure a container runtime.
- On macOS with Homebrew: `brew install colima && docker context use colima`
- On macOS with Homebrew: `brew install colima && brew services start colima && docker context use colima`
- On Ubuntu Linux: already installed with client
- Other platforms: [Docker Engine](https://docs.docker.com/engine/install/) (NB: NOT Docker Desktop) or [Podman](https://podman.io/docs/installation)
6. Install kubectl.
Expand Down
12 changes: 12 additions & 0 deletions apps/infra/src/k8s/serviceDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ export const services: ServiceDefinition[] = [
},
hosts: ['forms.bluedot.org'],
},
{
name: 'bluedot-posthog-proxy',
targetPort: 80,
spec: {
containers: [{
name: 'bluedot-posthog-proxy',
image: 'sjc.vultrcr.com/bluedot/bluedot-posthog-proxy:latest',
}],
imagePullSecrets: [{ name: containerRegistrySecret.metadata.name }],
},
hosts: ['analytics.k8s.bluedot.org'],
},
{
name: 'bluedot-meet',
targetPort: 8080,
Expand Down
7 changes: 1 addition & 6 deletions apps/miniextensions-proxy/src/nginx.template.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
http {
map $http_x_forwarded_proto $input_scheme {
default $http_x_forwarded_proto;
'' $scheme;
}

server {
listen 80;
add_header X-BlueDot-Version '$VERSION_TAG';
Expand All @@ -12,7 +7,7 @@ http {
location = / {
if ($host ~* ^[^.]+\.(.+)$) {
set $parent_domain $1;
rewrite ^ http://$parent_domain permanent;
rewrite ^ https://$parent_domain permanent;
}
}

Expand Down
8 changes: 8 additions & 0 deletions apps/posthog-proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM nginx:stable-alpine-slim

COPY src/nginx.template.conf /etc/nginx/nginx.template.conf
ARG VERSION_TAG
RUN envsubst '$VERSION_TAG' < /etc/nginx/nginx.template.conf > /etc/nginx/nginx.conf
RUN nginx -t

EXPOSE 80
8 changes: 8 additions & 0 deletions apps/posthog-proxy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@bluedot/posthog-proxy",
"version": "1.0.0",
"private": true,
"scripts": {
"deploy:prod": "tools/deployDocker.sh"
}
}
26 changes: 26 additions & 0 deletions apps/posthog-proxy/src/nginx.template.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
http {
server {
listen 80;
add_header X-BlueDot-Version '$VERSION_TAG';

# Redirect the course hub homepage back to the main website
location = / {
if ($host ~* ^[^.]+\.(.+)$) {
set $parent_domain $1;
rewrite ^ https://$parent_domain permanent;
}
}

location / {
proxy_pass https://eu.posthog.com;
proxy_redirect off;
proxy_ssl_session_reuse off;
proxy_ssl_server_name on;
proxy_set_header Host eu.posthog.com;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}

events {}
23 changes: 23 additions & 0 deletions apps/posthog-proxy/tools/deployDocker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euxo pipefail

cd $(dirname "${BASH_SOURCE[0]:-$0}")/..

APP_NAME=$(basename "$PWD")
REPO_URL="sjc.vultrcr.com/bluedot"
IMAGE_NAME="bluedot-$APP_NAME"
VERSION_TAG="$(TZ=UTC date +'%Y%m%d.%H%M%S').$(git rev-parse --short HEAD)"

# Build
APP_NAME=$APP_NAME VERSION_TAG=$VERSION_TAG npm run build --if-present
docker build --platform="linux/amd64" -t $IMAGE_NAME --build-arg APP_NAME="$APP_NAME" --build-arg VERSION_TAG="$VERSION_TAG" .

# Tag and push to registry
docker tag $IMAGE_NAME $REPO_URL/$IMAGE_NAME:$VERSION_TAG
docker tag $IMAGE_NAME $REPO_URL/$IMAGE_NAME:latest
docker push $REPO_URL/$IMAGE_NAME:$VERSION_TAG
docker push $REPO_URL/$IMAGE_NAME:latest

# Restart nodes in cluster so they pull the new image
kubectl rollout restart deployment $IMAGE_NAME-deployment
kubectl rollout status deployment $IMAGE_NAME-deployment
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4f50604

Please sign in to comment.