-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch to sqlite3, added docker image
- Loading branch information
1 parent
cd4c148
commit 0fde257
Showing
8 changed files
with
156 additions
and
200 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,61 @@ | ||
# syntax = docker/dockerfile:1 | ||
|
||
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile | ||
# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand: | ||
# docker build -t my-app . | ||
# docker run -d -p 80:80 -p 443:443 --name my-app -e RAILS_MASTER_KEY=<value from config/master.key> my-app | ||
|
||
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version | ||
ARG RUBY_VERSION=3.3.0 | ||
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base | ||
FROM docker.io/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" | ||
# Install base packages | ||
RUN apt-get update -qq && \ | ||
apt-get install --no-install-recommends -y curl libjemalloc2 sqlite3 libvips && \ | ||
rm -rf /var/lib/apt/lists /var/cache/apt/archives | ||
|
||
ENV RAILS_ENV="development" \ | ||
BUNDLE_DEPLOYMENT="1" \ | ||
BUNDLE_PATH="/usr/local/bundle" | ||
|
||
# Throw-away build stage to reduce size of final image | ||
FROM base as build | ||
FROM base AS build | ||
|
||
# Install packages needed to build gems | ||
RUN apt-get update -qq && \ | ||
apt-get install --no-install-recommends -y build-essential git libpq-dev libvips pkg-config | ||
apt-get install --no-install-recommends -y build-essential git pkg-config && \ | ||
rm -rf /var/lib/apt/lists /var/cache/apt/archives | ||
|
||
# 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 | ||
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git | ||
|
||
# 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 libvips postgresql-client && \ | ||
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 "${BUNDLE_PATH}" "${BUNDLE_PATH}" | ||
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 && \ | ||
RUN groupadd --system --gid 1000 rails && \ | ||
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ | ||
chown -R rails:rails db log storage tmp | ||
USER rails:rails | ||
USER 1000:1000 | ||
|
||
# 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"] | ||
CMD ["./bin/rails", "server", "-b", "0.0.0.0"] |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,30 @@ If you want to use sample data (products, categories), you can load it using the | |
bin/rake spree_sample:load | ||
``` | ||
|
||
#### Full docker setup | ||
|
||
If you're having trouble with Ruby/etc setup and just want to get everything up and running, you can use the following command to start the docker containers. | ||
|
||
```bash | ||
docker pull vendoconnect/spree_starter | ||
docker run -p 3000:3000 vendoconnect/spree_starter | ||
``` | ||
|
||
This will start the docker containers and automatically start the rails server. | ||
|
||
To sign in into the admin dashboard go to `https://localhost:3000/admin` and use the following credentials: | ||
|
||
```bash | ||
Email: [email protected] | ||
Password: spree123 | ||
``` | ||
|
||
### Switching to PostgreSQL | ||
|
||
```bash | ||
bin/rails db:system:change --to=postgresql | ||
``` | ||
|
||
### Switching to MySQL | ||
|
||
By default, Spree Starter uses PostgreSQL. If you want to switch to MySQL, you can do so by running the following command: | ||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,25 @@ | ||
# PostgreSQL. Versions 9.3 and up are supported. | ||
# SQLite. Versions 3.8.0 and up are supported. | ||
# gem install sqlite3 | ||
# | ||
# Install the pg driver: | ||
# gem install pg | ||
# On macOS with Homebrew: | ||
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config | ||
# On Windows: | ||
# gem install pg | ||
# Choose the win32 build. | ||
# Install PostgreSQL and put its /bin directory on your path. | ||
# | ||
# Configure Using Gemfile | ||
# gem "pg" | ||
# Ensure the SQLite 3 gem is defined in your Gemfile | ||
# gem "sqlite3" | ||
# | ||
default: &default | ||
adapter: postgresql | ||
encoding: unicode | ||
# For details on connection pooling, see Rails configuration guide | ||
# https://guides.rubyonrails.org/configuring.html#database-pooling | ||
adapter: sqlite3 | ||
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | ||
timeout: 5000 | ||
|
||
development: | ||
<<: *default | ||
database: spree_starter_development | ||
host: <%= ENV.fetch("DB_HOST", "localhost") %> | ||
username: <%= ENV.fetch("DB_USERNAME", "postgres") %> | ||
|
||
# The specified database role being used to connect to PostgreSQL. | ||
# To create additional roles in PostgreSQL see `$ createuser --help`. | ||
# When left blank, PostgreSQL will use the default role. This is | ||
# the same name as the operating system user running Rails. | ||
#username: spree_starter | ||
|
||
# The password associated with the PostgreSQL role (username). | ||
#password: | ||
|
||
# Connect on a TCP socket. Omitted by default since the client uses a | ||
# domain socket that doesn't need configuration. Windows does not have | ||
# domain sockets, so uncomment these lines. | ||
#host: localhost | ||
|
||
# The TCP port the server listens on. Defaults to 5432. | ||
# If your server runs on a different port number, change accordingly. | ||
#port: 5432 | ||
|
||
# Schema search path. The server defaults to $user,public | ||
#schema_search_path: myapp,sharedapp,public | ||
|
||
# Minimum log levels, in increasing order: | ||
# debug5, debug4, debug3, debug2, debug1, | ||
# log, notice, warning, error, fatal, and panic | ||
# Defaults to warning. | ||
#min_messages: notice | ||
database: storage/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: spree_starter_test | ||
host: <%= ENV.fetch("DB_HOST", "localhost") %> | ||
username: <%= ENV.fetch("DB_USERNAME", "postgres") %> | ||
database: storage/test.sqlite3 | ||
|
||
# As with config/credentials.yml, you never want to store sensitive information, | ||
# like your database password, in your source code. If your source code is | ||
# ever seen by anyone, they now have access to your database. | ||
# | ||
# Instead, provide the password or a full connection URL as an environment | ||
# variable when you boot the app. For example: | ||
# | ||
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" | ||
# | ||
# If the connection URL is provided in the special DATABASE_URL environment | ||
# variable, Rails will automatically merge its configuration values on top of | ||
# the values provided in this file. Alternatively, you can specify a connection | ||
# URL environment variable explicitly: | ||
# | ||
# production: | ||
# url: <%= ENV["MY_APP_DATABASE_URL"] %> | ||
# | ||
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database | ||
# for a full overview on how database connection configuration can be specified. | ||
# | ||
production: | ||
<<: *default | ||
url: <%= ENV["DATABASE_URL"] %> | ||
database: storage/production.sqlite3 |
Oops, something went wrong.