Build render (#2188)

* Build for arm and amd

* Add scripts

* Add scripts
This commit is contained in:
Charles Bochet 2023-10-22 23:47:43 +02:00 committed by GitHub
parent e67b2d23ae
commit 42af74eb46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 107 additions and 53 deletions

View File

@ -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}

View File

@ -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) {

View File

@ -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"]

View File

@ -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/

View File

@ -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

View File

@ -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"]

View File

@ -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"]

View File

@ -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"]

5
infra/release/build-front.sh Executable file
View File

@ -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 .

5
infra/release/build-server.sh Executable file
View File

@ -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 .

View File

@ -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

View File

@ -1,2 +0,0 @@
#!/bin/sh
export PG_DATABASE_URL=postgres://twenty:twenty@$PG_DATABASE_HOST:$PG_DATABASE_PORT/default

5
server/scripts/render-run.sh Executable file
View File

@ -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