[Wip] Update CI CD (#2945)

* Update CI and CD scripts

* Fix docker docs build

* Fix CD

* Fix CD

* Update front build and add postgres intel pg_graphql files

* Fix postgres install

* Fix

* Update docs
This commit is contained in:
Charles Bochet
2023-12-12 22:38:40 +01:00
committed by GitHub
parent 6594055317
commit 2496431703
45 changed files with 389 additions and 451 deletions

View File

@ -1,11 +1,13 @@
dev-build:
@docker compose -f dev/docker-compose.yml down
@docker compose -f dev/docker-compose.yml down
rm -rf ../twenty-front/node_modules
rm -rf ../twenty-server/node_modules
rm -rf ../twenty-docs/node_modules
@docker volume rm twenty_node_modules_front > /dev/null 2>&1 || true
@docker volume rm twenty_node_modules_server > /dev/null 2>&1 || true
@docker volume rm twenty_node_modules_docs > /dev/null 2>&1 || true
@docker volume rm twenty_dev_node_modules_front > /dev/null 2>&1 || true
@docker volume rm twenty_dev_node_modules_server > /dev/null 2>&1 || true
@docker volume rm twenty_dev_node_modules_docs > /dev/null 2>&1 || true
@docker volume rm twenty_dev_node_modules_root > /dev/null 2>&1 || true
@docker volume rm twenty_dev_node_modules_yarn > /dev/null 2>&1 || true
@docker compose -f dev/docker-compose.yml build
dev-up:
@ -22,3 +24,59 @@ dev-postgres-build:
@docker rm twenty_postgres || true
@docker volume rm twenty_db_data || true
@docker compose -f dev/docker-compose.yml up --build postgres -d
prod-docs-build:
@cd ../.. && docker build -f ./packages/twenty-docker/prod/twenty-docs/Dockerfile --tag twenty-docs . && cd -
prod-docs-run:
@docker run -p 3000:3000 twenty-docs
prod-front-build:
@cd ../.. && docker build -f ./packages/twenty-docker/prod/twenty-front/Dockerfile --tag twenty-front . && cd -
prod-front-run:
@docker run -p 3000:3000 twenty-front
prod-server-build:
@cd ../.. && docker build -f ./packages/twenty-docker/prod/twenty-server/Dockerfile --tag twenty-server . && cd -
prod-server-run:
@docker run -p 3000:3000 twenty-server
prod-postgres-build:
@cd ../.. && docker build -f ./packages/twenty-docker/prod/twenty-postgres/Dockerfile --tag twenty-postgres . && cd -
prod-postgres-run:
@docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres twenty-postgres
release-front:
@cd ../.. && docker buildx build \
--push \
--no-cache \
--platform linux/amd64,linux/arm64 \
-f ./packages/twenty-docker/prod/twenty-front/Dockerfile -t twentycrm/twenty-front:$(version) -t twentycrm/twenty-front:latest . \
&& cd -
release-server:
@cd ../.. && docker buildx build \
--push \
--no-cache \
--platform linux/amd64,linux/arm64 \
-f ./packages/twenty-docker/prod/twenty-server/Dockerfile -t twentycrm/twenty-server:$(version) -t twentycrm/twenty-server:latest . \
&& cd -
release-docs:
@cd ../.. && docker buildx build \
--push \
--no-cache \
--platform linux/amd64,linux/arm64 \
-f ./packages/twenty-docker/prod/twenty-docs/Dockerfile -t twentycrm/twenty-docs:$(version) -t twentycrm/twenty-docs:latest . \
&& cd -
release-postgres:
@cd ../.. && docker buildx build \
--push \
--no-cache \
--platform linux/amd64,linux/arm64 \
-f ./packages/twenty-docker/prod/twenty-postgres/Dockerfile -t twentycrm/twenty-postgres:$(version) -t twentycrm/twenty-postgres:latest . \
&& cd -

View File

@ -1,18 +0,0 @@
FROM node:18.16.0-alpine as docs
WORKDIR /app/docs
ARG SHOULD_INDEX_DOC
COPY ./docs/package.json .
COPY ./docs/yarn.lock .
RUN yarn install
COPY ./docs .
RUN npm run build
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 documentation."
CMD ["serve", "-s", "./build"]

View File

@ -1,29 +0,0 @@
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

@ -1,10 +0,0 @@
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

@ -1,15 +0,0 @@
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 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

@ -18,25 +18,14 @@ services:
- twenty_dev_node_modules_server:/app/packages/twenty-server/node_modules
depends_on:
- postgres
twenty-docs:
build:
context: ../../..
dockerfile: ./packages/twenty-docker/dev/twenty-docs/Dockerfile
ports:
- "5001:5001"
volumes:
- ../../../packages/twenty-docs:/app/packages/twenty-docs
- twenty_docs_node_modules_root:/app/node_modules
- twenty_docs_node_modules_yarn:/app/.yarn
- twenty_docs_node_modules_docs:/app/packages/twenty-docs/node_modules
postgres:
container_name: twenty_postgres
build: ./postgres
image: twentycrm/twenty-postgres:latest
volumes:
- twenty_db_data:/var/lib/postgresql/data
environment:
- POSTGRES_USER=twenty
- POSTGRES_PASSWORD=twenty
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=default
ports:
- "5432:5432"
@ -47,6 +36,4 @@ volumes:
twenty_dev_node_modules_yarn:
twenty_dev_node_modules_front:
twenty_dev_node_modules_server:
twenty_docs_node_modules_root:
twenty_docs_node_modules_yarn:
twenty_docs_node_modules_docs:
twenty_dev_node_modules_docs:

View File

@ -1,35 +0,0 @@
ARG PG_MAIN_VERSION=15.5
FROM postgres:${PG_MAIN_VERSION}-bullseye as postgres
ARG PG_MAIN_VERSION=15
ARG PG_GRAPHQL_VERSION=1.4.2
ARG WRAPPERS_VERSION=0.2.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 curl -y
# 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
# Install precompiled supabase wrappers extensions
RUN curl -L "https://github.com/supabase/wrappers/releases/download/v${WRAPPERS_VERSION}/wrappers-v${WRAPPERS_VERSION}-pg${PG_MAIN_VERSION}-${TARGETARCH}-linux-gnu.deb" -o wrappers.deb
RUN dpkg --install wrappers.deb
COPY init.sql /docker-entrypoint-initdb.d/

View File

@ -1,10 +0,0 @@
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

@ -1,16 +1,14 @@
FROM node:18.16-bullseye as twenty-dev
WORKDIR /app
COPY ../../../../package.json .
COPY ../../../../yarn.lock .
COPY ../../../../.yarnrc.yml .
COPY ../../../../.yarn/releases /app/.yarn/releases
COPY ../../../packages/twenty-front/package.json /app/packages/twenty-front/package.json
COPY ../../../packages/twenty-server/package.json /app/packages/twenty-server/package.json
COPY ../../../packages/twenty-server/patches /app/packages/twenty-server/patches
COPY ../../../packages/eslint-plugin-twenty/package.json /app/packages/eslint-plugin-twenty/package.json
RUN yarn
COPY ./package.json .
COPY ./yarn.lock .
COPY ./.yarnrc.yml .
COPY ./.yarn/releases /app/.yarn/releases
COPY ./packages/twenty-front/package.json /app/packages/twenty-front/package.json
COPY ./packages/twenty-server/package.json /app/packages/twenty-server/package.json
COPY ./packages/twenty-server/patches /app/packages/twenty-server/patches
COPY ./packages/eslint-plugin-twenty/package.json /app/packages/eslint-plugin-twenty/package.json
RUN npx playwright install-deps

View File

@ -1,15 +0,0 @@
FROM node:18.16-bullseye as twenty-docs
WORKDIR /app
COPY ../../../../package.json .
COPY ../../../../yarn.lock .
COPY ../../../../.yarnrc.yml .
COPY ../../../../.yarn/releases /app/.yarn/releases
COPY ../../../packages/twenty-docs/package.json /app/packages/twenty-docs/package.json
RUN yarn
WORKDIR /app/packages/twenty-docs
CMD ["tail", "-f", "/dev/null"]

View File

@ -1,3 +0,0 @@
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,30 +0,0 @@
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

@ -1,10 +0,0 @@
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

@ -1,3 +0,0 @@
FROM --platform=linux/amd64 twentycrm/twenty-server as server
CMD ["node", "dist/src/main"]

View File

@ -0,0 +1,30 @@
FROM node:18.16.0-alpine as twenty-docs-build
WORKDIR /app
ARG SHOULD_INDEX_DOC
COPY ./package.json .
COPY ./yarn.lock .
COPY ./.yarnrc.yml .
COPY ./.yarn/releases /app/.yarn/releases
COPY ./packages/twenty-docs/package.json /app/packages/twenty-docs/package.json
RUN yarn
COPY ./packages/twenty-docs /app/packages/twenty-docs
RUN yarn nx build twenty-docs
CMD ["tail", "-f", "/dev/null"]
FROM node:18.16.0-alpine as twenty-docs
WORKDIR /app/packages/twenty-docs
COPY --from=twenty-docs-build /app/packages/twenty-docs/build ./build
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 documentation."
CMD ["serve", "-s", "./build"]

View File

@ -0,0 +1,32 @@
FROM node:18.16.0-alpine as twenty-front-build
ARG REACT_APP_SERVER_BASE_URL
ARG REACT_APP_SERVER_AUTH_URL
ARG REACT_APP_SERVER_FILES_URL
WORKDIR /app
COPY ./package.json .
COPY ./yarn.lock .
COPY ./.yarnrc.yml .
COPY ./.yarn/releases /app/.yarn/releases
COPY ./packages/eslint-plugin-twenty /app/packages/eslint-plugin-twenty
COPY ./packages/twenty-front /app/packages/twenty-front
RUN yarn
RUN yarn nx build twenty-front
COPY ./packages/twenty-docker/prod/twenty-front/serve.json ./build
FROM node:18.16.0-alpine as twenty-front
WORKDIR /app/packages/twenty-front
COPY --from=twenty-front-build /app/packages/twenty-front/build ./build
COPY ./packages/twenty-front/scripts/inject-runtime-env.sh /app/packages/twenty-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", "./scripts/inject-runtime-env.sh && serve build"]

View File

@ -38,8 +38,8 @@ RUN dpkg --install wrappers.deb
RUN cp /usr/share/postgresql/${PG_MAIN_VERSION}/extension/wrappers* /opt/bitnami/postgresql/share/extension/
RUN cp /usr/lib/postgresql/${PG_MAIN_VERSION}/lib/wrappers* /opt/bitnami/postgresql/lib/
COPY ./infra/build/postgres/init.sql /docker-entrypoint-initdb.d/
COPY ./packages/twenty-docker/prod/twenty-postgres/init.sql /docker-entrypoint-initdb.d/
USER 1001
ENTRYPOINT [ "/opt/bitnami/scripts/postgresql/entrypoint.sh" ]
CMD [ "/opt/bitnami/scripts/postgresql/run.sh" ]
ENTRYPOINT ["/opt/bitnami/scripts/postgresql/entrypoint.sh"]
CMD ["/opt/bitnami/scripts/postgresql/run.sh"]

View File

@ -0,0 +1,4 @@
CREATE DATABASE "default";
CREATE DATABASE "test";
CREATE USER twenty PASSWORD 'twenty';
ALTER ROLE twenty superuser;

View File

@ -0,0 +1,21 @@
FROM node:18.16.0-alpine as twenty-server
WORKDIR /app
COPY ./package.json .
COPY ./yarn.lock .
COPY ./.yarnrc.yml .
COPY ./.yarn/releases /app/.yarn/releases
COPY ./packages/eslint-plugin-twenty /app/packages/eslint-plugin-twenty
COPY ./packages/twenty-server /app/packages/twenty-server
RUN yarn
RUN yarn
RUN yarn nx build twenty-server
WORKDIR /app/packages/twenty-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."
CMD ["node", "dist/src/main"]