Skip to content

Commit

Permalink
Add deploy buttons and clean environment variables (#974)
Browse files Browse the repository at this point in the history
* add render.yaml

* Clean environment variables



---------

Co-authored-by: Charles Bochet <[email protected]>
  • Loading branch information
FelixMalfait and charlesBochet authored Jul 31, 2023
1 parent a90cbac commit b028d9f
Show file tree
Hide file tree
Showing 31 changed files with 194 additions and 112 deletions.
19 changes: 5 additions & 14 deletions .ergomake/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ services:
context: ..
dockerfile: ./infra/prod/front/Dockerfile
args:
REACT_APP_API_URL: "http://localhost:3000/graphql"
REACT_APP_AUTH_URL: "http://localhost:3000/auth"
REACT_APP_FILES_URL: "http://localhost:3000/files"
REACT_APP_SERVER_BASE_URL: "http://localhost:3000"
ports:
- "3001:3000"
labels:
dev.ergomake.env.replace-arg.REACT_APP_API_URL: "https://{{ services.server.url }}/graphql"
dev.ergomake.env.replace-arg.REACT_APP_AUTH_URL: "https://{{ services.server.url }}/auth"
dev.ergomake.env.replace-arg.REACT_APP_FILES_URL: "https://{{ services.server.url }}/files"
dev.ergomake.env.replace-arg.REACT_APP_SERVER_BASE_URL: "https://{{ services.server.url }}"
server:
build:
context: ..
Expand All @@ -23,19 +19,14 @@ services:
- "3000:3000"
environment:
DEBUG_MODE: false
DEMO_MODE: true
IS_SIGN_IN_PREFILLED: true
ACCESS_TOKEN_SECRET: "secret_jwt"
ACCESS_TOKEN_EXPIRES_IN: "30m"
LOGIN_TOKEN_SECRET: "secret_login_token"
LOGIN_TOKEN_EXPIRES_IN: "15m"
REFRESH_TOKEN_SECRET: "secret_refresh_token"
REFRESH_TOKEN_EXPIRES_IN: "90d"
PG_DATABASE_URL: "postgres://postgres:postgrespassword@postgres:5432/default?connection_limit=1"
FRONT_AUTH_CALLBACK_URL: "http://localhost:3000/verify"
STORAGE_TYPE: "local"
STORAGE_LOCAL_PATH: ".local-storage"
FRONT_BASE_URL: "http://localhost:3000"
labels:
dev.ergomake.env.replace-env.FRONT_AUTH_CALLBACK_URL: "https://{{ services.server.url }}/verify"
dev.ergomake.env.replace-env.FRONT_BASE_URL: "https://{{ services.server.url }}"
postgres:
build: ../infra/dev/postgres
environment:
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/ci-chromatic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ jobs:
if: ${{ contains(github.event.*.labels.*.name, 'run-chromatic') }} || github.event_name == 'push' }}
runs-on: ubuntu-latest
env:
REACT_APP_API_URL: http://127.0.0.1:3000/graphql
REACT_APP_AUTH_URL: http://127.0.0.1:3000/auth
REACT_APP_FILES_URL: http://127.0.0.1:3000/files
REACT_APP_SERVER_BASE_URL: http://127.0.0.1:3000
steps:
- uses: actions/checkout@v3
if: github.event_name == 'push'
Expand All @@ -33,9 +31,7 @@ jobs:
run: |
cd front
touch .env
echo "REACT_APP_API_URL: $REACT_APP_API_URL" >> .env
echo "REACT_APP_AUTH_URL: $REACT_APP_AUTH_URL" >> .env
echo "REACT_APP_FILES_URL: $REACT_APP_FILES_URL" >> .env
echo "REACT_APP_SERVER_BASE_URL: $REACT_APP_SERVER_BASE_URL" >> .env
- name: Front / Install Dependencies
run: cd front && yarn
- name: Publish to Chromatic
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/ci-front.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ jobs:
front-test:
runs-on: ubuntu-latest
env:
REACT_APP_API_URL: http://localhost:3000/graphql
REACT_APP_AUTH_URL: http://localhost:3000/auth
REACT_APP_FILES_URL: http://localhost:3000/files
REACT_APP_SERVER_BASE_URL: http://localhost:3000
steps:
- uses: actions/checkout@v3
if: github.event_name == 'push'
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/developer/local-setup.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
sidebar_position: 0
sidebar_custom_props:
icon: TbArrowBigRight
icon: TbDeviceDesktop
---

# Local Setup
Expand Down
17 changes: 12 additions & 5 deletions docs/docs/hosting/self-hosting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ You will find these in the [infra/prod/front/Dockerfile](https://github.com/twen

```bash
docker build \
--build-arg REACT_APP_API_URL=REPLACE_ME \
--build-arg REACT_APP_AUTH_URL=REPLACE_ME \
--build-arg REACT_APP_FILES_URL=REPLACE_ME \
--build-arg REACT_APP_SERVER_BASE_URL=REPLACE_ME \
-t twenty-front:latest \
-f ./infra/prod/front/Dockerfile .
```
Expand All @@ -36,10 +34,19 @@ docker build \
-f ./infra/prod/server/Dockerfile .
```

## Render

[![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy?repo=https://github.com/twentyhq/twenty)


## AWS Elastic Beanstalk (soon)

We are working on providing a joint Docker image - containing both the Twenty frontend and server - that you can deploy using [AWS Elastic Beanstalk](https://aws.amazon.com/elasticbeanstalk/).

## Railway (soon)

[Railway](https://railway.app) is an infrastructure platform that lets you deploy to the cloud in one click. We are currently working on making it available.
<!--

## Railway
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/YWGqza?referralCode=3CLObs)

-->
2 changes: 1 addition & 1 deletion docs/docs/others/CLI.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ sidebar_custom_props:
icon: TbTerminal2
---

# CLI (soon)
# CLI

Available soon!
5 changes: 3 additions & 2 deletions docs/src/theme/DocSidebarItem/Link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Link from '@docusaurus/Link';
import isInternalUrl from '@docusaurus/isInternalUrl';
import IconExternalLink from '@theme/Icon/ExternalLink';
import styles from './styles.module.css';
import { TbFaceIdError, TbTerminal2, TbCloud, TbServer, TbBolt, TbApps, TbTopologyStar, TbChartDots, TbBug, TbVocabulary, TbArrowBigRight } from "react-icons/tb";
import { TbFaceIdError, TbTerminal2, TbCloud, TbServer, TbBolt, TbApps, TbTopologyStar, TbChartDots, TbBug, TbVocabulary, TbArrowBigRight, TbDeviceDesktop } from "react-icons/tb";


export default function DocSidebarItemLink({
Expand All @@ -30,7 +30,8 @@ export default function DocSidebarItemLink({
'TbTopologyStar': TbTopologyStar,
'TbChartDots': TbChartDots,
'TbBug': TbBug,
'TbVocabulary': TbVocabulary
'TbVocabulary': TbVocabulary,
'TbDeviceDesktop': TbDeviceDesktop,
};

let IconComponent = customProps && customProps.icon ? icons[customProps.icon] : TbFaceIdError;
Expand Down
9 changes: 5 additions & 4 deletions front/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
REACT_APP_API_URL=http://localhost:3000/graphql
REACT_APP_AUTH_URL=http://localhost:3000/auth
REACT_APP_FILES_URL=http://localhost:3000/files
REACT_APP_SERVER_BASE_URL=http://localhost:3000

CHROMATIC_PROJECT_TOKEN=REPLACE_ME
# ———————— Optional ————————
# REACT_APP_SERVER_AUTH_URL=http://localhost:3000/auth
# REACT_APP_SERVER_FILES_URL=http://localhost:3000/files
# CHROMATIC_PROJECT_TOKEN=
2 changes: 1 addition & 1 deletion front/codegen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
schema: process.env.REACT_APP_API_URL,
schema: process.env.REACT_APP_SERVER_BASE_URL + "/graphql",
documents: ['./src/**/*.tsx', './src/**/*.ts'],
overwrite: true,
generates: {
Expand Down
6 changes: 3 additions & 3 deletions front/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ export type ClientConfig = {
__typename?: 'ClientConfig';
authProviders: AuthProviders;
debugMode: Scalars['Boolean'];
demoMode: Scalars['Boolean'];
signInPrefilled: Scalars['Boolean'];
telemetry: Telemetry;
};

Expand Down Expand Up @@ -2333,7 +2333,7 @@ export type RenewTokenMutation = { __typename?: 'Mutation', renewToken: { __type
export type GetClientConfigQueryVariables = Exact<{ [key: string]: never; }>;


export type GetClientConfigQuery = { __typename?: 'Query', clientConfig: { __typename?: 'ClientConfig', demoMode: boolean, debugMode: boolean, authProviders: { __typename?: 'AuthProviders', google: boolean, password: boolean }, telemetry: { __typename?: 'Telemetry', enabled: boolean, anonymizationEnabled: boolean } } };
export type GetClientConfigQuery = { __typename?: 'Query', clientConfig: { __typename?: 'ClientConfig', signInPrefilled: boolean, debugMode: boolean, authProviders: { __typename?: 'AuthProviders', google: boolean, password: boolean }, telemetry: { __typename?: 'Telemetry', enabled: boolean, anonymizationEnabled: boolean } } };

export type GetCompaniesQueryVariables = Exact<{
orderBy?: InputMaybe<Array<CompanyOrderByWithRelationInput> | CompanyOrderByWithRelationInput>;
Expand Down Expand Up @@ -3369,7 +3369,7 @@ export const GetClientConfigDocument = gql`
google
password
}
demoMode
signInPrefilled
debugMode
telemetry {
enabled
Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/apollo/hooks/useApolloFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function useApolloFactory() {

const apolloClient = useMemo(() => {
apolloRef.current = new ApolloFactory({
uri: `${process.env.REACT_APP_API_URL}`,
uri: `${process.env.REACT_APP_SERVER_BASE_URL}/graphql`,
cache: new InMemoryCache({
typePolicies: {
Activity: {
Expand Down
5 changes: 4 additions & 1 deletion front/src/modules/auth/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ export function useAuth() {
);

const handleGoogleLogin = useCallback((workspaceInviteHash?: string) => {
const authServerUrl =
process.env.REACT_APP_SERVER_AUTH_URL ??
process.env.REACT_APP_SERVER_BASE_URL + '/auth';
window.location.href =
`${process.env.REACT_APP_AUTH_URL}/google/${
`${authServerUrl}/google/${
workspaceInviteHash ? '?inviteHash=' + workspaceInviteHash : ''
}` || '';
}, []);
Expand Down
8 changes: 4 additions & 4 deletions front/src/modules/auth/sign-in-up/hooks/useSignInUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useRecoilState, useRecoilValue } from 'recoil';
import * as Yup from 'yup';

import { authProvidersState } from '@/client-config/states/authProvidersState';
import { isDemoModeState } from '@/client-config/states/isDemoModeState';
import { isSignInPrefilledState } from '@/client-config/states/isSignInPrefilledState';
import { AppPath } from '@/types/AppPath';
import { PageHotkeyScope } from '@/types/PageHotkeyScope';
import { useSnackBar } from '@/ui/snack-bar/hooks/useSnackBar';
Expand Down Expand Up @@ -45,7 +45,7 @@ export function useSignInUp() {
const { enqueueSnackBar } = useSnackBar();
const isMatchingLocation = useIsMatchingLocation();
const [authProviders] = useRecoilState(authProvidersState);
const isDemoMode = useRecoilValue(isDemoModeState);
const isSignInPrefilled = useRecoilValue(isSignInPrefilledState);
const workspaceInviteHash = useParams().workspaceInviteHash;
const [signInUpStep, setSignInUpStep] = useState<SignInUpStep>(
SignInUpStep.Init,
Expand All @@ -61,8 +61,8 @@ export function useSignInUp() {
mode: 'onChange',
defaultValues: {
exist: false,
email: isDemoMode ? '[email protected]' : '',
password: isDemoMode ? 'Applecar2025' : '',
email: isSignInPrefilled ? '[email protected]' : '',
password: isSignInPrefilled ? 'Applecar2025' : '',
},
resolver: yupResolver(validationSchema),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useRecoilState } from 'recoil';

import { authProvidersState } from '@/client-config/states/authProvidersState';
import { isDebugModeState } from '@/client-config/states/isDebugModeState';
import { isDemoModeState } from '@/client-config/states/isDemoModeState';
import { isSignInPrefilledState } from '@/client-config/states/isSignInPrefilledState';
import { telemetryState } from '@/client-config/states/telemetryState';
import { useGetClientConfigQuery } from '~/generated/graphql';

Expand All @@ -12,7 +12,7 @@ export const ClientConfigProvider: React.FC<React.PropsWithChildren> = ({
}) => {
const [, setAuthProviders] = useRecoilState(authProvidersState);
const [, setDebugMode] = useRecoilState(isDebugModeState);
const [, setDemoMode] = useRecoilState(isDemoModeState);
const [, setSignInPrefilled] = useRecoilState(isSignInPrefilledState);
const [, setTelemetry] = useRecoilState(telemetryState);
const [isLoading, setIsLoading] = useState(true);

Expand All @@ -29,14 +29,14 @@ export const ClientConfigProvider: React.FC<React.PropsWithChildren> = ({
magicLink: false,
});
setDebugMode(data?.clientConfig.debugMode);
setDemoMode(data?.clientConfig.demoMode);
setSignInPrefilled(data?.clientConfig.signInPrefilled);
setTelemetry(data?.clientConfig.telemetry);
}
}, [
data,
setAuthProviders,
setDebugMode,
setDemoMode,
setSignInPrefilled,
setTelemetry,
setIsLoading,
loading,
Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/client-config/queries/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const GET_CLIENT_CONFIG = gql`
google
password
}
demoMode
signInPrefilled
debugMode
telemetry {
enabled
Expand Down
6 changes: 0 additions & 6 deletions front/src/modules/client-config/states/isDemoModeState.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { atom } from 'recoil';

export const isSignInPrefilledState = atom<boolean>({
key: 'isSignInPrefilledState',
default: false,
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ export function getImageAbsoluteURIOrBase64(imageUrl?: string | null) {
return imageUrl;
}

return `${process.env.REACT_APP_FILES_URL}/${imageUrl}`;
const serverFilesUrl =
process.env.REACT_APP_SERVER_FILES_URL ??
process.env.REACT_APP_SERVER_BASE_URL + '/files';

return `${serverFilesUrl}/${imageUrl}`;
}
2 changes: 1 addition & 1 deletion front/src/testing/graphqlMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const graphqlMocks = [
return res(
ctx.data({
clientConfig: {
demoMode: true,
signInPrefilled: true,
debugMode: false,
authProviders: { google: true, password: true, magicLink: false },
telemetry: { enabled: false, anonymizationEnabled: true },
Expand Down
2 changes: 1 addition & 1 deletion front/src/testing/mockedClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApolloClient, InMemoryCache } from '@apollo/client';

export const mockedClient = new ApolloClient({
uri: process.env.REACT_APP_API_URL,
uri: process.env.REACT_APP_SERVER_BASE_URL + '/graphql',
cache: new InMemoryCache(),
});
7 changes: 4 additions & 3 deletions infra/prod/front/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM node:18.16.0-alpine as build

ARG REACT_APP_API_URL
ARG REACT_APP_AUTH_URL
ARG REACT_APP_FILES_URL

ARG REACT_APP_SERVER_BASE_URL
ARG REACT_APP_SERVER_AUTH_URL
ARG REACT_APP_SERVER_FILES_URL

COPY ./packages/ /app/packages

Expand Down
42 changes: 42 additions & 0 deletions render.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
services:
- type: web
name: front
env: docker
dockerfilePath: ./infra/prod/front/Dockerfile
autoDeploy: false
envVars:
- key: REACT_APP_SERVER_BASE_URL
fromService:
name: server
type: web
envVarKey: RENDER_EXTERNAL_URL
- type: web
name: server
env: docker
dockerfilePath: ./infra/prod/server/Dockerfile
dockerCommand: "sh -c yarn prisma:migrate && node dist/src/main"
autoDeploy: false
envVars:
- key: ACCESS_TOKEN_SECRET
generateValue: true
- key: LOGIN_TOKEN_SECRET
generateValue: true
- key: REFRESH_TOKEN_SECRET
generateValue: true
- key: PG_DATABASE_URL
fromDatabase:
name: twenty-db
property: connectionString
- key: FRONT_BASE_URL
fromService:
name: front
type: web
envVarKey: RENDER_EXTERNAL_URL
disk:
name: twenty-disk
mountPath: /.local-storage
sizeGB: 5

databases:
- name: twenty-db
plan: starter
Loading

0 comments on commit b028d9f

Please sign in to comment.