diff options
Diffstat (limited to 'docker')
-rw-r--r-- | docker/docker-compose.api.yml | 60 | ||||
-rw-r--r-- | docker/docker-compose.base.yml | 72 | ||||
-rw-r--r-- | docker/docker-compose.db.yml | 80 |
3 files changed, 212 insertions, 0 deletions
diff --git a/docker/docker-compose.api.yml b/docker/docker-compose.api.yml new file mode 100644 index 0000000..5c7f6d8 --- /dev/null +++ b/docker/docker-compose.api.yml @@ -0,0 +1,60 @@ +### CRIMSON --- A simple PHP framework. +### Copyright © 2024 Freya Murphy <contact@freyacat.org> +### +### This file is part of CRIMSON. +### +### CRIMSON is free software; you can redistribute it and/or modify it +### under the terms of the GNU General Public License as published by +### the Free Software Foundation; either version 3 of the License, or (at +### your option) any later version. +### +### CRIMSON is distributed in the hope that it will be useful, but +### WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with CRIMSON. If not, see <http://www.gnu.org/licenses/>. + +services: + # `docker-compose-api.yml` + # This compose file creates the `rest` container running postgrest. This is + # the program that crimson uses for the default API functionality. + # + # This service stack is only enabled when API_ENABLED=true. + # + # WARNING: The postgres container must also be enabled `POSTGRES_ENABLED=true` + # otherwise the docker stack will be invalid. + + rest: + # Postgrest uses postgres to store the api schema. To work properly, the + # database must be working (healthy) and all the api schema must be loaded. + # It is db-init's job to load the api schema, thus this container depends + # on both postgres and db-init. + build: ../build/postgrest + restart: unless-stopped + environment: + - API_SECRET + - API_ROLE + - API_SCHEMA + - POSTGRES_DB + - POSTGRES_USER + - POSTGRES_PASSWORD + healthcheck: + test: curl -I "http://localhost:3000/" + interval: 10s + timeout: 3s + retries: 10 + start_period: 3s + depends_on: + postgres: + condition: service_healthy + db-init: + condition: service_completed_successfully + + web: + # Nginx proxies requests to the API making it an added dependency. + depends_on: + rest: + condition: service_healthy + diff --git a/docker/docker-compose.base.yml b/docker/docker-compose.base.yml new file mode 100644 index 0000000..3dcc7b8 --- /dev/null +++ b/docker/docker-compose.base.yml @@ -0,0 +1,72 @@ +### CRIMSON --- A simple PHP framework. +### Copyright © 2024 Freya Murphy <contact@freyacat.org> +### +### This file is part of CRIMSON. +### +### CRIMSON is free software; you can redistribute it and/or modify it +### under the terms of the GNU General Public License as published by +### the Free Software Foundation; either version 3 of the License, or (at +### your option) any later version. +### +### CRIMSON is distributed in the hope that it will be useful, but +### WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with CRIMSON. If not, see <http://www.gnu.org/licenses/>. + +services: + # `docker-compose-base.yml` + # This compose file creates the `web`, `php`, and `init` containers. + # This is the barebones stack required to run crimson. + # + # This service stack is ALWAYS enabled. + + web: + # Crimson runs a nginx proxy to facilitate requets to PHP and requests + # to the API (if enabled). Since it needs PHP to be running to send + # requests, `php` is an added dependency. + # + # HTTP_PORT and HTTP_BIND sets what the external listen address will be for + # the entire crimson stack. + build: ../build/nginx + restart: unless-stopped + environment: + - API_ENABLED + ports: + - ${HTTP_BIND}:${HTTP_PORT}:8080 + volumes: + - ${SOURCE}:/opt/site:ro + - ../src:/opt/crimson:ro + depends_on: + php: + condition: service_started + + php: + # There exists some crimson functionaly that MAY be used which requires a + # stamp.php file to be auto generated. This is done in `init`, this `init` + # is an added dependency. + build: ../build/php + restart: unless-stopped + environment: + - POSTGRES_DB + - POSTGRES_USER + - POSTGRES_PASSWORD + volumes: + - ${SOURCE}:/opt/site:ro + - ../src:/opt/crimson:ro + - ${DATA}/crimson:/var/run/crimson + depends_on: + init: + condition: service_completed_successfully + + init: + # Initalizes required files for php. Currently init only generates stamp.php. + # This file hols all file stamps for all public assets, which is used in + # crimsons `asset_stamp` controller function. + build: ../build/init + restart: no + volumes: + - ${SOURCE}:/opt/site + - ${DATA}/crimson:/var/run/crimson diff --git a/docker/docker-compose.db.yml b/docker/docker-compose.db.yml new file mode 100644 index 0000000..4979bbe --- /dev/null +++ b/docker/docker-compose.db.yml @@ -0,0 +1,80 @@ +### CRIMSON --- A simple PHP framework. +### Copyright © 2024 Freya Murphy <contact@freyacat.org> +### +### This file is part of CRIMSON. +### +### CRIMSON is free software; you can redistribute it and/or modify it +### under the terms of the GNU General Public License as published by +### the Free Software Foundation; either version 3 of the License, or (at +### your option) any later version. +### +### CRIMSON is distributed in the hope that it will be useful, but +### WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with CRIMSON. If not, see <http://www.gnu.org/licenses/>. + +services: + # `docker-compose-db.yml` + # This compose file creates the `postgres`, and `db-init` containers. + # Crimson uses prostgres for its database and uses db-init to initalize the + # baseline required for all crimson components. + # + # This service stack is only enabled when API_ENABLED=true. + + postgres: + build: ../build/postgres + restart: unless-stopped + environment: + - POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=C --lc-ctype=C + - POSTGRES_DB + - POSTGRES_USER + - POSTGRES_PASSWORD + volumes: + - ${DATA}/schemas:/var/lib/postgresql/data + - ${SOURCE}/db:/db:ro + healthcheck: + test: pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB} + interval: 1s + timeout: 3s + retries: 10 + start_period: 3s + + db-init: + # => Guarantees the required crimson baseline in the database. + # i.e. sys schema used for storing migration meta data and other small + # things. + # => Runs all database migrations for you. All that is needed + # is that the migration file convention is followed. + # => If the API is enabled, also loads in the api schema for postgrest. + # + # Once db-init finishes, it will create a `db-ready` file in + # /var/run/crimson to tell crimson's php code its to further route requests. + # + # For information on databse conventions and layouts, see + # `build/db-init/README.md`. + build: ../build/db-init + restart: no + environment: + - POSTGRES_DB + - POSTGRES_USER + - POSTGRES_PASSWORD + - API_ENABLED + - API_SECRET + volumes: + - ${SOURCE}/db:/db:ro + - ${DATA}/crimson:/var/run/crimson + depends_on: + postgres: + condition: service_healthy + + php: + # Crimson supports calling the postgres database inside php though the + # database library. Thus is in added dependency. Crimson does not need to + # depend on db-init since db-init has a ready file that crimons uses + # instead. + depends_on: + postgres: + condition: service_healthy |