Compare commits

..

7 Commits

Author SHA1 Message Date
15d4cd5b9b
chore: start database and directus services 2025-03-07 14:03:33 +00:00
b775bd366e
chore(directus): improve definition
* Use latest version
* Configure `postgres` and `valkey` services
2025-03-07 14:02:29 +00:00
7fab4e4072
chore(database): add postgres and valkey services
These are used by `strapi` and `directus` to store data.
2025-03-07 13:59:33 +00:00
1ad7e94ea1
chore: add common configuration for the project
Set `editorconfig` pattern and files/paths to be ignored by `git` and
`docker`.

Finally, define runtimes needed by the project using `mise`.
2025-03-07 13:58:33 +00:00
Joao P Dubas
cb46478b0e wip: add base compose 2025-03-06 23:13:52 -03:00
Joao P Dubas
d57ea1ac67 wip: add strapi 2025-03-06 23:13:34 -03:00
Joao P Dubas
278d280eca feat: add directus 2025-03-06 23:13:07 -03:00
11 changed files with 261 additions and 0 deletions

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
**/node_modules
**/.next

41
.editorconfig Normal file
View File

@ -0,0 +1,41 @@
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
[*.{ts,tsx,js,jsx,json}]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
indent_size = 2
[{Dockerfile,docker-compose.yml,docker-compose.*.yml,compose.yml,compose.*.yml}]
indent_style = space
indent_size = 2
[*.{yml,yaml}]
indent_style = space
indent_size = 2
[*.sh]
end_of_line = lf
indent_style = space
indent_size = 2
[package.json]
indent_style = space
indent_size = 2
[*.{xml,config,conf}]
indent_style = space
indent_size = 2
[Makefile]
indent_style = tab

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
**/node_modules
**/.next

6
compose.yml Normal file
View File

@ -0,0 +1,6 @@
---
name: ${CMS_PROJECT_NAME:-cms}
include:
- services/database/compose.yml
- services/directus/compose.yml

3
mise.toml Normal file
View File

@ -0,0 +1,3 @@
[tools]
node = "18.20.7"
yarn = "1.22.22"

View File

@ -0,0 +1,48 @@
---
services:
postgres:
image: 'postgres:17.4-bookworm'
hostname: ${CMS_POSTGRES_HOST:-postgres}
init: true
restart: unless-stopped
healthcheck:
test:
- CMD-SHELL
- pg_isready
- --hostname
- localhost
- --username
- ${CMD_POSTGRES_USER:-postgres}
interval: 10s
timeout: 5s
retries: 5
start_interval: 5s
start_period: 30s
environment:
POSTGRES_USER: ${CMS_POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${CMS_POSTGRES_PASSWORD:-postgres}
volumes:
- 'postgres_data:/var/lib/postgresql/data'
- './scripts/postgres:/docker-entrypoint-initdb.d'
# NOTE: (jpd) this is an open-source alternative to redis
valkey:
image: 'valkey/valkey:8.0.2-bookworm'
hostname: ${CMS_VALKEY_HOST:-valkey}
init: true
restart: unless-stopped
healthcheck:
test:
- CMD-SHELL
- '[ $$(redis-cli ping) = "PONG" ]'
interval: 10s
timeout: 5s
retries: 5
start_interval: 5s
start_period: 30s
volumes:
- 'valkey_data:/data'
volumes:
postgres_data: {}
valkey_data: {}

View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -ex
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE DATABASE strapi;
GRANT ALL PRIVILEGES ON DATABASE strapi TO ${POSTGRES_USER};
EOSQL

View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE DATABASE directus;
GRANT ALL PRIVILEGES ON DATABASE strapi TO ${POSTGRES_USER};
EOSQL

View File

@ -0,0 +1,36 @@
---
services:
directus:
image: 'directus/directus:11.5.1'
hostname: directus
init: true
restart: unless-stopped
ports:
- ${CMS_DIRECTUS_PORTS:-8055:8055}
depends_on:
postgres:
condition: service_healthy
valkey:
condition: service_healthy
volumes:
- 'uploads:/directus/uploads'
- 'extensions:/directus/extensions'
environment:
SECRET: ${CMS_DIRECTUS_SECRET:-replace-with-random-value}
ADMIN_EMAIL: ${CMS_DIRECTUS_ADMIN_EMAIL:-admin@example.com}
ADMIN_PASSWORD: ${CMS_DIRECTUS_ADMIN_PASSWORD:-d1r3ctu5}
CACHE_ENABLED: 'true'
CACHE_AUTO_PURGE: 'true'
CACHE_STORE: redis
REDIS: ${CMS_VALKEY_URI:-redis://valkey:6379}
DB_CLIENT: pg
DB_USER: ${CMS_POSTGRES_USER:-postgres}
DB_PASSWORD: ${CMS_POSTGRES_PASSWORD:-postgres}
DB_HOST: ${CMS_POSTGRES_HOST:-postgres}
DB_PORT: ${CMS_POSTGRES_PORT:-5432}
DB_DATABASE: directus
WEBSOCKETS_ENABLED: 'true'
volumes:
extensions: {}
uploads: {}

View File

@ -0,0 +1,50 @@
FROM node:18-alpine3.18 AS development
# Installing libvips-dev for sharp Compatibility
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev git
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY package.json yarn.lock ./
RUN yarn global add node-gyp
RUN yarn config set network-timeout 600000 -g && yarn install
ENV PATH /opt/node_modules/.bin:$PATH
WORKDIR /opt/app
COPY . .
RUN chown -R node:node /opt/app
USER node
RUN ["yarn", "build"]
EXPOSE 1337
CMD ["yarn", "develop"]
# Creating multi-stage build for production
FROM node:18-alpine as build
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev git > /dev/null 2>&1
ENV NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY package.json yarn.lock ./
RUN yarn global add node-gyp
RUN yarn config set network-timeout 600000 -g && yarn install --production
ENV PATH /opt/node_modules/.bin:$PATH
WORKDIR /opt/app
COPY . .
RUN yarn build
# Creating final production image
FROM node:18-alpine
RUN apk add --no-cache vips-dev
ENV NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY --from=build /opt/node_modules ./node_modules
WORKDIR /opt/app
COPY --from=build /opt/app ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN chown -R node:node /opt/app
USER node
EXPOSE 1337
CMD ["yarn", "start"]

View File

@ -0,0 +1,59 @@
---
services:
strapi:
container_name: strapi
build: .
image: strapi:latest
restart: unless-stopped
env_file: .env
environment:
DATABASE_CLIENT: ${DATABASE_CLIENT}
DATABASE_HOST: strapiDB
DATABASE_PORT: ${DATABASE_PORT}
DATABASE_NAME: ${DATABASE_NAME}
DATABASE_USERNAME: ${DATABASE_USERNAME}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
JWT_SECRET: ${JWT_SECRET}
ADMIN_JWT_SECRET: ${ADMIN_JWT_SECRET}
APP_KEYS: ${APP_KEYS}
NODE_ENV: ${NODE_ENV}
volumes:
- ./config:/opt/app/config
- ./src:/opt/app/src
- ./package.json:/opt/package.json
- ./yarn.lock:/opt/yarn.lock
- ./.env:/opt/app/.env
- ./public/uploads:/opt/app/public/uploads
ports:
- "1337:1337"
networks:
- strapi
depends_on:
- strapiDB
strapiDB:
container_name: strapiDB
platform: linux/amd64 #for platform error on Apple M1 chips
restart: unless-stopped
env_file: .env
image: postgres:12.0-alpine
environment:
POSTGRES_USER: ${DATABASE_USERNAME}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_DB: ${DATABASE_NAME}
volumes:
- strapi-data:/var/lib/postgresql/data/ #using a volume
#- ./data:/var/lib/postgresql/data/ # if you want to use a bind folder
ports:
- "5432:5432"
networks:
- strapi
volumes:
strapi-data:
networks:
strapi:
name: Strapi
driver: bridge