Created
September 7, 2023 14:36
-
-
Save hopsoft/9a0bf00be2816cbe036fae5aa3d85b73 to your computer and use it in GitHub Desktop.
Ruby + SQLite Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ruby:3.2.2-alpine | |
# ============================================================================================================ | |
# Install system packages | |
# ============================================================================================================ | |
RUN apk add --no-cache --update \ | |
bash \ | |
build-base \ | |
curl \ | |
gcompat \ | |
libc6-compat \ | |
libsass \ | |
linux-headers \ | |
sqlite-dev \ | |
tzdata \ | |
vim | |
# setup directories for external mounted volumes | |
RUN mkdir -p /mnt/external/bundle /mnt/external/databases | |
ENV GEM_HOME="/mnt/external/bundle" | |
RUN gem update --system && gem install bundler | |
# ============================================================================================================ | |
# Compile and install sqlite3 (for performance turning and build customizations) | |
# SEE: https://www.sqlite.org/compile.html | |
# NOTE: The sqlite3 Ruby gem will not work with the following compile time flags | |
# * -DSQLITE_OMIT_DEPRECATED | |
# ============================================================================================================ | |
# download and extract | |
RUN curl --remote-name --remote-header-name https://www.sqlite.org/2023/sqlite-amalgamation-3410200.zip && unzip sqlite-amalgamation-3410200.zip | |
WORKDIR /sqlite-amalgamation-3410200 | |
ENV CFLAGS="\ | |
-DSQLITE_DEFAULT_MEMSTATUS=0 \ | |
-DSQLITE_DEFAULT_PAGE_SIZE=16384 \ | |
-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 \ | |
-DSQLITE_DQS=0 \ | |
-DSQLITE_ENABLE_FTS5 \ | |
-DSQLITE_LIKE_DOESNT_MATCH_BLOBS \ | |
-DSQLITE_MAX_EXPR_DEPTH=0 \ | |
-DSQLITE_OMIT_PROGRESS_CALLBACK \ | |
-DSQLITE_OMIT_SHARED_CACHE \ | |
-DSQLITE_USE_ALLOCA" | |
# compile the executable | |
RUN gcc $CFLAGS shell.c sqlite3.c -lpthread -ldl -lm -o /usr/local/bin/sqlite3 | |
# compile and setup shared library | |
RUN gcc $CFLAGS shell.c sqlite3.c -lpthread -ldl -lm -fPIC -shared -o /usr/local/lib/libsqlite3.so && \ | |
chmod 755 /usr/local/lib/libsqlite3.so && \ | |
ln -s /usr/local/lib/libsqlite3.so /usr/local/lib/libsqlite3.so.0 | |
# copy header/include files | |
RUN mkdir -p /usr/local/include/sqlite3 && \ | |
cp sqlite3.h /usr/local/include/sqlite3/ && \ | |
cp sqlite3ext.h /usr/local/include/sqlite3/ | |
# configure bundler to be aware of the custom sqlite3 installation | |
ENV BUILD_SQLITE3="true" | |
RUN bundle config set --global build.sqlite3 --enable-system-libraries --with-sqlite3-include=/usr/local/include/sqlite3 --with-sqlite3-lib=/usr/local/lib | |
# cleanup | |
ENV CFLAGS="" | |
RUN rm -rf /sqlite-amalgamation-3410200 /sqlite-amalgamation-3410200.zip | |
# ============================================================================================================ | |
# Application and Deployment setup | |
# ============================================================================================================ | |
COPY . /app | |
WORKDIR /app | |
# default command that runs when the container is started | |
CMD /app/bin/docker/run |
See upstream feature request: sparklemotion/sqlite3-ruby#401
This is great @flavorjones. Thank you for sharing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An alternative that I think might be simpler: you can set your CFLAGS environment variable to contain the
-DSQLITE_*
flags at gem installation time and they will be built into the gem's sqlite: