Skip to content

Instantly share code, notes, and snippets.

@MaherSaif
Forked from hopsoft/Dockerfile
Created March 29, 2024 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaherSaif/e2e4f202574a1c61933322ec80d80768 to your computer and use it in GitHub Desktop.
Save MaherSaif/e2e4f202574a1c61933322ec80d80768 to your computer and use it in GitHub Desktop.
Ruby + SQLite Dockerfile
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment