FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive

# Install required packages
RUN apt-get update && apt-get install -y \
    wget \
    curl \
    ca-certificates \
    apt-transport-https \
    gnupg

# Add ClickHouse repository
RUN curl -fsSL 'https://packages.clickhouse.com/rpm/lts/repodata/repomd.xml.key' | gpg --dearmor -o /usr/share/keyrings/clickhouse-keyring.gpg
RUN echo "deb [signed-by=/usr/share/keyrings/clickhouse-keyring.gpg] https://packages.clickhouse.com/deb stable main" | tee /etc/apt/sources.list.d/clickhouse.list

# Update package lists
RUN apt-get update

# Install ClickHouse server and client
RUN apt-get install -y clickhouse-server clickhouse-client

# Create a ClickHouse configuration file
COPY clickhouse-server.xml /etc/clickhouse-server/config.xml

# Set environment variables
ENV CLICKHOUSE_CONFIG_FILE=/etc/clickhouse-server/config.xml
ENV CLICKHOUSE_USER=default
ENV CLICKHOUSE_PASSWORD=password

# Expose ClickHouse port
EXPOSE 8123

# Start ClickHouse server
CMD ["/usr/bin/clickhouse-server"]
