mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-06 04:22:07 +00:00
change hubspot endpoint to grwoth server
This commit is contained in:
122
.github/workflows/production.yml
vendored
122
.github/workflows/production.yml
vendored
@@ -1,75 +1,73 @@
|
||||
name: Production deployment
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
env:
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
STACK_FILE: docker/production.yml
|
||||
REPOSITORY: website
|
||||
REGISTRY_USERNAME: christyjacob4
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
STACK_FILE: docker/production.yml
|
||||
REPOSITORY: website
|
||||
REGISTRY_USERNAME: christyjacob4
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v2
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ghcr.io/appwrite/website:${{ env.TAG }}
|
||||
build-args: |
|
||||
"PUBLIC_APPWRITE_PROJECT_ID=${{ vars.PUBLIC_APPWRITE_PROJECT_ID }}"
|
||||
"PUBLIC_APPWRITE_DB_MAIN_ID=${{ vars.PUBLIC_APPWRITE_DB_MAIN_ID }}"
|
||||
"PUBLIC_APPWRITE_COL_THREADS_ID=${{ vars.PUBLIC_APPWRITE_COL_THREADS_ID }}"
|
||||
"PUBLIC_APPWRITE_COL_MESSAGES_ID=${{ vars.PUBLIC_APPWRITE_COL_MESSAGES_ID }}"
|
||||
"PUBLIC_APPWRITE_FN_TLDR_ID=${{ vars.PUBLIC_APPWRITE_FN_TLDR_ID }}"
|
||||
"PUBLIC_APPWRITE_PROJECT_INIT_ID=${{ vars.PUBLIC_APPWRITE_PROJECT_INIT_ID }}"
|
||||
"APPWRITE_DB_INIT_ID=${{ secrets.APPWRITE_DB_INIT_ID }}"
|
||||
"APPWRITE_COL_INIT_ID=${{ secrets.APPWRITE_COL_INIT_ID }}"
|
||||
"HUBSPOT_INIT_TOKEN=${{ secrets.HUBSPOT_INIT_TOKEN }}"
|
||||
"HUBSPOT_LIST_ID=${{ secrets.HUBSPOT_LIST_ID }}"
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ghcr.io/appwrite/website:${{ env.TAG }}
|
||||
build-args: |
|
||||
"PUBLIC_APPWRITE_PROJECT_ID=${{ vars.PUBLIC_APPWRITE_PROJECT_ID }}"
|
||||
"PUBLIC_APPWRITE_DB_MAIN_ID=${{ vars.PUBLIC_APPWRITE_DB_MAIN_ID }}"
|
||||
"PUBLIC_APPWRITE_COL_THREADS_ID=${{ vars.PUBLIC_APPWRITE_COL_THREADS_ID }}"
|
||||
"PUBLIC_APPWRITE_COL_MESSAGES_ID=${{ vars.PUBLIC_APPWRITE_COL_MESSAGES_ID }}"
|
||||
"PUBLIC_APPWRITE_FN_TLDR_ID=${{ vars.PUBLIC_APPWRITE_FN_TLDR_ID }}"
|
||||
"PUBLIC_APPWRITE_PROJECT_INIT_ID=${{ vars.PUBLIC_APPWRITE_PROJECT_INIT_ID }}"
|
||||
"APPWRITE_DB_INIT_ID=${{ secrets.APPWRITE_DB_INIT_ID }}"
|
||||
"APPWRITE_COL_INIT_ID=${{ secrets.APPWRITE_COL_INIT_ID }}"
|
||||
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Execute SSH commands
|
||||
uses: appleboy/ssh-action@master
|
||||
with:
|
||||
host: ${{ secrets.PRD_SSH_HOST }}
|
||||
username: ${{ secrets.PRD_SSH_USERNAME }}
|
||||
key: ${{ secrets.PRD_SSH_KEY }}
|
||||
script: |
|
||||
url="https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/appwrite/${{ env.REPOSITORY }}.git"
|
||||
if ! git clone "${url}" "${{ env.REPOSITORY }}" 2>/dev/null && [ -d "${{ env.REPOSITORY }}" ] ; then
|
||||
echo "Clone failed because the folder ${{ env.REPOSITORY }} exists"
|
||||
fi
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Execute SSH commands
|
||||
uses: appleboy/ssh-action@master
|
||||
with:
|
||||
host: ${{ secrets.PRD_SSH_HOST }}
|
||||
username: ${{ secrets.PRD_SSH_USERNAME }}
|
||||
key: ${{ secrets.PRD_SSH_KEY }}
|
||||
script: |
|
||||
url="https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/appwrite/${{ env.REPOSITORY }}.git"
|
||||
if ! git clone "${url}" "${{ env.REPOSITORY }}" 2>/dev/null && [ -d "${{ env.REPOSITORY }}" ] ; then
|
||||
echo "Clone failed because the folder ${{ env.REPOSITORY }} exists"
|
||||
fi
|
||||
|
||||
cd ${{ env.REPOSITORY }}
|
||||
git reset --hard HEAD
|
||||
git remote set-url origin $url
|
||||
git fetch origin
|
||||
git checkout ${{ env.TAG }}
|
||||
cd ${{ env.REPOSITORY }}
|
||||
git reset --hard HEAD
|
||||
git remote set-url origin $url
|
||||
git fetch origin
|
||||
git checkout ${{ env.TAG }}
|
||||
|
||||
rm -f .env
|
||||
echo "_APP_VERSION=${{ env.TAG }}" >> .env
|
||||
echo "_APP_DOMAIN=${{ secrets.PRD_APP_DOMAIN }}" >> .env
|
||||
echo "_APP_SYSTEM_SECURITY_EMAIL_ADDRESS=${{ secrets.APP_SYSTEM_SECURITY_EMAIL_ADDRESS }}" >> .env
|
||||
echo "SEMATEXT_TOKEN=${{ secrets.SEMATEXT_TOKEN }}" >> .env
|
||||
rm -f .env
|
||||
echo "_APP_VERSION=${{ env.TAG }}" >> .env
|
||||
echo "_APP_DOMAIN=${{ secrets.PRD_APP_DOMAIN }}" >> .env
|
||||
echo "_APP_SYSTEM_SECURITY_EMAIL_ADDRESS=${{ secrets.APP_SYSTEM_SECURITY_EMAIL_ADDRESS }}" >> .env
|
||||
echo "SEMATEXT_TOKEN=${{ secrets.SEMATEXT_TOKEN }}" >> .env
|
||||
|
||||
echo ${{ secrets.GH_REGISTRY_TOKEN }} | docker login ghcr.io --username ${{ env.REGISTRY_USERNAME }} --password-stdin
|
||||
docker-compose -f ${{ env.STACK_FILE }} config
|
||||
env $(cat .env | xargs) docker stack deploy --prune --resolve-image always --with-registry-auth -c ${{ env.STACK_FILE }} ${{ env.REPOSITORY }}
|
||||
echo ${{ secrets.GH_REGISTRY_TOKEN }} | docker login ghcr.io --username ${{ env.REGISTRY_USERNAME }} --password-stdin
|
||||
docker-compose -f ${{ env.STACK_FILE }} config
|
||||
env $(cat .env | xargs) docker stack deploy --prune --resolve-image always --with-registry-auth -c ${{ env.STACK_FILE }} ${{ env.REPOSITORY }}
|
||||
|
||||
124
.github/workflows/staging.yml
vendored
124
.github/workflows/staging.yml
vendored
@@ -1,76 +1,74 @@
|
||||
name: Staging deployment
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
env:
|
||||
TAG: ${{ github.sha }}
|
||||
STACK_FILE: docker/stage.yml
|
||||
REPOSITORY: website
|
||||
REGISTRY_USERNAME: christyjacob4
|
||||
TAG: ${{ github.sha }}
|
||||
STACK_FILE: docker/stage.yml
|
||||
REPOSITORY: website
|
||||
REGISTRY_USERNAME: christyjacob4
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v2
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ghcr.io/appwrite/website:${{ env.TAG }}
|
||||
build-args: |
|
||||
"PUBLIC_APPWRITE_PROJECT_ID=${{ vars.PUBLIC_APPWRITE_PROJECT_ID }}"
|
||||
"PUBLIC_APPWRITE_DB_MAIN_ID=${{ vars.PUBLIC_APPWRITE_DB_MAIN_ID }}"
|
||||
"PUBLIC_APPWRITE_COL_THREADS_ID=${{ vars.PUBLIC_APPWRITE_COL_THREADS_ID }}"
|
||||
"PUBLIC_APPWRITE_COL_MESSAGES_ID=${{ vars.PUBLIC_APPWRITE_COL_MESSAGES_ID }}"
|
||||
"PUBLIC_APPWRITE_FN_TLDR_ID=${{ vars.PUBLIC_APPWRITE_FN_TLDR_ID }}"
|
||||
"PUBLIC_APPWRITE_PROJECT_INIT_ID=${{ vars.PUBLIC_APPWRITE_PROJECT_INIT_ID }}"
|
||||
"APPWRITE_DB_INIT_ID=${{ secrets.APPWRITE_DB_INIT_ID }}"
|
||||
"APPWRITE_COL_INIT_ID=${{ secrets.APPWRITE_COL_INIT_ID }}"
|
||||
"HUBSPOT_INIT_TOKEN=${{ secrets.HUBSPOT_INIT_TOKEN }}"
|
||||
"HUBSPOT_LIST_ID=${{ secrets.HUBSPOT_LIST_ID }}"
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ghcr.io/appwrite/website:${{ env.TAG }}
|
||||
build-args: |
|
||||
"PUBLIC_APPWRITE_PROJECT_ID=${{ vars.PUBLIC_APPWRITE_PROJECT_ID }}"
|
||||
"PUBLIC_APPWRITE_DB_MAIN_ID=${{ vars.PUBLIC_APPWRITE_DB_MAIN_ID }}"
|
||||
"PUBLIC_APPWRITE_COL_THREADS_ID=${{ vars.PUBLIC_APPWRITE_COL_THREADS_ID }}"
|
||||
"PUBLIC_APPWRITE_COL_MESSAGES_ID=${{ vars.PUBLIC_APPWRITE_COL_MESSAGES_ID }}"
|
||||
"PUBLIC_APPWRITE_FN_TLDR_ID=${{ vars.PUBLIC_APPWRITE_FN_TLDR_ID }}"
|
||||
"PUBLIC_APPWRITE_PROJECT_INIT_ID=${{ vars.PUBLIC_APPWRITE_PROJECT_INIT_ID }}"
|
||||
"APPWRITE_DB_INIT_ID=${{ secrets.APPWRITE_DB_INIT_ID }}"
|
||||
"APPWRITE_COL_INIT_ID=${{ secrets.APPWRITE_COL_INIT_ID }}"
|
||||
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Execute SSH commands
|
||||
uses: appleboy/ssh-action@master
|
||||
with:
|
||||
host: ${{ secrets.STG_SSH_HOST }}
|
||||
username: ${{ secrets.STG_SSH_USERNAME }}
|
||||
key: ${{ secrets.STG_SSH_KEY }}
|
||||
script: |
|
||||
url="https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/appwrite/${{ env.REPOSITORY }}.git"
|
||||
if ! git clone "${url}" "${{ env.REPOSITORY }}" 2>/dev/null && [ -d "${{ env.REPOSITORY }}" ] ; then
|
||||
echo "Clone failed because the folder ${{ env.REPOSITORY }} exists"
|
||||
fi
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Execute SSH commands
|
||||
uses: appleboy/ssh-action@master
|
||||
with:
|
||||
host: ${{ secrets.STG_SSH_HOST }}
|
||||
username: ${{ secrets.STG_SSH_USERNAME }}
|
||||
key: ${{ secrets.STG_SSH_KEY }}
|
||||
script: |
|
||||
url="https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/appwrite/${{ env.REPOSITORY }}.git"
|
||||
if ! git clone "${url}" "${{ env.REPOSITORY }}" 2>/dev/null && [ -d "${{ env.REPOSITORY }}" ] ; then
|
||||
echo "Clone failed because the folder ${{ env.REPOSITORY }} exists"
|
||||
fi
|
||||
|
||||
cd ${{ env.REPOSITORY }}
|
||||
git reset --hard HEAD
|
||||
git remote set-url origin $url
|
||||
git fetch origin
|
||||
git checkout ${{ env.TAG }}
|
||||
cd ${{ env.REPOSITORY }}
|
||||
git reset --hard HEAD
|
||||
git remote set-url origin $url
|
||||
git fetch origin
|
||||
git checkout ${{ env.TAG }}
|
||||
|
||||
rm -f .env
|
||||
echo "_APP_VERSION=${{ env.TAG }}" >> .env
|
||||
echo "_APP_DOMAIN=${{ secrets.STG_APP_DOMAIN }}" >> .env
|
||||
echo "_APP_SYSTEM_SECURITY_EMAIL_ADDRESS=${{ secrets.APP_SYSTEM_SECURITY_EMAIL_ADDRESS }}" >> .env
|
||||
echo "SEMATEXT_TOKEN=${{ secrets.SEMATEXT_TOKEN }}" >> .env
|
||||
rm -f .env
|
||||
echo "_APP_VERSION=${{ env.TAG }}" >> .env
|
||||
echo "_APP_DOMAIN=${{ secrets.STG_APP_DOMAIN }}" >> .env
|
||||
echo "_APP_SYSTEM_SECURITY_EMAIL_ADDRESS=${{ secrets.APP_SYSTEM_SECURITY_EMAIL_ADDRESS }}" >> .env
|
||||
echo "SEMATEXT_TOKEN=${{ secrets.SEMATEXT_TOKEN }}" >> .env
|
||||
|
||||
echo ${{ secrets.GH_REGISTRY_TOKEN }} | docker login ghcr.io --username ${{ env.REGISTRY_USERNAME }} --password-stdin
|
||||
docker-compose -f ${{ env.STACK_FILE }} config
|
||||
env $(cat .env | xargs) docker stack deploy --prune --resolve-image always --with-registry-auth -c ${{ env.STACK_FILE }} ${{ env.REPOSITORY }}
|
||||
echo ${{ secrets.GH_REGISTRY_TOKEN }} | docker login ghcr.io --username ${{ env.REGISTRY_USERNAME }} --password-stdin
|
||||
docker-compose -f ${{ env.STACK_FILE }} config
|
||||
env $(cat .env | xargs) docker stack deploy --prune --resolve-image always --with-registry-auth -c ${{ env.STACK_FILE }} ${{ env.REPOSITORY }}
|
||||
|
||||
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@@ -45,6 +45,4 @@ jobs:
|
||||
PUBLIC_APPWRITE_PROJECT_INIT_ID: ${{ secrets.PUBLIC_APPWRITE_PROJECT_INIT_ID }}
|
||||
APPWRITE_DB_INIT_ID: ${{ secrets.APPWRITE_DB_INIT_ID }}
|
||||
APPWRITE_COL_INIT_ID: ${{ secrets.APPWRITE_COL_INIT_ID }}
|
||||
HUBSPOT_INIT_TOKEN: ${{ secrets.HUBSPOT_INIT_TOKEN }}
|
||||
HUBSPOT_LIST_ID: ${{ secrets.HUBSPOT_LIST_ID }}
|
||||
run: pnpm run build
|
||||
|
||||
@@ -25,11 +25,7 @@ ENV APPWRITE_DB_INIT_ID ${APPWRITE_DB_INIT_ID}
|
||||
ARG APPWRITE_COL_INIT_ID
|
||||
ENV APPWRITE_COL_INIT_ID ${APPWRITE_COL_INIT_ID}
|
||||
|
||||
ARG HUBSPOT_INIT_TOKEN
|
||||
ENV HUBSPOT_INIT_TOKEN ${HUBSPOT_INIT_TOKEN}
|
||||
|
||||
ARG HUBSPOT_LIST_ID
|
||||
ENV HUBSPOT_LIST_ID ${HUBSPOT_LIST_ID}
|
||||
|
||||
ENV PNPM_HOME="/pnpm"
|
||||
ENV PATH="$PNPM_HOME:$PATH"
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import { HUBSPOT_INIT_TOKEN } from '$env/static/private';
|
||||
|
||||
export const hubspot = {
|
||||
fetch: async (path: string, options?: RequestInit) => {
|
||||
return fetch(`https://api.hubapi.com/crm/v3/${path}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${HUBSPOT_INIT_TOKEN}`,
|
||||
'Content-Type': 'application/json',
|
||||
...options?.headers
|
||||
},
|
||||
...options
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,23 +1,9 @@
|
||||
import { APPWRITE_COL_INIT_ID, APPWRITE_DB_INIT_ID, HUBSPOT_LIST_ID } from '$env/static/private';
|
||||
import { APPWRITE_COL_INIT_ID, APPWRITE_DB_INIT_ID } from '$env/static/private';
|
||||
import { appwriteInit } from '$lib/appwrite/init.js';
|
||||
import { isProUser } from '$lib/utils/console.js';
|
||||
import type { User } from '$routes/init/helpers.js';
|
||||
import { ID, Query } from '@appwrite.io/console';
|
||||
import type { TicketData, TicketDoc } from '../constants.js';
|
||||
import { hubspot } from '$lib/hubspot.server.js';
|
||||
import { isProUser } from '$lib/utils/console.js';
|
||||
|
||||
type Contact = {
|
||||
id: string;
|
||||
properties: {
|
||||
email: string;
|
||||
hs_object_id: '4831113';
|
||||
lastmodifieddate: '2024-01-24T09:16:04.042Z';
|
||||
};
|
||||
};
|
||||
|
||||
type ContactResults = {
|
||||
results: Array<Contact>;
|
||||
};
|
||||
|
||||
type SendToHubspotArgs = {
|
||||
name: string;
|
||||
@@ -25,43 +11,16 @@ type SendToHubspotArgs = {
|
||||
};
|
||||
|
||||
async function sendToHubspot({ name, email }: SendToHubspotArgs) {
|
||||
// See if contact exists
|
||||
const contacts: ContactResults = await hubspot
|
||||
.fetch('objects/contacts/batch/read', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
properties: ['email'],
|
||||
idProperty: 'email',
|
||||
inputs: [
|
||||
{
|
||||
id: email
|
||||
}
|
||||
]
|
||||
})
|
||||
await fetch('https://growth.appwrite.io/v1/mailinglists/init', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
name
|
||||
})
|
||||
.then((res) => res.json());
|
||||
let contact = contacts.results?.[0];
|
||||
|
||||
if (!contact) {
|
||||
contact = await hubspot
|
||||
.fetch('objects/contacts', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
properties: {
|
||||
email: email,
|
||||
firstname: name
|
||||
}
|
||||
})
|
||||
})
|
||||
.then((res) => res.json());
|
||||
}
|
||||
|
||||
await hubspot
|
||||
.fetch(`lists/${HUBSPOT_LIST_ID}/memberships/add`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify([contact.id])
|
||||
})
|
||||
.then((res) => res.json());
|
||||
});
|
||||
}
|
||||
|
||||
async function getTicketDocByUser(user: User) {
|
||||
@@ -75,13 +34,13 @@ async function getTicketDocByUser(user: User) {
|
||||
const [gh, aw, isPro] = await Promise.all([
|
||||
user.github?.login
|
||||
? appwriteInit.database.listDocuments(APPWRITE_DB_INIT_ID, APPWRITE_COL_INIT_ID, [
|
||||
Query.equal('gh_user', user.github.login)
|
||||
])
|
||||
Query.equal('gh_user', user.github.login)
|
||||
])
|
||||
: null,
|
||||
user.appwrite?.$id
|
||||
? appwriteInit.database.listDocuments(APPWRITE_DB_INIT_ID, APPWRITE_COL_INIT_ID, [
|
||||
Query.equal('aw_email', user.appwrite.email)
|
||||
])
|
||||
Query.equal('aw_email', user.appwrite.email)
|
||||
])
|
||||
: null,
|
||||
isProUser()
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user