Skip to content

Commit

Permalink
API stack (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChuckHend authored Dec 21, 2023
1 parent faf073c commit 06bb35c
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tembo-operator/src/stacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use types::{Stack, StackType};
use lazy_static::lazy_static;

lazy_static! {
pub static ref API: Stack =
serde_yaml::from_str(include_str!("templates/api.yaml")).expect("api.yaml not found");
pub static ref DATAWAREHOUSE: Stack = serde_yaml::from_str(include_str!("templates/data_warehouse.yaml"))
.expect("data_warehouse.yaml not found");
pub static ref MQ: Stack = serde_yaml::from_str(include_str!("templates/message_queue.yaml"))
Expand All @@ -24,11 +26,12 @@ lazy_static! {
serde_yaml::from_str(include_str!("templates/gis.yaml")).expect("gis.yaml not found");
pub static ref MONGO_ALTERNATIVE: Stack =
serde_yaml::from_str(include_str!("templates/mongo_alternative.yaml"))
.expect("mongo_adapter.yaml not found");
.expect("mongo_alternative.yaml not found");
}

pub fn get_stack(entity: StackType) -> types::Stack {
match entity {
StackType::API => API.clone(),
StackType::DataWarehouse => DATAWAREHOUSE.clone(),
StackType::MessageQueue => MQ.clone(),
StackType::Standard => STANDARD.clone(),
Expand Down
100 changes: 100 additions & 0 deletions tembo-operator/src/stacks/templates/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: API
description: Tembo Stack with REST and graphQL interfaces.
image: "quay.io/tembo/standard-cnpg:15.3.0-1-1096aeb"
stack_version: 0.1.0
appServices:
- image: postgrest/postgrest:v12.0.0
name: http
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: 400m
memory: 256Mi
routing:
- port: 3000
ingressPath: /rest/v1
middlewares:
- rest-headers
- strip-path-prefix
- port: 3000
ingressPath: /graphql/v1
middlewares:
- gql-headers
- map-gql
middlewares:
- !customRequestHeaders
name: rest-headers
config:
Authorization: ""
- !customRequestHeaders
name: gql-headers
config:
Authorization: ""
Content-Profile: graphql
Accept-Profile: graphql
- !stripPrefix
name: strip-path-prefix
config:
- /rest/v1
- !replacePathRegex
name: map-gql
config:
regex: '\/graphql\/v1\/?'
replacement: /rpc/resolve
env:
- name: PGRST_DB_URI
valueFromPlatform: ReadWriteConnection
- name: PGRST_DB_SCHEMA
value: "public, graphql"
- name: PGRST_DB_ANON_ROLE
value: postgres
trunk_installs:
- name: pg_graphql
version: 1.4.1
extensions:
- name: pg_graphql
locations:
- database: postgres
enabled: true
version: 1.4.1
compute_templates:
- cpu: 0.25
memory: 1Gi
- cpu: 0.5
memory: 2Gi
- cpu: 1
memory: 4Gi
- cpu: 2
memory: 8Gi
- cpu: 4
memory: 16Gi
- cpu: 8
memory: 32Gi
- cpu: 16
memory: 32Gi
postgres_config_engine: standard
postgres_config:
- name: autovacuum_vacuum_cost_limit
value: -1
- name: autovacuum_vacuum_scale_factor
value: 0.05
- name: autovacuum_vacuum_insert_scale_factor
value: 0.05
- name: autovacuum_analyze_scale_factor
value: 0.05
- name: checkpoint_timeout
value: 10min
- name: track_activity_query_size
value: 2048
- name: wal_compression
value: 'on'
- name: track_io_timing
value: 'on'
- name: log_min_duration_statement # https://www.postgresql.org/docs/15/runtime-config-logging.html
value: 1000
- name: pg_stat_statements.track
value: all
- name: shared_preload_libraries
value: pg_stat_statements
7 changes: 7 additions & 0 deletions tembo-operator/src/stacks/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use utoipa::ToSchema;

#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, ToSchema)]
pub enum StackType {
API,
DataWarehouse,
Standard,
MessageQueue,
Expand All @@ -29,6 +30,7 @@ impl std::str::FromStr for StackType {

fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"API" => Ok(StackType::API),
"DataWarehouse" => Ok(StackType::DataWarehouse),
"Standard" => Ok(StackType::Standard),
"MessageQueue" => Ok(StackType::MessageQueue),
Expand All @@ -46,6 +48,7 @@ impl std::str::FromStr for StackType {
impl StackType {
pub fn as_str(&self) -> &str {
match self {
StackType::API => "API",
StackType::DataWarehouse => "DataWarehouse",
StackType::Standard => "Standard",
StackType::MessageQueue => "MessageQueue",
Expand Down Expand Up @@ -185,6 +188,7 @@ mod tests {
fn test_all_stack_deserialization() {
// must not panic when reading any stack definitions from yaml
let all_stacks = vec![
StackType::API,
StackType::DataWarehouse,
StackType::Standard,
StackType::MessageQueue,
Expand All @@ -201,6 +205,9 @@ mod tests {
// pattern match on the StackType enum, which if a new stack is added, this test will fail until its updated
// guarantees all StackTypes are tested
match stack {
StackType::API => {
get_stack(StackType::API);
}
StackType::DataWarehouse => {
get_stack(StackType::DataWarehouse);
}
Expand Down

0 comments on commit 06bb35c

Please sign in to comment.