Skip to content

Commit f23898f

Browse files
committed
feat: add posthog config to production deploys
1 parent e86d4c8 commit f23898f

2 files changed

Lines changed: 54 additions & 33 deletions

File tree

.github/workflows/_deploy-environment.yml

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ jobs:
5252
build-args: |
5353
BASEURL=${{ vars.BACKEND_API_URL }}
5454
GOOGLE_CLIENT_ID=${{ vars.GOOGLE_CLIENT_ID }}
55+
POSTHOG_KEY=${{ (inputs.environment == 'production' || inputs.environment == 'staging-cloud') && vars.POSTHOG_KEY || '' }}
56+
POSTHOG_HOST=${{ (inputs.environment == 'production' || inputs.environment == 'staging-cloud') && vars.POSTHOG_HOST || '' }}
5557
COMPASS_BUILD_REF=${{ steps.version.outputs.image_version }}
5658
tags: switchbacktech/compass-web:${{ inputs.environment }}-${{ steps.version.outputs.image_version }}
5759

@@ -65,6 +67,8 @@ jobs:
6567
GCAL_NOTIFICATION_EXPIRATION_MIN: ${{ vars.GCAL_NOTIFICATION_EXPIRATION_MIN }}
6668
GOOGLE_CLIENT_ID: ${{ vars.GOOGLE_CLIENT_ID }}
6769
IMAGE_VERSION: ${{ steps.version.outputs.image_version }}
70+
POSTHOG_KEY: ${{ (inputs.environment == 'production' || inputs.environment == 'staging-cloud') && vars.POSTHOG_KEY || '' }}
71+
POSTHOG_HOST: ${{ (inputs.environment == 'production' || inputs.environment == 'staging-cloud') && vars.POSTHOG_HOST || '' }}
6872
RELEASE_TAG: ${{ inputs.tag }}
6973
SSH_HOST: ${{ vars.SSH_HOST }}
7074
SSH_USER: ${{ vars.SSH_USER }}
@@ -86,39 +90,46 @@ jobs:
8690
echo "$SSH_PRIVATE_KEY" > ~/.ssh/staging_key
8791
chmod 600 ~/.ssh/staging_key
8892
ssh-keyscan -H "$SSH_HOST" >> ~/.ssh/known_hosts
89-
printf '%s\n' \
90-
'runtime:' \
91-
" version: \"${IMAGE_VERSION}\"" \
92-
' nodeEnv: production' \
93-
' timezone: Etc/UTC' \
94-
'web:' \
95-
' port: 9080' \
96-
" url: \"${FRONTEND_URL}\"" \
97-
" image: \"${WEB_IMAGE}\"" \
98-
'backend:' \
99-
' port: 3000' \
100-
" apiUrl: \"${BACKEND_API_URL}\"" \
101-
' originsAllowed:' \
102-
" - \"${FRONTEND_URL}\"" \
103-
" compassToken: \"${COMPASS_SYNC_TOKEN}\"" \
104-
'mongo:' \
105-
' username: compass' \
106-
" password: \"${MONGO_PASSWORD}\"" \
107-
${MONGO_REPLICA_SET_KEY:+" replicaSetKey: \"${MONGO_REPLICA_SET_KEY}\""} \
108-
" uri: \"${MONGO_URI}\"" \
109-
'supertokens:' \
110-
" uri: \"${SUPERTOKENS_URI}\"" \
111-
" key: \"${SUPERTOKENS_KEY}\"" \
112-
${SUPERTOKENS_POSTGRES_PASSWORD:+' postgres:'} \
113-
${SUPERTOKENS_POSTGRES_PASSWORD:+' user: supertokens'} \
114-
${SUPERTOKENS_POSTGRES_PASSWORD:+" password: \"${SUPERTOKENS_POSTGRES_PASSWORD}\""} \
115-
${SUPERTOKENS_POSTGRES_PASSWORD:+' database: supertokens'} \
116-
'google:' \
117-
" clientId: \"${GOOGLE_CLIENT_ID}\"" \
118-
" clientSecret: \"${GOOGLE_CLIENT_SECRET}\"" \
119-
" notificationToken: \"${GCAL_NOTIFICATION_TOKEN}\"" \
120-
${GCAL_NOTIFICATION_EXPIRATION_MIN:+" channelExpirationMin: ${GCAL_NOTIFICATION_EXPIRATION_MIN}"} \
121-
| ssh -i ~/.ssh/staging_key "$SSH_USER@$SSH_HOST" \
93+
{
94+
printf '%s\n' \
95+
'runtime:' \
96+
" version: \"${IMAGE_VERSION}\"" \
97+
' nodeEnv: production' \
98+
' timezone: Etc/UTC' \
99+
'web:' \
100+
' port: 9080' \
101+
" url: \"${FRONTEND_URL}\"" \
102+
" image: \"${WEB_IMAGE}\"" \
103+
'backend:' \
104+
' port: 3000' \
105+
" apiUrl: \"${BACKEND_API_URL}\"" \
106+
' originsAllowed:' \
107+
" - \"${FRONTEND_URL}\"" \
108+
" compassToken: \"${COMPASS_SYNC_TOKEN}\"" \
109+
'mongo:' \
110+
' username: compass' \
111+
" password: \"${MONGO_PASSWORD}\"" \
112+
${MONGO_REPLICA_SET_KEY:+" replicaSetKey: \"${MONGO_REPLICA_SET_KEY}\""} \
113+
" uri: \"${MONGO_URI}\"" \
114+
'supertokens:' \
115+
" uri: \"${SUPERTOKENS_URI}\"" \
116+
" key: \"${SUPERTOKENS_KEY}\"" \
117+
${SUPERTOKENS_POSTGRES_PASSWORD:+' postgres:'} \
118+
${SUPERTOKENS_POSTGRES_PASSWORD:+' user: supertokens'} \
119+
${SUPERTOKENS_POSTGRES_PASSWORD:+" password: \"${SUPERTOKENS_POSTGRES_PASSWORD}\""} \
120+
${SUPERTOKENS_POSTGRES_PASSWORD:+' database: supertokens'} \
121+
'google:' \
122+
" clientId: \"${GOOGLE_CLIENT_ID}\"" \
123+
" clientSecret: \"${GOOGLE_CLIENT_SECRET}\"" \
124+
" notificationToken: \"${GCAL_NOTIFICATION_TOKEN}\"" \
125+
${GCAL_NOTIFICATION_EXPIRATION_MIN:+" channelExpirationMin: ${GCAL_NOTIFICATION_EXPIRATION_MIN}"}
126+
if [ -n "$POSTHOG_KEY" ] && [ -n "$POSTHOG_HOST" ]; then
127+
printf '%s\n' \
128+
'posthog:' \
129+
" key: \"${POSTHOG_KEY}\"" \
130+
" host: \"${POSTHOG_HOST}\""
131+
fi
132+
} | ssh -i ~/.ssh/staging_key "$SSH_USER@$SSH_HOST" \
122133
"umask 077 && mkdir -p ~/compass && cat > ~/compass/compass.yaml && chmod 644 ~/compass/compass.yaml"
123134
COMPOSE_GIT_REF="${COMPOSE_GIT_REF:-${RELEASE_TAG}}"
124135
compose_url="https://raw.githubusercontent.com/SwitchbackTech/compass/${COMPOSE_GIT_REF}/self-host/compose.yaml"

self-host/Dockerfile.web

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ COPY . .
55

66
ARG BASEURL=http://localhost:3000/api
77
ARG GOOGLE_CLIENT_ID=
8+
ARG POSTHOG_KEY=
9+
ARG POSTHOG_HOST=
810
ARG COMPASS_BUILD_REF=self-host
911

1012
ENV COMPASS_BUILD_REF=${COMPASS_BUILD_REF}
@@ -29,6 +31,14 @@ RUN printf '%s\n' \
2931
" clientId: ${GOOGLE_CLIENT_ID}" \
3032
> compass.yaml
3133

34+
RUN if [ -n "$POSTHOG_KEY" ] && [ -n "$POSTHOG_HOST" ]; then \
35+
printf '%s\n' \
36+
'posthog:' \
37+
" key: ${POSTHOG_KEY}" \
38+
" host: ${POSTHOG_HOST}" \
39+
>> compass.yaml; \
40+
fi
41+
3242
RUN bun install --frozen-lockfile
3343
RUN cd packages/web && bun run build.ts
3444

0 commit comments

Comments
 (0)