Skip to content

The open alternative to Salesforce, designed for AI.

Build render (#2188)

Charles Bochet42af74eb46c8
diff --git a/front/src/modules/favorites/components/Favorites.tsx b/front/src/modules/favorites/components/Favorites.tsx
index 91f3ed2546c..971c4375015 100644
--- a/front/src/modules/favorites/components/Favorites.tsx
+++ b/front/src/modules/favorites/components/Favorites.tsx
@@ -60,7 +60,7 @@ export const Favorites = () => {
draggableItems={
<>
{favorites.map((favorite, index) => {
- const { id, person, company } = favorite;
+ const { id, person, company, position } = favorite;
return (
<DraggableItem
key={id}
@@ -68,6 +68,7 @@ export const Favorites = () => {
index={index}
itemComponent={
<>
+ {position}
{person && (
<NavItem
key={id}
diff --git a/front/src/modules/favorites/hooks/useFavorites.ts b/front/src/modules/favorites/hooks/useFavorites.ts
index 42fa2369bb0..7fee499fd37 100644
--- a/front/src/modules/favorites/hooks/useFavorites.ts
+++ b/front/src/modules/favorites/hooks/useFavorites.ts
@@ -110,7 +110,7 @@ export const useFavorites = () => {
}
if (destIndex === favorites.length - 1) {
- return favorites[destIndex].position + 1;
+ return favorites[destIndex - 1].position + 1;
}
if (sourceIndex < destIndex) {
diff --git a/infra/prod/docs/Dockerfile b/infra/build/docs/Dockerfile
similarity index 100%
rename from infra/prod/docs/Dockerfile
rename to infra/build/docs/Dockerfile
diff --git a/infra/build/front/Dockerfile b/infra/build/front/Dockerfile
new file mode 100644
index 00000000000..18e853d0bd4
--- /dev/null
+++ b/infra/build/front/Dockerfile
@@ -0,0 +1,29 @@
+FROM node:18.16.0-alpine as build
+
+ARG REACT_APP_SERVER_BASE_URL
+ARG REACT_APP_SERVER_AUTH_URL
+ARG REACT_APP_SERVER_FILES_URL
+
+COPY ./packages/ /app/packages
+
+WORKDIR /app/front
+COPY ./front .
+
+RUN yarn install
+RUN yarn build
+
+COPY ./infra/build/front/serve.json ./build
+
+FROM node:18.16.0-alpine as front
+
+WORKDIR /app/front
+
+COPY --from=build /app/front/build ./build
+COPY ./front/scripts/inject-runtime-env.sh /app/front/scripts/inject-runtime-env.sh
+
+RUN yarn global add serve
+
+LABEL org.opencontainers.image.source=https://github.com/twentyhq/twenty
+LABEL org.opencontainers.image.description="This image provides a consistent and reproducible environment for the frontend."
+
+CMD ["/bin/sh", "-c", "/app/front/scripts/inject-runtime-env.sh && serve build"]
diff --git a/infra/prod/front/serve.json b/infra/build/front/serve.json
similarity index 100%
rename from infra/prod/front/serve.json
rename to infra/build/front/serve.json
diff --git a/infra/build/postgres/Dockerfile b/infra/build/postgres/Dockerfile
new file mode 100644
index 00000000000..5f2865444ac
--- /dev/null
+++ b/infra/build/postgres/Dockerfile
@@ -0,0 +1,30 @@
+ARG PG_MAIN_VERSION=14
+
+FROM postgres:${PG_MAIN_VERSION} as postgres
+
+ARG PG_MAIN_VERSION
+ARG PG_GRAPHQL_VERSION=1.3.0
+ARG TARGETARCH
+
+RUN set -eux; \
+ ARCH="$(dpkg --print-architecture)"; \
+ case "${ARCH}" in \
+ aarch64|arm64) \
+ TARGETARCH='arm64'; \
+ ;; \
+ amd64|x86_64) \
+ TARGETARCH='amd64'; \
+ ;; \
+ *) \
+ echo "Unsupported arch: ${ARCH}"; \
+ exit 1; \
+ ;; \
+ esac;
+
+RUN apt update && apt install -y curl
+
+# Install precompiled pg_graphql extensions
+RUN curl -L "https://github.com/supabase/pg_graphql/releases/download/v${PG_GRAPHQL_VERSION}/pg_graphql-v${PG_GRAPHQL_VERSION}-pg${PG_MAIN_VERSION}-${TARGETARCH}-linux-gnu.deb" -o pg_graphql.deb
+RUN dpkg --install pg_graphql.deb
+
+COPY ./infra/prod/postgres/init.sql /docker-entrypoint-initdb.d/
\ No newline at end of file
diff --git a/infra/build/postgres/init.sql b/infra/build/postgres/init.sql
new file mode 100644
index 00000000000..5123e987ca9
--- /dev/null
+++ b/infra/build/postgres/init.sql
@@ -0,0 +1,10 @@
+SELECT 'CREATE DATABASE "default"'
+WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'default')\gexec
+
+SELECT 'CREATE DATABASE "test"'
+WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'test')\gexec
+
+SELECT 'CREATE USER twenty PASSWORD ''twenty'''
+WHERE NOT EXISTS (SELECT FROM pg_user WHERE usename = 'twenty')\gexec
+
+SELECT 'ALTER ROLE twenty superuser'\gexec
diff --git a/infra/build/server/Dockerfile b/infra/build/server/Dockerfile
new file mode 100644
index 00000000000..354183f28b8
--- /dev/null
+++ b/infra/build/server/Dockerfile
@@ -0,0 +1,17 @@
+FROM node:18.16.0-alpine as build
+
+WORKDIR /app/server
+COPY ./server/package.json ./
+COPY ./server/yarn.lock ./
+COPY ./server/patches ./patches
+RUN yarn install
+
+COPY ./server .
+RUN npx prisma generate
+
+RUN yarn build
+
+LABEL org.opencontainers.image.source=https://github.com/twentyhq/twenty
+LABEL org.opencontainers.image.description="This image provides a consistent and reproducible environment for the backend, ensuring it deploys faster and runs the same way regardless of the deployment environment."
+
+CMD ["node", "dist/src/main"]
diff --git a/infra/prod/front/Dockerfile b/infra/prod/front/Dockerfile
index 2b6c3e79880..3ec5bb0821a 100644
--- a/infra/prod/front/Dockerfile
+++ b/infra/prod/front/Dockerfile
@@ -1,29 +1,3 @@
-FROM node:18.16.0-alpine as build
-
-ARG REACT_APP_SERVER_BASE_URL
-ARG REACT_APP_SERVER_AUTH_URL
-ARG REACT_APP_SERVER_FILES_URL
-
-COPY ./packages/ /app/packages
-
-WORKDIR /app/front
-COPY ./front .
-
-RUN yarn install
-RUN yarn build
-
-COPY ./infra/prod/front/serve.json ./build
-
-FROM node:18.16.0-alpine as front
-
-WORKDIR /app/front
-
-COPY --from=build /app/front/build ./build
-COPY ./front/scripts/inject-runtime-env.sh /app/front/scripts/inject-runtime-env.sh
-
-RUN yarn global add serve
-
-LABEL org.opencontainers.image.source=https://github.com/twentyhq/twenty
-LABEL org.opencontainers.image.description="This image provides a consistent and reproducible environment for the frontend."
+FROM --platform=linux/amd64 twentycrm/twenty-front as front
CMD ["/bin/sh", "-c", "/app/front/scripts/inject-runtime-env.sh && serve build"]
diff --git a/infra/prod/server/Dockerfile b/infra/prod/server/Dockerfile
index f7fba86aa67..aedf00c1cd7 100644
--- a/infra/prod/server/Dockerfile
+++ b/infra/prod/server/Dockerfile
@@ -1,23 +1,3 @@
-FROM node:18.16.0-alpine as build
-
-WORKDIR /app/server
-COPY ./server/package.json ./
-COPY ./server/yarn.lock ./
-COPY ./server/patches ./patches
-RUN yarn install
-
-COPY ./server .
-RUN npx prisma generate
-
-RUN yarn build
-
-FROM node:18.16.0-alpine as server
-
-COPY --from=build /app/server/dist ./dist
-
-WORKDIR /app/server
-
-LABEL org.opencontainers.image.source=https://github.com/twentyhq/twenty
-LABEL org.opencontainers.image.description="This image provides a consistent and reproducible environment for the backend, ensuring it deploys faster and runs the same way regardless of the deployment environment."
+FROM --platform=linux/amd64 twentycrm/twenty-server as server
CMD ["node", "dist/src/main"]
diff --git a/infra/release/build-front.sh b/infra/release/build-front.sh
new file mode 100755
index 00000000000..66c4bf8652b
--- /dev/null
+++ b/infra/release/build-front.sh
@@ -0,0 +1,5 @@
+
+docker buildx build \
+--push \
+--platform linux/amd64,linux/arm64 \
+-f ./infra/build/front/Dockerfile -t twentycrm/twenty-front:0.1.5 -t twentycrm/twenty-front:latest .
diff --git a/infra/release/build-server.sh b/infra/release/build-server.sh
new file mode 100755
index 00000000000..2705f1cc290
--- /dev/null
+++ b/infra/release/build-server.sh
@@ -0,0 +1,5 @@
+
+docker buildx build \
+--push \
+--platform linux/amd64,linux/arm64 \
+-f ./infra/build/server/Dockerfile -t twentycrm/twenty-server:0.1.5 -t twentycrm/twenty-server:latest .
\ No newline at end of file
diff --git a/render.yaml b/render.yaml
index e028d983b0c..7f2f48b4f96 100644
--- a/render.yaml
+++ b/render.yaml
@@ -14,7 +14,7 @@ services:
name: server
env: docker
dockerfilePath: ./infra/prod/server/Dockerfile
- dockerCommand: "sh -c ./scripts/compute-database-url.sh && yarn prisma:migrate && yarn database:setup && node dist/src/main"
+ dockerCommand: "sh -c ./scripts/render-run.sh"
autoDeploy: false
envVars:
- key: FRONT_BASE_URL
diff --git a/server/scripts/compute-database-url.sh b/server/scripts/compute-database-url.sh
deleted file mode 100755
index 13cc38149dd..00000000000
--- a/server/scripts/compute-database-url.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-export PG_DATABASE_URL=postgres://twenty:twenty@$PG_DATABASE_HOST:$PG_DATABASE_PORT/default
\ No newline at end of file
diff --git a/server/scripts/render-run.sh b/server/scripts/render-run.sh
new file mode 100755
index 00000000000..4899ace777b
--- /dev/null
+++ b/server/scripts/render-run.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+export PG_DATABASE_URL=postgres://twenty:twenty@$PG_DATABASE_HOST:$PG_DATABASE_PORT/default
+yarn prisma:migrate
+yarn database:setup
+node dist/src/main
\ No newline at end of file