Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some issue while dockerizing the application #15

Closed
yalamber opened this issue Oct 10, 2023 · 8 comments
Closed

Some issue while dockerizing the application #15

yalamber opened this issue Oct 10, 2023 · 8 comments

Comments

@yalamber
Copy link

I am trying to dockerize this application to make it easier for me to deploy.
But when I run docker compose up
I receive following error
/app/app/controllers/saved_searches_controller.rb:3:in <class:SavedSearchesController>': uninitialized constant Blacklight::SavedSearches (NameError) gbl_admin_mutant-web-1 | gbl_admin_mutant-web-1 | include Blacklight::SavedSearches gbl_admin_mutant-web-1 | ^^^^^^^^^^^^^^^ gbl_admin_mutant-web-1 | Did you mean? SavedSearchesController gbl_admin_mutant-web-1 | from /app/app/controllers/saved_searches_controller.rb:2:in

'

seems like issue related to this projectblacklight/blacklight_advanced_search#105
But I am not sure why it's only having issue while running inside docker container.

@yalamber
Copy link
Author

this seems to be specific case when trying to run the rails app in production mode. Do we have any guide on how to set this up for production use case.

@ewlarson
Copy link
Contributor

Hi @yalamber

This project is still a pretty young thing, at just v0.2. It's a rewrite, as a GeoBlacklight plugin, of the Big Ten Academic Alliance's production GeoBlacklight management application: GEOMG.

We're not running GBL Admin in production for the BTAA just yet, but hopefully soon. I'll try to write up some documentation about running this in production-mode this week.

Very happy to have another developer testing the project out. Please keep the feedback coming. Cheers!

@yalamber
Copy link
Author

Hello @ewlarson,
Thank you for your contribution, we are able to test this out and so far it is looking great in development mode. I am just trying to dockerize it and also be able to run in RAILS_ENV=production, So far this is my Dockerfile and docker compose file

Dockerfile

FROM arm64v8/ruby:3.2.2-slim

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
  ca-certificates\
  gnupg \
  curl \
  postgresql-client \
  build-essential \
  libxml2-dev \
  libxslt1-dev \
  libffi-dev \
  libreadline-dev \
  libpq-dev \
  sqlite3 \
  libsqlite3-dev \
  libc6-dev \
  file \
  imagemagick \
  git \
  tzdata \
  openssh-client \
  && rm -rf /var/lib/apt/lists/*

ENV NODE_VERSION=16.13.0
RUN apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version
RUN npm install yarn -g

WORKDIR /app
COPY package*.json ./
RUN npm install --legacy-peer-deps
COPY . /app/
RUN gem install rails -v '6.1.7.4' \
  && bundle install

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh

ENTRYPOINT ["entrypoint.sh"]
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
EXPOSE 3000
version: '3'

services:
  db:
    image: postgres
    ports:
      - '5432:5432'
    volumes:
      - pgdata:/var/lib/postgresql/data
    env_file:
      - .docker.env
  solr:
    image: solr:8.4
    ports:
      - '8983:8983'
    command:
      - sh
      - "-c"
      - "solr-precreate blacklight-core /opt/solr/server/configsets/geoblacklightconf"
    volumes:
      - solrdata:/var/solr/data:cached
      - ./solr/conf:/opt/solr/server/configsets/geoblacklightconf
  redis:
    image: redis
    volumes:
      - redisdata:/data
  web:
    build: .
    volumes:
      - .:/gbl_admin
    ports:
      - '3000:3000'
    depends_on:
      - db
      - solr
      - redis
    env_file:
      - .docker.env
    command: bundle exec rails server -b 0.0.0.0

volumes:
  pgdata:
  solrdata:
  redisdata:

and entrypoint.sh

#!/bin/bash
set -e

# Check if the setup marker file exists
if [ ! -f /tmp/initialized ]; then
    # export RAILS_ENV=production
    # Run setup commands
    bundle exec rake db:migrate
    # bundle exec rails generate blacklight:install --devise
    # bundle exec rails generate geoblacklight:install --force
    # bundle exec rails generate blacklight_advanced_search:install --force
    # bundle exec rails generate geoblacklight_admin:install --force
    bundle exec rake db:seed
    bundle exec rails assets:precompile
    # bundle exec rake gbl_admin:server
    # Create a marker file to indicate setup has been done
    touch /tmp/initialized
fi

# Execute CMD
exec "$@"

@ewlarson
Copy link
Contributor

Hi again @yalamber

Outside of Docker, but just running the application in production mode on my local machine, I was able to replicate the error you encountered.

I resolved it locally via these steps.

# Replicated Error
# uninitialized constant Blacklight::SavedSearches (NameError)

# Remove the misbehaving controller -- This controller was removed from Blacklight
rm app/controllers/saved_searches_controller.rb

# Create a dotenv file for production
# Update your database connection settings as necessary
cp .env.development .env.production

# Migrate the database
RAILS_ENV=production bundle exec rake db:migrate

# Seed the database
RAILS_ENV=production bundle exec rake db:seed

# Precompile assets
RAILS_ENV=production rails assets:precompile

# Serve local assets (just for running app locally in production mode)
# In .env.production, add:
# Rails serve local assets
RAILS_SERVE_STATIC_FILES=true

RAILS_ENV=production bundle exec rake gbl_admin:server

# App runs and works as expected

@yalamber
Copy link
Author

hello @ewlarson
RAILS_ENV=production bundle exec rake gbl_admin:server will this run app in background

@yalamber
Copy link
Author

I am trying to rebuild the docker image and run in production, I am facing below error,

rake aborted!
mutant_geoblacklight_admin-web-1 | ArgumentError: Can't add, conflict with existing attribute name dct_title_s: [:dct_title_s, :string, {:container_attribute=>"json_attributes", :default=>""}]
mutant_geoblacklight_admin-web-1 | /usr/local/bundle/gems/attr_json-2.2.0/lib/attr_json/attribute_definition/registry.rb:80:in add!' mutant_geoblacklight_admin-web-1 | /usr/local/bundle/gems/attr_json-2.2.0/lib/attr_json/attribute_definition/registry.rb:71:in block (2 levels) in with'

Screenshot 2023-10-14 at 11 38 04 Is it because I am running migration again during the build?

@ewlarson
Copy link
Contributor

Hi again! AttrJson (attr_json) is the library Kithe uses for JSON attributes. I think what's happening here is your database has been seeded twice (or more), so the same attribute (dct_title_s) is in the Elements table more than once: "conflict with existing attribute name dct_title_s".

Hope that makes sense! Really, the code should have a unique key guard against the same attribute being loaded twice. I'll make an issue for that.

@yalamber
Copy link
Author

I see you have created new issue for this. Thank you closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants