Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uses alt base image based on the stack for local #627

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions tembo-cli/src/cmd/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use controller::extensions::types::Extension as ControllerExtension;
use controller::extensions::types::ExtensionInstallLocation as ControllerExtensionInstallLocation;
use controller::extensions::types::TrunkInstall as ControllerTrunkInstall;
use controller::stacks::get_stack;
use controller::stacks::types::Stack;
use controller::stacks::types::StackType as ControllerStackType;
use itertools::Itertools;
use log::info;
Expand Down Expand Up @@ -240,10 +241,11 @@ fn docker_apply_instance(
stack.app_services.clone(),
extensions,
trunk_installs,
stack.postgres_config,
stack.postgres_config.clone(),
)?;

let rendered_dockerfile: String = get_rendered_dockerfile(&trunk_installs)?;
let rendered_dockerfile: String =
get_rendered_dockerfile(&trunk_installs, &stack, instance_setting.pg_version)?;

FileUtils::create_file(
DOCKERFILE_NAME.to_string(),
Expand Down Expand Up @@ -988,6 +990,8 @@ pub fn get_instance_settings(

pub fn get_rendered_dockerfile(
trunk_installs: &Option<Vec<ControllerTrunkInstall>>,
stack: &Stack,
pg_version: u8,
) -> Result<String, anyhow::Error> {
// Include the Dockerfile template directly into the binary
let contents = include_str!("../../tembo/Dockerfile.template");
Expand All @@ -996,6 +1000,14 @@ pub fn get_rendered_dockerfile(
let _ = tera.add_raw_template("dockerfile", contents);
let mut context = Context::new();

let image = match pg_version.into() {
14 => &stack.images.pg14,
15 => &stack.images.pg15,
16 => &stack.images.pg16,
_ => &stack.images.pg15,
};

context.insert("image_with_version", &image);
context.insert("trunk_installs", &trunk_installs);

let rendered_dockerfile = tera.render("dockerfile", &context).unwrap();
Expand Down Expand Up @@ -1109,6 +1121,15 @@ fn get_postgres_config(
}
}

postgres_config.push_str(
"
listen_addresses = '*'
ssl = 'on'
ssl_cert_file = '/var/lib/postgresql/server.crt'
ssl_key_file = '/var/lib/postgresql/server.key'
ssl_min_protocol_version = 'TLSv1.2'",
);

Ok(postgres_config)
}

Expand Down
47 changes: 45 additions & 2 deletions tembo-cli/tembo/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
FROM quay.io/tembo/tembo-local:latest
FROM quay.io/tembo/{{image_with_version}}

USER root

RUN apt-get update && \
apt-get install -y vim openssl && \
apt-get autoremove -y && \
apt-get clean -y && \
rm -rf /var/lib/apt/lists/*

RUN chown -R postgres:postgres $PGDATA && \
chmod -R 0700 $PGDATA
# Set up the environment for the data directory
ENV PGDATA /var/lib/postgresql/data2
RUN mkdir -p $PGDATA && \
chown -R postgres:postgres $PGDATA && \
chmod -R 0700 $PGDATA

# Generate self-signed certificate
RUN openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 \
-subj "/CN=*.local.tembo.io" \
-keyout /var/lib/postgresql/server.key \
-out /var/lib/postgresql/server.crt && \
chown postgres:postgres /var/lib/postgresql/server.* && \
chmod 600 /var/lib/postgresql/server.key

USER postgres

# Initialize the database
RUN pg_ctl -c init


# Set permissive authentication (for local testing)
RUN echo "hostssl all all 0.0.0.0/0 trust" >> ${PGDATA}/pg_hba.conf
RUN echo "include_dir = 'extra-configs'" >> ${PGDATA}/postgresql.conf
RUN mkdir -p $PGDATA/extra-configs

# Set environment variables
ENV PGHOST=localhost
ENV PGPORT=5432
ENV PGDATABASE=postgres
ENV PGUSER=postgres

{% for trunk_install in trunk_installs %}
{% if trunk_install.version %}
Expand All @@ -10,4 +51,6 @@ RUN trunk install {{trunk_install.name}}

# Optional:
# Specify extra Postgres configurations by copying into this directory
COPY postgres.conf $PGDATA/extra-configs
COPY postgres.conf $PGDATA/extra-configs/postgres.conf

CMD ["postgres"]