Skip to content

Commit

Permalink
Merge pull request #145 from fly-apps/pick-only-one-database
Browse files Browse the repository at this point in the history
Pick only one database.
  • Loading branch information
rubys authored Feb 21, 2025
2 parents 2fb907d + e505a3f commit 78843dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
23 changes: 15 additions & 8 deletions lib/dockerfile-rails/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,30 @@ def scan_rails_app

### database ###

# start by checkout config/database.yml. It defaults to sqlite3,
# but we can't rely on that because DATABASE_URL can override it.
# if we see anything else, assume the change was intentional.
database = YAML.load_file("config/database.yml", aliases: true).
dig("production", "adapter") rescue nil

if database == "sqlite3"
@sqlite3 = true
elsif database == "postgresql"
if database == "postgresql"
@postgresql = true
elsif (database == "mysql") || (database == "mysql2") || (database == "trilogy")
@mysql = true
elsif database == "sqlserver"
@sqlserver = true
end

@sqlite3 = true if @gemfile.include? "sqlite3"
@postgresql = true if @gemfile.include? "pg"
@mysql = true if @gemfile.include?("mysql2") || using_trilogy?
@sqlserver = true if @gemfile.include?("activerecord-sqlserver-adapter")
## if not found (or sqlite3), check the Gemfile
elsif @gemfile.include? "pg"
@postgresql = true
elsif @gemfile.include?("mysql2") || using_trilogy?
@mysql = true
elsif @gemfile.include?("activerecord-sqlserver-adapter")
@sqlserver = true
elsif @gemfile.include?("sqlite3") || database == "sqlite3"
# check this one last as sqlite3 may be used in development
@sqlite3 = true
end

### node modules ###

Expand Down
4 changes: 2 additions & 2 deletions test/results/trilogy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN gem update --system --no-document && \

# Install base packages
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl default-mysql-client libjemalloc2 sqlite3 && \
apt-get install --no-install-recommends -y curl default-mysql-client libjemalloc2 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Set production environment
Expand All @@ -35,7 +35,7 @@ FROM base AS build

# Install packages needed to build gems
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential libyaml-dev pkg-config && \
apt-get install --no-install-recommends -y build-essential libyaml-dev && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Install application gems
Expand Down

0 comments on commit 78843dd

Please sign in to comment.