tursodatabase / libsql

libSQL is a fork of SQLite that is both Open Source, and Open Contributions.
https://turso.tech/libsql
MIT License
11.62k stars 290 forks source link

Unable to run on `oven/bun:distroless` docker image #1558

Open jamiehaywood opened 4 months ago

jamiehaywood commented 4 months ago

When I try and run a libsql on a Bun distroless image I get an error: TypeError: libgcc_s.so.1: cannot open shared object file: No such file or directory

I assume that the distroless is missing some native binaries that libsql relies on?

Minimal repro:

index.ts

import { drizzle } from "drizzle-orm/libsql";
import { createClient } from "@libsql/client";
import * as schema from "./schema";

const client = createClient({
  url: `file:${__dirname}/sqlite.db`,
});

const db = drizzle<typeof schema>(client, { schema });

const res = await db.select().from(schema.books);

console.log(res);

drizzle.config.ts

import { defineConfig } from "drizzle-kit";

export default defineConfig({
  dialect: "sqlite",

  schema: "./schema.ts",
  out: "./drizzle",

  dbCredentials: {
    url: "sqlite.db",
  },
});

schema.ts

import { sqliteTable, text } from "drizzle-orm/sqlite-core";

const books = sqliteTable("books", {
  id: text("id").notNull().primaryKey(),
  title: text("title").notNull(),
  description: text("description"),
});

export { books };

Dockerfile

FROM oven/bun:distroless
COPY dist .
ENTRYPOINT ["bun", "./index.js"]
  1. Run bun build index.ts --outdir dist --target bun
  2. Run docker build . -t repro
  3. Run docker run -p 8080:8080 test
jamiehaywood commented 4 months ago

Update: works using the oven/bun:latest image.

Would be ideal if we could run distroless as it halves the final docker image size.

flexchar commented 3 months ago

I would say it's not libsql issue but rather that the base image is missing the module. It is therefore your responsibility to provide the modules, especially when using the skinniest docker image variations, for what you would like to run - in this case sqld.

So this could be closed. :)

jamiehaywood commented 3 months ago

thanks for your reply @flexchar - how do you know that sqld is the missing module?

flexchar commented 3 months ago

The error you shared in the first paragraph tells us exactly that - that libgcc_s.so.1 is missing.

I have been tinkering with docker for several years and I stumbled upon issues like that more than I would wish anyone :D.

Upon googling, I find this https://pkgs.alpinelinux.org/package/edge/main/x86_64/libgcc

So I would suggest to install this package and try again. You can do so by adding RUN apk install -y libgcc to your Dockerfile. Let me know if that helps!