ECS Configuration
Table of Contents
Overview
This document describes the configuration file config.ts used in the ECS (Elastic Container Service) infrastructure for the Ghost application. The file contains various configuration settings and environment variables necessary for running the application in a containerized environment.
Helper Function
The getEnv function is a crucial utility used throughout the configuration file:
const getEnv = (key: string, fallback: string = ""): string => process.env[key] || fallback;
Parameters
key: The name of the environment variable to retrieve.fallback: (Optional) A default value to return if the environment variable is not set.
Return Value
- Returns the value of the environment variable if it exists, otherwise returns the fallback value.
Usage Example
const databaseName = getEnv("DB_NAME", "ghost");
This function allows for flexible configuration management, enabling the use of environment variables with fallback values for better robustness.
Configuration Sections
Database
const dbConfig = {
engine: "django.db.backends.postgresql",
name: "ghost",
username: getEnv("POSTGRES_USER"),
password: getEnv("POSTGRES_PASSWORD"),
host: getEnv("POSTGRES_HOST"),
port: "5432",
};
Note: The database engine is set to PostgreSQL.
AWS
const awsConfig = {
s3Manager: {
accessKeyId: getEnv("AWS_ACCESS_KEY_ID_S3_MANAGER"),
secretAccessKey: getEnv("AWS_SECRET_ACCESS_KEY_S3_MANAGER"),
},
};
Important: Keep AWS credentials secure and never commit them to version control.
Application
export const appConfig = {
secretKey: getEnv("SECRET_KEY"),
rabbitMQUrl: getEnv("RMQ_URL"),
publicBackend: {
protocol: getEnv("PUBLIC_BACKEND_PROTOCOL"),
host: getEnv("PUBLIC_BACKEND_HOST", "api.onghost.com"),
port: getEnv("PUBLIC_BACKEND_PORT"),
},
auth0: {
PUBLIC_AUTH0_DOMAIN: getEnv("PUBLIC_AUTH0_DOMAIN"),
PUBLIC_AUTH0_CLIENT_ID: getEnv("PUBLIC_AUTH0_CLIENT_ID"),
AUTH0_M2M_CLIENT_ID: getEnv("AUTH0_M2M_CLIENT_ID"),
AUTH0_M2M_CLIENT_SECRET: getEnv("AUTH0_M2M_CLIENT_SECRET"),
PUBLIC_AUTH0_AUDIENCE: getEnv("PUBLIC_AUTH0_AUDIENCE"),
PUBLIC_AUTH0_CUSTOM_DOMAIN: getEnv("PUBLIC_AUTH0_CUSTOM_DOMAIN"),
},
};
This section includes RabbitMQ and Auth0 configurations.
Flower
export const flowerConfig = {
basicAuth: {
user1: getEnv("FLOWER_USER"),
password1: getEnv("FLOWER_PASSWORD"),
},
certificateDomain: getEnv("FLOWER_HOST", "flower.onghost.com"),
};
Flower is used for monitoring Celery tasks.
Django Superuser
const djangoSuperuser = {
email: getEnv("DJANGO_SUPERUSER_EMAIL", "admin@onghost.com"),
username: getEnv("DJANGO_SUPERUSER_USERNAME", "admin"),
password: getEnv("DJANGO_SUPERUSER_PASSWORD", "admin"),
};
Caution: Always change the default superuser credentials in production.
Environment Variables
The environmentVariables array contains all the environment variables that will be passed to the container:
export const environmentVariables = [
{ name: "SECRET_KEY", value: appConfig.secretKey },
// ... more variables ...
];
This array includes:
- Database settings
- Email configuration
- AWS credentials
- Application settings
- Auth0 configuration
Docker Configuration
const dockerConfig = {
registry: getEnv("ECR_REGISTRY"),
repository: getEnv("ECR_REPOSITORY"),
imageTag: getEnv("IMAGE_TAG"),
};
export const image = `${dockerConfig.registry}/${dockerConfig.repository}:${dockerConfig.imageTag}`;
This section configures the Docker image details, including the ECR (Elastic Container Registry) information and image tag.
This configuration file is essential for setting up the Ghost application in an ECS environment. It ensures that all necessary settings and environment variables are properly configured for the containerized application to run smoothly.
Best Practice: Regularly review and update these configurations to maintain security and optimal performance.