From 95fcd84f2206ef1c7e9c6ed914b096f39f2d11c3 Mon Sep 17 00:00:00 2001 From: Fan Yang Date: Tue, 26 Nov 2024 17:33:18 +0800 Subject: [PATCH] ci: pre-install the required DuckDB extensions (#217) --- docker/Dockerfile | 18 ++++++++---------- main.go | 10 ++++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 5fc08647..652a4ad0 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -46,14 +46,15 @@ FROM debian:bookworm-slim ARG TARGETOS ARG TARGETARCH -RUN apt-get update && apt-get install -y \ +RUN apt-get update && apt-get install -y debian-archive-keyring \ + && apt-get update && apt-get install -y \ vim \ procps \ curl \ unzip \ libstdc++6 \ - python3 \ - python3-pip \ + python3 python3-pip \ + libpq-dev postgresql-client \ --no-install-recommends \ && rm -rf /var/lib/apt/lists/* @@ -68,6 +69,7 @@ RUN if [ "$TARGETARCH" = "arm64" ]; then \ fi && \ curl -LJO https://dev.mysql.com/get/Downloads/MySQL-Shell/mysql-shell-9.1.0-linux-glibc2.28-${ARCH}-64bit.tar.gz \ && tar -zxvf mysql-shell-9.1.0-linux-glibc2.28-${ARCH}-64bit.tar.gz \ + && rm mysql-shell-9.1.0-linux-glibc2.28-${ARCH}-64bit.tar.gz \ && mv mysql-shell-9.1.0-linux-glibc2.28-${ARCH}-64bit /usr/local/mysqlsh \ && ln -s /usr/local/mysqlsh/bin/mysqlsh /usr/local/bin/mysqlsh \ && mysqlsh --version @@ -85,13 +87,6 @@ RUN if [ "$TARGETARCH" = "arm64" ]; then \ && rm duckdb_cli-linux-$ARCH.zip \ && duckdb -c 'SELECT extension_name, loaded, install_path FROM duckdb_extensions() where installed' -RUN apt-get update && \ - apt-get install -y debian-archive-keyring && \ - apt-get update && \ - apt-get install -y libpq-dev postgresql-client \ - --no-install-recommends \ - && rm -rf /var/lib/apt/lists/* - RUN duckdb -version RUN useradd --create-home --user-group --shell /bin/bash admin \ @@ -111,6 +106,9 @@ COPY --chown=admin:admin --chmod=755 devtools/replica-setup-postgres ./replica-s # ENV LC_CTYPE="en_US.UTF-8" # ENV LANG="en_US.UTF-8" +# Install the required DuckDB extensions +RUN myduckserver --init + # Expose the ports your server will run on (if applicable) EXPOSE 3306 EXPOSE 5432 diff --git a/main.go b/main.go index 466f0cdc..82dbf5da 100644 --- a/main.go +++ b/main.go @@ -42,6 +42,8 @@ import ( // The included MySQL client is used in this example, however any MySQL-compatible client will work. var ( + initMode = false + address = "0.0.0.0" port = 3306 socket string @@ -55,6 +57,8 @@ var ( ) func init() { + flag.BoolVar(&initMode, "init", initMode, "Initialize the program and exit. The necessary extensions will be installed.") + flag.StringVar(&address, "address", address, "The address to bind to.") flag.IntVar(&port, "port", port, "The port to bind to.") flag.StringVar(&socket, "socket", socket, "The Unix domain socket to bind to.") @@ -95,6 +99,12 @@ func main() { ensureSQLTranslate() + if initMode { + provider := catalog.NewInMemoryDBProvider() + provider.Close() + return + } + provider, err := catalog.NewDBProvider(dataDirectory, dbFileName) if err != nil { logrus.Fatalln("Failed to open the database:", err)