diff --git a/.circleci/config.yml b/.circleci/config.yml index 57d1d00915..99ebc88031 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,12 +23,13 @@ workflows: jobs: - tests - aws-ecr/build-and-push-image: + name: build-image filters: branches: only: main requires: - tests - dockerfile: Dockerfile + dockerfile: ./infra/prod/Dockerfile registry-id: AWS_ACCOUNT_ID aws-access-key-id: AWS_ACCESS_KEY_ID aws-secret-access-key: AWS_SECRET_ACCESS_KEY @@ -38,7 +39,7 @@ workflows: - aws-ecs/deploy-service-update: name: deploy-canary requires: - - aws-ecr/build-and-push-image + - build-image family: $AWS_ECS_CONTAINER_NAME_CANARY cluster: $AWS_ECS_CLUSTER container-image-name-updates: "container=$AWS_ECS_CONTAINER_NAME_CANARY,tag=${CIRCLE_SHA1}" @@ -64,4 +65,15 @@ workflows: template: basic_success_1 - slack/notify: event: fail - template: basic_fail_1 \ No newline at end of file + template: basic_fail_1 + - aws-ecr/build-and-push-image: + name: build-image-latest + requires: + - deploy-prod + dockerfile: ./infra/prod/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 diff --git a/README.md b/README.md index 206ad965bb..5246345cda 100644 --- a/README.md +++ b/README.md @@ -4,40 +4,34 @@ Welcome to Twenty! ## Setup & Development -### Frontend - ``` -cd front && npm install -npm run start +docker-compose -f infra/dev/docker-compose.yml up --build --force-recreate ``` -Browse: `localhost:3000` - -### Backend - -``` -cd server && npm install -npm run start:dev -``` - -Browse: `localhost:5000` +Browse: +- FE/BE: localhost:3000 +- Hasura: localhost:8080 ## Tests +Ssh into the twenty-server container using: +- `docker ps` to get the container id +- `docker exec -it CONTAINER_ID sh` + ### Frontend ``` +cd front npm run test ``` ### Backend ``` +cd server npm run test ``` -Browse: `localhost:5000` - ## Production ``` diff --git a/buildspec.yml b/buildspec.yml deleted file mode 100644 index 63eb6fbf07..0000000000 --- a/buildspec.yml +++ /dev/null @@ -1,24 +0,0 @@ -version: 0.2 - -phases: - pre_build: - commands: - - echo Logging in to Amazon ECR... - - aws ecr get-login-password --region eu-west-3 | docker login --username AWS --password-stdin 255840220362.dkr.ecr.eu-west-3.amazonaws.com - build: - commands: - - echo Build started on `date` - - docker build -t twenty-pilot . - - docker tag twenty-pilot 255840220362.dkr.ecr.eu-west-3.amazonaws.com/twenty-pilot:latest - - cd $CODEBUILD_SRC_DIR - post_build: - commands: - - echo Build completed on `date` - - echo Pushing the Docker images... - - docker push 255840220362.dkr.ecr.eu-west-3.amazonaws.com/twenty-pilot:latest - - echo Writing image definitions file... - - printf '{"AWSEBDockerrunVersion":"1","Image":{"Name":"%s","Update":"true"},"Ports":[{"ContainerPort":3000,"HostPort":80}]}' 255840220362.dkr.ecr.eu-west-3.amazonaws.com/twenty-pilot:latest > Dockerrun.aws.json - - cat Dockerrun.aws.json - -artifacts: - files: Dockerrun.aws.json diff --git a/infra/dev/docker-compose.yml b/infra/dev/docker-compose.yml new file mode 100644 index 0000000000..6fe72880d3 --- /dev/null +++ b/infra/dev/docker-compose.yml @@ -0,0 +1,33 @@ +version: "3.9" +services: + twenty-server: + build: + context: ../.. + dockerfile: ./infra/dev/twenty-server/Dockerfile + ports: + - "3000:3000" + depends_on: + - postgres + twenty-api: + image: hasura/graphql-engine:latest + ports: + - "8080:8080" + depends_on: + - "postgres" + restart: always + environment: + HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/hasura + PG_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/twenty + HASURA_GRAPHQL_ENABLE_CONSOLE: "true" + HASURA_GRAPHQL_DEV_MODE: "true" + HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log + postgres: + build: ./postgres + volumes: + - db_data:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: postgrespassword + ports: + - "5432:5432" +volumes: + db_data: \ No newline at end of file diff --git a/infra/dev/postgres/Dockerfile b/infra/dev/postgres/Dockerfile new file mode 100644 index 0000000000..0a2f10315f --- /dev/null +++ b/infra/dev/postgres/Dockerfile @@ -0,0 +1,3 @@ +FROM postgres:13.7 as postgres + +COPY init.sql /docker-entrypoint-initdb.d/ \ No newline at end of file diff --git a/infra/dev/postgres/init.sql b/infra/dev/postgres/init.sql new file mode 100644 index 0000000000..30a091e626 --- /dev/null +++ b/infra/dev/postgres/init.sql @@ -0,0 +1,2 @@ +CREATE DATABASE twenty; +CREATE DATABASE hasura; \ No newline at end of file diff --git a/infra/dev/twenty-server/Dockerfile b/infra/dev/twenty-server/Dockerfile new file mode 100644 index 0000000000..18e6c0d315 --- /dev/null +++ b/infra/dev/twenty-server/Dockerfile @@ -0,0 +1,14 @@ +FROM node:18-alpine as app + +WORKDIR /app +COPY ../.. . + +WORKDIR /app/front +RUN npm install +RUN npm run build + +WORKDIR /app/server +RUN npm install +RUN npm run build + +CMD ["npm", "run", "start:prod"] diff --git a/Dockerfile b/infra/prod/Dockerfile similarity index 100% rename from Dockerfile rename to infra/prod/Dockerfile