From f4025098e9960be5e8cb7b7ff0cdb5459fdaba33 Mon Sep 17 00:00:00 2001 From: Jan Kohlbach Date: Tue, 6 Aug 2024 09:39:52 +0200 Subject: [PATCH] feat: add platformsh config --- .environment | 30 ++++++++++++++++++++++ .platform.app.yaml | 55 +++++++++++++++++++++++++++++++++++++++++ .platform/routes.yaml | 7 ++++++ .platform/services.yaml | 10 ++++++++ 4 files changed, 102 insertions(+) create mode 100644 .environment create mode 100644 .platform.app.yaml create mode 100644 .platform/routes.yaml create mode 100644 .platform/services.yaml diff --git a/.environment b/.environment new file mode 100644 index 000000000..2d00e47cc --- /dev/null +++ b/.environment @@ -0,0 +1,30 @@ +#!/bin/bash +# This script can be a starting point to convert +# PLATFORM_RELATIONSHIPS into another environment variable +# Many CMS systems use a DATABASE_URL to connect to the database +# Feel free to use this as inspiration + +getRelationshipInfo() { + RELATIONSHIP_NAME="$1" + PROPERTY="$2" + JQ_STR="to_entries[] | select(.key==\"$RELATIONSHIP_NAME\") | .value[].$PROPERTY" + CMD="echo $PLATFORM_RELATIONSHIPS | base64 -d | jq -r '$JQ_STR'" + eval $CMD +} + +# choose the name of the relationship to parse, feel free to alter this +RELATIONSHIP="postgresdatabase" +DB_DATABASE="main" + +# Extract the information we need +DB_TYPE=$(getRelationshipInfo "$RELATIONSHIP" 'scheme') +DB_USERNAME=$(getRelationshipInfo "$RELATIONSHIP" 'username') +DB_HOST=$(getRelationshipInfo "$RELATIONSHIP" 'host') +DB_PASS=$(getRelationshipInfo "$RELATIONSHIP" 'password') +DB_PORT=$(getRelationshipInfo "$RELATIONSHIP" 'port') + +# Create your DATABASE_URL variable here +export DATABASE_URL="postgresql://$DB_USERNAME:$DB_PASS@$DB_HOST:$DB_PORT/$DB_DATABASE" + +# So now we have postgresql://user:@db_mysql.internal:3306/main +# echo "$DATABASE_URL" #only echo to test since it will expose the credentials diff --git a/.platform.app.yaml b/.platform.app.yaml new file mode 100644 index 000000000..db0cfe627 --- /dev/null +++ b/.platform.app.yaml @@ -0,0 +1,55 @@ +# The name of this app. Must be unique within a project. +name: app + +# The runtime the application uses. The 'type' key defines the base container +# image that will be used to run the application. There is a separate base +# container image for each primary language for the application, +# in multiple versions. Check the JavaScript/Node.js documentation +# (https://docs.platform.sh/languages/nodejs.html#supported-versions) +# to find the supported versions for the 'nodejs' type. +type: 'nodejs:18' + +dependencies: + nodejs: + yarn: '*' + +build: + flavor: none + +hooks: + build: | + set -e + yarn install + yarn build + deploy: | + set -e + yarn update-db + +# The following block defines a single writable directory, 'web/uploads' +# The 'source' specifies where the writable mount is. The 'local' source +# indicates that the mount point will point to a local directory on the +# application container. The 'source_path' specifies the subdirectory +# from within the source that the mount should point at. +mounts: + 'web/uploads': + source: local + source_path: uploads + +# The size of the persistent disk of the application (in MB). +disk: 2048 + +resources: + base_memory: 256 + memory_ratio: 128 + +# The relationships of the application with services or other applications. +# +# The left-hand side is the name of the relationship as it will be exposed +# to the application in the PLATFORM_RELATIONSHIPS variable. The right-hand +# side is in the form ':'. +relationships: + postgresdatabase: 'dbpostgres:postgresql' + +web: + commands: + start: 'yarn start' diff --git a/.platform/routes.yaml b/.platform/routes.yaml new file mode 100644 index 000000000..a9181e0c2 --- /dev/null +++ b/.platform/routes.yaml @@ -0,0 +1,7 @@ +"https://{default}/": + type: upstream + upstream: "app:http" + +"https://www.{default}/": + type: redirect + to: "https://{default}/" diff --git a/.platform/services.yaml b/.platform/services.yaml new file mode 100644 index 000000000..cc9a7a02c --- /dev/null +++ b/.platform/services.yaml @@ -0,0 +1,10 @@ +# The name given to the PostgreSQL service (lowercase alphanumeric only). +dbpostgres: + # The type of your service (postgresql), which uses the format + # 'type:version'. Be sure to consult the PostgreSQL documentation + # (https://docs.platform.sh/add-services/postgresql.html#supported-versions) + # when choosing a version. If you specify a version number which is not available, + # the CLI will return an error. + type: postgresql:15 + # The disk attribute is the size of the persistent disk (in MB) allocated to the service. + disk: 2048