Last active
October 30, 2024 15:06
-
-
Save robzolkos/96ca00b56dee3f6ba7207ef57fceaa9c to your computer and use it in GitHub Desktop.
Kamal / SQLite3 issue
This file contains 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
# SQLite. Versions 3.8.0 and up are supported. | |
# gem install sqlite3 | |
# | |
# Ensure the SQLite 3 gem is defined in your Gemfile | |
# gem "sqlite3" | |
# | |
default: &default | |
adapter: sqlite3 | |
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | |
timeout: 5000 | |
development: | |
<<: *default | |
database: data/development.sqlite3 | |
# Warning: The database defined as "test" will be erased and | |
# re-generated from your development database when you run "rake". | |
# Do not set this db to the same as development or production. | |
test: | |
<<: *default | |
database: data/test.sqlite3 | |
production: | |
<<: *default | |
database: /data/production.sqlite3 |
This file contains 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
service: <app name> | |
image: <image> | |
servers: | |
- <server ip> | |
registry: | |
server: registry.digitalocean.com | |
username: | |
- KAMAL_REGISTRY_PASSWORD | |
password: | |
- KAMAL_REGISTRY_PASSWORD | |
env: | |
secret: | |
- RAILS_MASTER_KEY | |
volumes: | |
- data:/data |
This file contains 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
#!/bin/bash -e | |
# If running the rails server then create or migrate existing database | |
if [ "${*}" == "./bin/rails server" ]; then | |
./bin/rails db:prepare | |
fi | |
exec "${@}" |
This file contains 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
# syntax = docker/dockerfile:1 | |
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile | |
ARG RUBY_VERSION=3.2.2 | |
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base | |
# Rails app lives here | |
WORKDIR /rails | |
# Set production environment | |
ENV RAILS_ENV="production" \ | |
BUNDLE_DEPLOYMENT="1" \ | |
BUNDLE_PATH="/usr/local/bundle" \ | |
BUNDLE_WITHOUT="development" | |
# Throw-away build stage to reduce size of final image | |
FROM base as build | |
# Install packages needed to build gems and node modules | |
RUN apt-get update -qq && \ | |
apt-get install --no-install-recommends -y build-essential curl git libvips node-gyp pkg-config python-is-python3 | |
# Install JavaScript dependencies | |
ARG NODE_VERSION=18.17.1 | |
ARG YARN_VERSION=1.22.19 | |
ENV PATH=/usr/local/node/bin:$PATH | |
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \ | |
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \ | |
npm install -g yarn@$YARN_VERSION && \ | |
rm -rf /tmp/node-build-master | |
# Install application gems | |
COPY Gemfile Gemfile.lock ./ | |
RUN bundle install && \ | |
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ | |
bundle exec bootsnap precompile --gemfile | |
# Install node modules | |
COPY package.json yarn.lock ./ | |
RUN yarn install --frozen-lockfile | |
# Copy application code | |
COPY . . | |
# Precompile bootsnap code for faster boot times | |
RUN bundle exec bootsnap precompile app/ lib/ | |
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY | |
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile | |
# Final stage for app image | |
FROM base | |
# Install packages needed for deployment | |
RUN apt-get update -qq && \ | |
apt-get install --no-install-recommends -y curl libsqlite3-0 libvips && \ | |
rm -rf /var/lib/apt/lists /var/cache/apt/archives | |
# Copy built artifacts: gems, application | |
COPY --from=build /usr/local/bundle /usr/local/bundle | |
COPY --from=build /rails /rails | |
# Run and own only the runtime files as a non-root user for security | |
RUN useradd rails --create-home --shell /bin/bash && \ | |
chown -R rails:rails db log storage tmp | |
USER rails:rails | |
# Entrypoint prepares the database. | |
ENTRYPOINT ["/rails/bin/docker-entrypoint"] | |
# Start the server by default, this can be overwritten at runtime | |
EXPOSE 3000 | |
CMD ["./bin/rails", "server"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
oh man.. thanks a lot. this GIST helped me a lot! You guys are awesome - thank you for providing the proper details.
I also had the same issue as described above - the proper solution was to add the directory to the
chown
command!