update
This commit is contained in:
+18
-5
@@ -1,14 +1,27 @@
|
||||
# Makefile for building Twenty CRM docker images.
|
||||
# Set the tag and/or target build platform using make command-line variables assignments.
|
||||
#
|
||||
# Optional make variables:
|
||||
# PLATFORM - defaults to 'linux/amd64'
|
||||
# TAG - defaults to 'latest'
|
||||
#
|
||||
# Example: make
|
||||
# Example: make PLATFORM=linux/aarch64 TAG=my-tag
|
||||
|
||||
PLATFORM ?= linux/amd64
|
||||
TAG ?= latest
|
||||
|
||||
prod-build:
|
||||
@cd ../.. && docker build -f ./packages/twenty-docker/twenty/Dockerfile --tag twenty . && cd -
|
||||
@cd ../.. && docker build -f ./packages/twenty-docker/twenty/Dockerfile --platform $(PLATFORM) --tag twenty:$(TAG) . && cd -
|
||||
|
||||
prod-run:
|
||||
@docker run -d -p 3000:3000 --name twenty twenty
|
||||
@docker run -d -p 3000:3000 --name twenty twenty:$(TAG)
|
||||
|
||||
prod-postgres-run:
|
||||
@docker run -d -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres --name twenty-postgres twenty-postgres
|
||||
@docker run -d -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres --name twenty-postgres twenty-postgres:$(TAG)
|
||||
|
||||
prod-website-build:
|
||||
@cd ../.. && docker build -f ./packages/twenty-docker/twenty-website/Dockerfile --tag twenty-website . && cd -
|
||||
@cd ../.. && docker build -f ./packages/twenty-docker/twenty-website/Dockerfile --platform $(PLATFORM) --tag twenty-website:$(TAG) . && cd -
|
||||
|
||||
prod-website-run:
|
||||
@docker run -d -p 3000:3000 --name twenty-website twenty-website
|
||||
@docker run -d -p 3000:3000 --name twenty-website twenty-website:$(TAG)
|
||||
|
||||
@@ -1,21 +1,10 @@
|
||||
name: twenty
|
||||
|
||||
services:
|
||||
change-vol-ownership:
|
||||
image: ubuntu
|
||||
user: root
|
||||
volumes:
|
||||
- server-local-data:/tmp/server-local-data
|
||||
- docker-data:/tmp/docker-data
|
||||
command: >
|
||||
bash -c " chown -R 1000:1000 /tmp/server-local-data && chown -R 1000:1000
|
||||
/tmp/docker-data"
|
||||
|
||||
server:
|
||||
image: twentycrm/twenty:${TAG:-latest}
|
||||
volumes:
|
||||
- server-local-data:/app/packages/twenty-server/${STORAGE_LOCAL_PATH:-.local-storage}
|
||||
- docker-data:/app/docker-data
|
||||
- server-local-data:/app/packages/twenty-server/.local-storage
|
||||
environment:
|
||||
NODE_PORT: 3000
|
||||
PG_DATABASE_URL: postgres://${PG_DATABASE_USER:-postgres}:${PG_DATABASE_PASSWORD:-postgres}@${PG_DATABASE_HOST:-db}:${PG_DATABASE_PORT:-5432}/default
|
||||
@@ -27,21 +16,45 @@ services:
|
||||
STORAGE_S3_NAME: ${STORAGE_S3_NAME}
|
||||
STORAGE_S3_ENDPOINT: ${STORAGE_S3_ENDPOINT}
|
||||
|
||||
APP_SECRET: ${APP_SECRET}
|
||||
APP_SECRET: ${APP_SECRET:-replace_me_with_a_random_string}
|
||||
# MESSAGING_PROVIDER_GMAIL_ENABLED: ${MESSAGING_PROVIDER_GMAIL_ENABLED}
|
||||
# CALENDAR_PROVIDER_GOOGLE_ENABLED: ${CALENDAR_PROVIDER_GOOGLE_ENABLED}
|
||||
# AUTH_GOOGLE_CLIENT_ID: ${AUTH_GOOGLE_CLIENT_ID}
|
||||
# AUTH_GOOGLE_CLIENT_SECRET: ${AUTH_GOOGLE_CLIENT_SECRET}
|
||||
# AUTH_GOOGLE_CALLBACK_URL: ${AUTH_GOOGLE_CALLBACK_URL}
|
||||
# AUTH_GOOGLE_APIS_CALLBACK_URL: ${AUTH_GOOGLE_APIS_CALLBACK_URL}
|
||||
|
||||
# CALENDAR_PROVIDER_MICROSOFT_ENABLED: ${CALENDAR_PROVIDER_MICROSOFT_ENABLED}
|
||||
# MESSAGING_PROVIDER_MICROSOFT_ENABLED: ${MESSAGING_PROVIDER_MICROSOFT_ENABLED}
|
||||
# AUTH_MICROSOFT_ENABLED: ${AUTH_MICROSOFT_ENABLED}
|
||||
# AUTH_MICROSOFT_CLIENT_ID: ${AUTH_MICROSOFT_CLIENT_ID}
|
||||
# AUTH_MICROSOFT_CLIENT_SECRET: ${AUTH_MICROSOFT_CLIENT_SECRET}
|
||||
# AUTH_MICROSOFT_CALLBACK_URL: ${AUTH_MICROSOFT_CALLBACK_URL}
|
||||
# AUTH_MICROSOFT_APIS_CALLBACK_URL: ${AUTH_MICROSOFT_APIS_CALLBACK_URL}
|
||||
|
||||
# EMAIL_FROM_ADDRESS: ${EMAIL_FROM_ADDRESS:-contact@yourdomain.com}
|
||||
# EMAIL_FROM_NAME: ${EMAIL_FROM_NAME:-"John from YourDomain"}
|
||||
# EMAIL_SYSTEM_ADDRESS: ${EMAIL_SYSTEM_ADDRESS:-system@yourdomain.com}
|
||||
# EMAIL_DRIVER: ${EMAIL_DRIVER:-smtp}
|
||||
# EMAIL_SMTP_HOST: ${EMAIL_SMTP_HOST:-smtp.gmail.com}
|
||||
# EMAIL_SMTP_PORT: ${EMAIL_SMTP_PORT:-465}
|
||||
# EMAIL_SMTP_USER: ${EMAIL_SMTP_USER:-}
|
||||
# EMAIL_SMTP_PASSWORD: ${EMAIL_SMTP_PASSWORD:-}
|
||||
|
||||
depends_on:
|
||||
change-vol-ownership:
|
||||
condition: service_completed_successfully
|
||||
db:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
test: curl --fail http://localhost:3000/healthz
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
retries: 20
|
||||
restart: always
|
||||
|
||||
worker:
|
||||
image: twentycrm/twenty:${TAG:-latest}
|
||||
volumes:
|
||||
- server-local-data:/app/packages/twenty-server/${STORAGE_LOCAL_PATH:-.local-storage}
|
||||
command: [ "yarn", "worker:prod" ]
|
||||
environment:
|
||||
PG_DATABASE_URL: postgres://${PG_DATABASE_USER:-postgres}:${PG_DATABASE_PASSWORD:-postgres}@${PG_DATABASE_HOST:-db}:${PG_DATABASE_PORT:-5432}/default
|
||||
@@ -54,7 +67,31 @@ services:
|
||||
STORAGE_S3_NAME: ${STORAGE_S3_NAME}
|
||||
STORAGE_S3_ENDPOINT: ${STORAGE_S3_ENDPOINT}
|
||||
|
||||
APP_SECRET: ${APP_SECRET}
|
||||
APP_SECRET: ${APP_SECRET:-replace_me_with_a_random_string}
|
||||
# MESSAGING_PROVIDER_GMAIL_ENABLED: ${MESSAGING_PROVIDER_GMAIL_ENABLED}
|
||||
# CALENDAR_PROVIDER_GOOGLE_ENABLED: ${CALENDAR_PROVIDER_GOOGLE_ENABLED}
|
||||
# AUTH_GOOGLE_CLIENT_ID: ${AUTH_GOOGLE_CLIENT_ID}
|
||||
# AUTH_GOOGLE_CLIENT_SECRET: ${AUTH_GOOGLE_CLIENT_SECRET}
|
||||
# AUTH_GOOGLE_CALLBACK_URL: ${AUTH_GOOGLE_CALLBACK_URL}
|
||||
# AUTH_GOOGLE_APIS_CALLBACK_URL: ${AUTH_GOOGLE_APIS_CALLBACK_URL}
|
||||
|
||||
# CALENDAR_PROVIDER_MICROSOFT_ENABLED: ${CALENDAR_PROVIDER_MICROSOFT_ENABLED}
|
||||
# MESSAGING_PROVIDER_MICROSOFT_ENABLED: ${MESSAGING_PROVIDER_MICROSOFT_ENABLED}
|
||||
# AUTH_MICROSOFT_ENABLED: ${AUTH_MICROSOFT_ENABLED}
|
||||
# AUTH_MICROSOFT_CLIENT_ID: ${AUTH_MICROSOFT_CLIENT_ID}
|
||||
# AUTH_MICROSOFT_CLIENT_SECRET: ${AUTH_MICROSOFT_CLIENT_SECRET}
|
||||
# AUTH_MICROSOFT_CALLBACK_URL: ${AUTH_MICROSOFT_CALLBACK_URL}
|
||||
# AUTH_MICROSOFT_APIS_CALLBACK_URL: ${AUTH_MICROSOFT_APIS_CALLBACK_URL}
|
||||
|
||||
# EMAIL_FROM_ADDRESS: ${EMAIL_FROM_ADDRESS:-contact@yourdomain.com}
|
||||
# EMAIL_FROM_NAME: ${EMAIL_FROM_NAME:-"John from YourDomain"}
|
||||
# EMAIL_SYSTEM_ADDRESS: ${EMAIL_SYSTEM_ADDRESS:-system@yourdomain.com}
|
||||
# EMAIL_DRIVER: ${EMAIL_DRIVER:-smtp}
|
||||
# EMAIL_SMTP_HOST: ${EMAIL_SMTP_HOST:-smtp.gmail.com}
|
||||
# EMAIL_SMTP_PORT: ${EMAIL_SMTP_PORT:-465}
|
||||
# EMAIL_SMTP_USER: ${EMAIL_SMTP_USER:-}
|
||||
# EMAIL_SMTP_PASSWORD: ${EMAIL_SMTP_PASSWORD:-}
|
||||
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
@@ -63,14 +100,12 @@ services:
|
||||
restart: always
|
||||
|
||||
db:
|
||||
image: twentycrm/twenty-postgres-spilo:${TAG:-latest}
|
||||
image: postgres:16
|
||||
volumes:
|
||||
- db-data:/home/postgres/pgdata
|
||||
- db-data:/var/lib/postgresql/data
|
||||
environment:
|
||||
PGUSER_SUPERUSER: ${PG_DATABASE_USER:-postgres}
|
||||
PGPASSWORD_SUPERUSER: ${PG_DATABASE_PASSWORD:-postgres}
|
||||
ALLOW_NOSSL: "true"
|
||||
SPILO_PROVIDER: "local"
|
||||
POSTGRES_USER: ${PG_DATABASE_USER:-postgres}
|
||||
POSTGRES_PASSWORD: ${PG_DATABASE_PASSWORD:-postgres}
|
||||
healthcheck:
|
||||
test: pg_isready -U ${PG_DATABASE_USER:-postgres} -h localhost -d postgres
|
||||
interval: 5s
|
||||
@@ -81,8 +116,8 @@ services:
|
||||
redis:
|
||||
image: redis
|
||||
restart: always
|
||||
command: [ "--maxmemory-policy", "noeviction" ]
|
||||
|
||||
volumes:
|
||||
docker-data:
|
||||
db-data:
|
||||
server-local-data:
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
# README
|
||||
DISCLAIMER: The k8s and podman deployments are not maintained by the core team.
|
||||
These files are provided and maintained by the community. Twenty core team
|
||||
maintains support for docker deployment.
|
||||
|
||||
## Overview
|
||||
|
||||
|
||||
@@ -25,9 +25,10 @@ spec:
|
||||
- name: redis
|
||||
image: redis/redis-stack-server:latest
|
||||
imagePullPolicy: Always
|
||||
args: ["--maxmemory-policy", "noeviction"]
|
||||
env:
|
||||
- name: PORT
|
||||
value: 6379
|
||||
value: "6379"
|
||||
ports:
|
||||
- containerPort: 6379
|
||||
name: redis
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
# How to deploy twenty on podman
|
||||
|
||||
DISCLAIMER: The k8s and podman deployments are not maintained by the core team.
|
||||
These files are provided and maintained by the community. Twenty core team
|
||||
maintains support for docker deployment.
|
||||
|
||||
|
||||
## How to use
|
||||
|
||||
1. Edit `.env` file. At the minimum set `POSTGRES_PASSWORD`, `SERVER_URL`, and `APP_SECRET`.
|
||||
2. Start twenty by running `podman-compose up -d`.
|
||||
|
||||
If you need to stop twenty, you can do so by running `podman-compose down`.
|
||||
|
||||
|
||||
### Install systemd service (optional)
|
||||
|
||||
If you want to install a systemd service to run twenty, you can use the provided systemd service.
|
||||
|
||||
Edit `twentycrm.service` and change these two variables:
|
||||
|
||||
|
||||
WorkingDirectory=/opt/apps/twenty
|
||||
EnvironmentFile=/opt/apps/twenty/.env
|
||||
|
||||
`WorkingDirectory` should be changed to the path in which `podman-compose.yml` is located.
|
||||
|
||||
`EnvironmentFile` should be changed to the path in which your `.env`file is located.
|
||||
|
||||
You can run the script `install-systemd-user-service` to install the systemd service under the current user.
|
||||
|
||||
|
||||
./install-systemd-user-service
|
||||
|
||||
Note: this script will enable the service and also start it. So it will assume that twenty is not currently running.
|
||||
If you started it previously, bring it down using:
|
||||
|
||||
podman-compose down
|
||||
|
||||
|
||||
|
||||
## Compatibility
|
||||
|
||||
These files should be compatible with podman 4.3+.
|
||||
|
||||
I have tested this on Debian GNU/Linux 12 (bookworm) and with the podman that is distributed with the official Debian stable mirrors (podman v4.3.1+ds1-8+deb12u1, podman-compose v1.0.3-3).
|
||||
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
mkdir -p ~/.config/systemd/user
|
||||
[ -f twentycrm.service ] || { echo "Error: twentycrm.service not found"; exit 1; }
|
||||
cp twentycrm.service ~/.config/systemd/user
|
||||
|
||||
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable twentycrm.service
|
||||
systemctl --user start twentycrm.service
|
||||
@@ -0,0 +1,71 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
if [ ! -f "$(dirname "$0")/.env" ]; then
|
||||
echo "Error: .env file not found"
|
||||
exit 1
|
||||
fi
|
||||
source "$(dirname "$0")/.env"
|
||||
|
||||
## steps to cleanup and start over from scratch - useful when testing
|
||||
#podman pod stop twenty-pod
|
||||
#podman pod rm twenty-pod
|
||||
#podman volume rm twenty-db-data twenty-server-data twenty-redis-data
|
||||
# end of cleanup
|
||||
|
||||
podman volume create twenty-db-data
|
||||
podman volume create twenty-server-data
|
||||
podman volume create twenty-redis-data
|
||||
|
||||
podman pod create --name twenty-pod -p 127.0.0.1:8080:3000
|
||||
|
||||
podman run -d --pod twenty-pod --name twenty-db \
|
||||
-e POSTGRES_DB=twenty \
|
||||
-e POSTGRES_USER=twenty \
|
||||
-e POSTGRES_PASSWORD="$POSTGRES_PASSWORD" \
|
||||
-v twenty-db-data:/var/lib/postgresql/data:Z \
|
||||
docker.io/library/postgres:16
|
||||
|
||||
podman run -d --pod twenty-pod --name twenty-redis \
|
||||
-v twenty-redis-data:/data:Z \
|
||||
docker.io/library/redis:latest
|
||||
|
||||
podman run -d --pod twenty-pod --name twenty-server \
|
||||
-e NODE_PORT=3000 \
|
||||
-e SERVER_URL="$SERVER_URL" \
|
||||
-e PG_DATABASE_URL="postgresql://twenty:$POSTGRES_PASSWORD@twenty-db:5432/twenty" \
|
||||
-e REDIS_URL="redis://twenty-redis:6379" \
|
||||
-e APP_SECRET="$APP_SECRET" \
|
||||
-e NODE_ENV=production \
|
||||
-e LOG_LEVEL=info \
|
||||
-v twenty-server-data:/app/docker-data:Z \
|
||||
docker.io/twentycrm/twenty:latest
|
||||
|
||||
podman run -d --pod twenty-pod --name twenty-worker \
|
||||
--init \
|
||||
-e SERVER_URL="$SERVER_URL" \
|
||||
-e PG_DATABASE_URL="postgresql://twenty:$POSTGRES_PASSWORD@twenty-db:5432/twenty" \
|
||||
-e REDIS_URL="redis://twenty-redis:6379" \
|
||||
-e APP_SECRET="$APP_SECRET" \
|
||||
-e DISABLE_DB_MIGRATIONS=true \
|
||||
-e NODE_ENV=production \
|
||||
-e LOG_LEVEL=info \
|
||||
-v twenty-server-data:/app/docker-data:Z \
|
||||
docker.io/twentycrm/twenty:latest \
|
||||
yarn worker:prod
|
||||
|
||||
# wait some time, check status
|
||||
sleep 30
|
||||
podman ps --pod -f name=twenty-pod
|
||||
|
||||
|
||||
mkdir -p ~/.config/systemd/user
|
||||
if [ ! -f "twentycrm.service" ]; then
|
||||
echo "Error: twentycrm.service file not found"
|
||||
exit 1
|
||||
fi
|
||||
cp twentycrm.service ~/.config/systemd/user
|
||||
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable twentycrm.service
|
||||
systemctl --user start twentycrm.service
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
db:
|
||||
container_name: twenty-db
|
||||
image: postgres:16
|
||||
environment:
|
||||
POSTGRES_DB: twenty
|
||||
POSTGRES_USER: twenty
|
||||
POSTGRES_PASSWORD: ${PG_DATABASE_PASSWORD}
|
||||
volumes:
|
||||
- twenty-db-data:/var/lib/postgresql/data:Z
|
||||
|
||||
redis:
|
||||
container_name: twenty-redis
|
||||
image: redis:latest
|
||||
command: ["--maxmemory-policy", "noeviction"]
|
||||
volumes:
|
||||
- twenty-redis-data:/data:Z
|
||||
|
||||
server:
|
||||
container_name: twenty-server
|
||||
image: twentycrm/twenty:latest
|
||||
environment:
|
||||
NODE_PORT: "3000"
|
||||
SERVER_URL: ${SERVER_URL}
|
||||
PG_DATABASE_URL: "postgresql://twenty:${PG_DATABASE_PASSWORD}@twenty-db:5432/twenty"
|
||||
REDIS_URL: "redis://twenty-redis:6379"
|
||||
APP_SECRET: ${APP_SECRET}
|
||||
NODE_ENV: production
|
||||
LOG_LEVEL: info
|
||||
volumes:
|
||||
- twenty-server-data:/app/docker-data:Z
|
||||
ports:
|
||||
- 127.0.0.1:8080:3000
|
||||
|
||||
worker:
|
||||
container_name: twenty-worker
|
||||
image: twentycrm/twenty:latest
|
||||
command: yarn worker:prod
|
||||
environment:
|
||||
SERVER_URL: ${SERVER_URL}
|
||||
PG_DATABASE_URL: "postgresql://twenty:${PG_DATABASE_PASSWORD}@twenty-db:5432/twenty"
|
||||
REDIS_URL: "redis://twenty-redis:6379"
|
||||
APP_SECRET: ${APP_SECRET}
|
||||
DISABLE_DB_MIGRATIONS: "true"
|
||||
NODE_ENV: production
|
||||
LOG_LEVEL: info
|
||||
volumes:
|
||||
- twenty-server-data:/app/docker-data:Z
|
||||
init: true
|
||||
|
||||
volumes:
|
||||
twenty-db-data:
|
||||
twenty-server-data:
|
||||
twenty-redis-data:
|
||||
@@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description=TwentyCRM Container Stack via Podman-Compose
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=/opt/apps/twenty
|
||||
EnvironmentFile=/opt/apps/twenty/.env
|
||||
ExecStart=/usr/bin/podman-compose -f podman-compose.yml up -d
|
||||
ExecStop=/usr/bin/podman-compose -f podman-compose.yml down
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
|
||||
@@ -8,10 +8,18 @@ COPY ./yarn.lock .
|
||||
COPY ./.yarnrc.yml .
|
||||
COPY ./.yarn/releases /app/.yarn/releases
|
||||
COPY ./tools/eslint-rules /app/tools/eslint-rules
|
||||
COPY ./packages/twenty-ui/package.json /app/packages/twenty-ui/
|
||||
COPY ./packages/twenty-shared/package.json /app/packages/twenty-shared/
|
||||
COPY ./packages/twenty-website/package.json /app/packages/twenty-website/package.json
|
||||
|
||||
RUN yarn
|
||||
|
||||
ENV KEYSTATIC_GITHUB_CLIENT_ID="<fake build value>"
|
||||
ENV KEYSTATIC_GITHUB_CLIENT_SECRET="<fake build value>"
|
||||
ENV KEYSTATIC_SECRET="<fake build value>"
|
||||
ENV NEXT_PUBLIC_KEYSTATIC_GITHUB_APP_SLUG="<fake build value>"
|
||||
|
||||
COPY ./packages/twenty-ui /app/packages/twenty-ui
|
||||
COPY ./packages/twenty-website /app/packages/twenty-website
|
||||
RUN npx nx build twenty-website
|
||||
|
||||
@@ -26,4 +34,9 @@ WORKDIR /app/packages/twenty-website
|
||||
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 website."
|
||||
|
||||
RUN chown -R 1000 /app
|
||||
|
||||
# Use non root user with uid 1000
|
||||
USER 1000
|
||||
|
||||
CMD ["/bin/sh", "-c", "npx nx start"]
|
||||
@@ -7,6 +7,7 @@ WORKDIR /app
|
||||
COPY ./package.json ./yarn.lock ./.yarnrc.yml ./tsconfig.base.json ./nx.json /app/
|
||||
COPY ./.yarn/releases /app/.yarn/releases
|
||||
|
||||
COPY ./.prettierrc /app/
|
||||
COPY ./packages/twenty-emails/package.json /app/packages/twenty-emails/
|
||||
COPY ./packages/twenty-server/package.json /app/packages/twenty-server/
|
||||
COPY ./packages/twenty-server/patches /app/packages/twenty-server/patches
|
||||
@@ -63,8 +64,9 @@ WORKDIR /app/packages/twenty-server
|
||||
|
||||
ARG REACT_APP_SERVER_BASE_URL
|
||||
ENV REACT_APP_SERVER_BASE_URL $REACT_APP_SERVER_BASE_URL
|
||||
ARG SENTRY_RELEASE
|
||||
ENV SENTRY_RELEASE $SENTRY_RELEASE
|
||||
|
||||
ARG APP_VERSION
|
||||
ENV APP_VERSION $APP_VERSION
|
||||
|
||||
# Copy built applications from previous stages
|
||||
COPY --chown=1000 --from=twenty-server-build /app /app
|
||||
@@ -75,8 +77,8 @@ COPY --chown=1000 --from=twenty-front-build /app/packages/twenty-front/build /ap
|
||||
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 and frontend, ensuring it deploys faster and runs the same way regardless of the deployment environment."
|
||||
|
||||
RUN mkdir /app/.local-storage
|
||||
RUN chown -R 1000 /app
|
||||
RUN mkdir -p /app/.local-storage /app/packages/twenty-server/.local-storage && \
|
||||
chown -R 1000:1000 /app
|
||||
|
||||
# Use non root user with uid 1000
|
||||
USER 1000
|
||||
|
||||
@@ -1,26 +1,33 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# Check if the initialization has already been done and that we enabled automatic migration
|
||||
if [ "${DISABLE_DB_MIGRATIONS}" != "true" ] && [ ! -f /app/docker-data/db_status ]; then
|
||||
echo "Running database setup and migrations..."
|
||||
setup_and_migrate_db() {
|
||||
if [ "${DISABLE_DB_MIGRATIONS}" = "true" ]; then
|
||||
echo "Database setup and migrations are disabled, skipping..."
|
||||
return
|
||||
fi
|
||||
|
||||
# Creating the database if it doesn't exist
|
||||
echo "Running database setup and migrations..."
|
||||
PGUSER=$(echo $PG_DATABASE_URL | awk -F '//' '{print $2}' | awk -F ':' '{print $1}')
|
||||
PGPASS=$(echo $PG_DATABASE_URL | awk -F ':' '{print $3}' | awk -F '@' '{print $1}')
|
||||
PGHOST=$(echo $PG_DATABASE_URL | awk -F '@' '{print $2}' | awk -F ':' '{print $1}')
|
||||
PGPORT=$(echo $PG_DATABASE_URL | awk -F ':' '{print $4}' | awk -F '/' '{print $1}')
|
||||
PGPASSWORD=${PGPASS} psql -h ${PGHOST} -p ${PGPORT} -U ${PGUSER} -d postgres -tc "SELECT 1 FROM pg_database WHERE datname = 'default'" | grep -q 1 || \
|
||||
PGPASSWORD=${PGPASS} psql -h ${PGHOST} -p ${PGPORT} -U ${PGUSER} -d postgres -c "CREATE DATABASE \"default\""
|
||||
PGDATABASE=$(echo $PG_DATABASE_URL | awk -F ':' '{print $4}' | awk -F '/' '{print $2}')
|
||||
|
||||
# Run setup and migration scripts
|
||||
NODE_OPTIONS="--max-old-space-size=1500" tsx ./scripts/setup-db.ts
|
||||
yarn database:migrate:prod
|
||||
# Creating the database if it doesn't exist
|
||||
db_count=$(PGPASSWORD=${PGPASS} psql -h ${PGHOST} -p ${PGPORT} -U ${PGUSER} -d postgres -tAc "SELECT COUNT(*) FROM pg_database WHERE datname = '${PGDATABASE}'")
|
||||
if [ "$db_count" = "0" ]; then
|
||||
echo "Database ${PGDATABASE} does not exist, creating..."
|
||||
PGPASSWORD=${PGPASS} psql -h ${PGHOST} -p ${PGPORT} -U ${PGUSER} -d postgres -c "CREATE DATABASE \"${PGDATABASE}\""
|
||||
|
||||
# Mark initialization as done
|
||||
echo "Successfuly migrated DB!"
|
||||
touch /app/docker-data/db_status
|
||||
fi
|
||||
# Run setup and migration scripts
|
||||
NODE_OPTIONS="--max-old-space-size=1500" tsx ./scripts/setup-db.ts
|
||||
fi
|
||||
|
||||
yarn command:prod upgrade
|
||||
echo "Successfully migrated DB!"
|
||||
}
|
||||
setup_and_migrate_db
|
||||
|
||||
# Continue with the original Docker command
|
||||
exec "$@"
|
||||
|
||||
Reference in New Issue
Block a user