Skip to content

Commit

Permalink
Simplify infrastructure to one container
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Bochet committed Mar 6, 2023
1 parent 2ddb191 commit c2833ca
Show file tree
Hide file tree
Showing 61 changed files with 2,211 additions and 1,992 deletions.
117 changes: 16 additions & 101 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ orbs:
slack: circleci/slack@4.12.0
node: circleci/node@5.0.3

parameters:
build-api:
type: boolean
default: false

jobs:
tests-server:
tests-front:
executor: node/default
steps:
- checkout
Expand All @@ -22,67 +17,51 @@ jobs:
- run:
command: cd front && npm run test
name: tests
deploy-api-canary:
docker:
- image: hasura/graphql-engine:latest.cli-migrations-v3
steps:
- checkout
- run: cd api && /bin/hasura-cli deploy --admin-secret $HASURA_ADMIN_SECRET --endpoint $HASURA_CANARY_ENDPOINT
deploy-api:
docker:
- image: hasura/graphql-engine:latest.cli-migrations-v3
steps:
- checkout
- run: cd api && /bin/hasura-cli metadata apply --admin-secret $HASURA_ADMIN_SECRET --endpoint $HASURA_ENDPOINT

workflows:
build-and-deploy-server:
build-and-deploy:
jobs:
- tests-server
- tests-front
- aws-ecr/build-and-push-image:
name: build-image-server
name: build-image
filters:
branches:
only: main
requires:
- tests-server
dockerfile: ./infra/prod/twenty-server/Dockerfile
- tests-front
dockerfile: ./infra/prod/twenty/Dockerfile
registry-id: AWS_ACCOUNT_ID
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
region: $AWS_REGION
repo: $AWS_ECR_REPO
tag: $CIRCLE_SHA1
extra-build-args: >
--build-arg REACT_APP_AUTH0_DOMAIN=$REACT_APP_AUTH0_DOMAIN
--build-arg REACT_APP_AUTH0_CLIENT_ID=$REACT_APP_AUTH0_CLIENT_ID
--build-arg REACT_APP_AUTH0_CALLBACK_URL=$REACT_APP_AUTH0_CALLBACK_URL
--build-arg REACT_APP_AUTH0_AUDIENCE=$REACT_APP_AUTH0_AUDIENCE
--build-arg REACT_APP_API_URL=$REACT_APP_API_URL
- aws-ecs/deploy-service-update:
name: deploy-server-canary
name: deploy-canary
requires:
- build-image-server
family: $AWS_ECS_CONTAINER_NAME_SERVER_CANARY
- build-image
family: $AWS_ECS_CONTAINER_NAME_CANARY
cluster: $AWS_ECS_CLUSTER
container-image-name-updates: "container=$AWS_ECS_CONTAINER_NAME_SERVER_CANARY,tag=${CIRCLE_SHA1}"
container-image-name-updates: "container=$AWS_ECS_CONTAINER_NAME_CANARY,tag=${CIRCLE_SHA1}"
- slack/on-hold:
name: slack-notification
context: slack-secrets
requires:
- deploy-server-canary
- deploy-canary
- hold:
type: approval
requires:
- slack-notification
- aws-ecs/deploy-service-update:
name: deploy-server-default
name: deploy-default
requires:
- hold
family: $AWS_ECS_CONTAINER_NAME_SERVER_DEFAULT
family: $AWS_ECS_CONTAINER_NAME_DEFAULT
cluster: $AWS_ECS_CLUSTER
container-image-name-updates: "container=$AWS_ECS_CONTAINER_NAME_SERVER_DEFAULT,tag=${CIRCLE_SHA1}"
container-image-name-updates: "container=$AWS_ECS_CONTAINER_NAME_DEFAULT,tag=${CIRCLE_SHA1}"
post-steps:
- slack/notify:
event: pass
Expand All @@ -93,77 +72,13 @@ workflows:
- aws-ecr/build-and-push-image:
name: build-image-latest
requires:
- deploy-server-default
dockerfile: ./infra/prod/twenty-server/Dockerfile
- deploy-default
dockerfile: ./infra/prod/twenty/Dockerfile
registry-id: AWS_ACCOUNT_ID
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
region: $AWS_REGION
repo: $AWS_ECR_REPO
tag: latest
extra-build-args: >
--build-arg REACT_APP_AUTH0_DOMAIN=$REACT_APP_AUTH0_DOMAIN
--build-arg REACT_APP_AUTH0_CLIENT_ID=$REACT_APP_AUTH0_CLIENT_ID
--build-arg REACT_APP_AUTH0_CALLBACK_URL=$REACT_APP_AUTH0_CALLBACK_URL
--build-arg REACT_APP_AUTH0_AUDIENCE=$REACT_APP_AUTH0_AUDIENCE
--build-arg REACT_APP_API_URL=$REACT_APP_API_URL
deploy-api:
jobs:
- deploy-api-canary:
filters:
branches:
only: main
- slack/on-hold:
name: slack-notification
context: slack-secrets
requires:
- deploy-api-canary
- hold:
type: approval
requires:
- slack-notification
- deploy-api:
requires:
- hold
build-api:
when: << pipeline.parameters.build-api >>
jobs:
- aws-ecr/build-and-push-image:
name: build-image-api
dockerfile: ./infra/prod/twenty-api/Dockerfile
registry-id: AWS_ACCOUNT_ID
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
region: $AWS_REGION
repo: $AWS_ECR_REPO_API
tag: $CIRCLE_SHA1
- aws-ecs/deploy-service-update:
name: deploy-api-canary
requires:
- build-image-api
family: $AWS_ECS_CONTAINER_NAME_API_CANARY
cluster: $AWS_ECS_CLUSTER
container-image-name-updates: "container=$AWS_ECS_CONTAINER_NAME_API_CANARY,tag=${CIRCLE_SHA1}"
- hold:
type: approval
requires:
- deploy-api-canary
- aws-ecs/deploy-service-update:
name: deploy-api-default
requires:
- hold
family: $AWS_ECS_CONTAINER_NAME_API_DEFAULT
cluster: $AWS_ECS_CLUSTER
container-image-name-updates: "container=$AWS_ECS_CONTAINER_NAME_API_DEFAULT,tag=${CIRCLE_SHA1}"
- aws-ecr/build-and-push-image:
name: build-image-api-latest
requires:
- deploy-api-default
dockerfile: ./infra/prod/twenty-api/Dockerfile
registry-id: AWS_ACCOUNT_ID
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
region: $AWS_REGION
repo: $AWS_ECR_REPO_API
tag: latest
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/*
**/**/.env
.DS_Store
.DS_Store
node_modules/**/**
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

83 changes: 28 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@ Welcome to Twenty documentation!

## High Level Overview

Twenty development stack is composed of 5 different layers:
- twenty-front: our frontend React app
- twenty-api (Hasura): our backend presentation layer that can do straight forward CRUDs, permissionning, authentication.
- twenty-server: our backend that contain complex logics, scripts, jobs...
- [tbd] twenty-events (Jitsu): our event ingestor which is separated from api and server to ensure high availability
- storages: postgres, [tbd] elasticsearch, [tbd] redis.
Twenty development stack is composed of 3 different layers
- front: our frontend React app
- server: our backend that contain endpoint, crm logic, scripts, jobs...
- storages: postgres

## Development environment setup
## Development environment setup with npm (Alternative 1)

This section only discusses the development setup. The whole developemnt environment is containerized with Docker and orchestrated with docker-compose.
This is the easiest way to get started contributing to twenty
Make sure you have `node@18` installed on your machine. You can use `nvm` to manage your nvm versions in case you have projects that require different node versions.

`npm install`
`npm start`

You'll need to provide your own postgres storage.

Once this is completed you should have:
- front available on: http://localhost:3001
- server available on: http://localhost:3000/health


## Development environment setup with docker-compose (Alternative 2)

We also provide a containerized environment with Docker and orchestrated with docker-compose in case it is easier for you. This install will also provision a postgres container out of the box.

### Step 1: pre-requesites
Make sure to have the latest Docker and Docker-compose versions installed on your computer.
Expand All @@ -31,10 +44,9 @@ docker-compose up --build --force-recreate
```

Once this is completed you should have:
- twenty-front available on: http://localhost:3001
- twenty-api available on: http://localhost:8080
- twenty-server available on: http://localhost:3000/health
- postgres: available on http://localhost:5432 that should contain two database: twenty (data) and hasura (metadata)
- front available on: http://localhost:3001
- server available on: http://localhost:3000/health
- postgres: available on http://localhost:5432 that should contain `twenty` database

### Step 3: environment file
Configure your environment by copying the `.env.example` file located in `infra/dev` folder into `.env`.
Expand All @@ -44,34 +56,16 @@ cp infra/dev/.env.example infra/dev/.env

Then, you'll need to replace all REPLACE_ME variable by their development value. Please reach out to another engineer to get these values (as most of them are third party credentials, sensitive data)

### Step 4: API (Hasura) metadata
Browse Hasura console on http://localhost:8080, go to settings and import metadata file located in `infra/dev/twenty-api` folder

## Developping on Frontend
### Note

The whole development experience is happening in `infra/dev` folder.
```
cd infra/dev
```

The development FE server is running on docker up and is exposing the `twenty-front` on port http://localhost:3001. As you modify the `/front` folder on your computer, this folder is synced with your `twenty-front` container and the frontend application is automatically refreshed.
If you are using Docker install, make sure to ssh in the docker container during development to execute commands. You can also use `Makefile` to help you

### Develop

Recommended: as you modify frontend code, here is how to access `twenty-front` server logs in order to debug / watch typescript issues:
```
make up
make logs container=twenty-front
```

### Open a shell into the container
```
make front-sh
```
## Development

### Tests

#### Unit tests:

```
make front-test
# coverage
Expand All @@ -83,27 +77,6 @@ make front-coverage
make front-storybook
```

## Developping on API

The whole development experience is happening in `infra/dev` folder.
```
cd infra/dev
```

The API is a Hasura instance which is a no-code container.
To modify API behavior, you'll need to connect to run Hasura console through the CLI
```
make api-console
```

Once your local changes in the console are finished you can export them into the filesystem (in order to version them, and deploy them to other environments), depending on your needs:

```
make api-make-migration name=my_migration_name
make api-make-metadata
make api-make-seeds
```

## Developping on server

Section TBD
6 changes: 0 additions & 6 deletions api/config.yaml

This file was deleted.

Empty file removed api/metadata/actions.graphql
Empty file.
6 changes: 0 additions & 6 deletions api/metadata/actions.yaml

This file was deleted.

1 change: 0 additions & 1 deletion api/metadata/allow_list.yaml

This file was deleted.

1 change: 0 additions & 1 deletion api/metadata/api_limits.yaml

This file was deleted.

1 change: 0 additions & 1 deletion api/metadata/backend_configs.yaml

This file was deleted.

1 change: 0 additions & 1 deletion api/metadata/cron_triggers.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions api/metadata/databases/databases.yaml

This file was deleted.

31 changes: 0 additions & 31 deletions api/metadata/databases/twenty/tables/public_tenants.yaml

This file was deleted.

Loading

0 comments on commit c2833ca

Please sign in to comment.