Closed johndmulhausen closed 2 years ago
Hi, thanks for the PR! A couple of thoughts on this:
Currently the Dockerfile is running the webpack development server over port 3808 which is not ideal if the goal is self-hosting in production (it would be more appropriate if this were a Dockerfile for use in development). Instead you can add a RUN TARGET=production npm run build
after the yarn install
line, and then make sure the RAILS_ENV
var is set to production
so that Rails looks for the prebuilt assets rather than the dev server. And then you don't need to expose port 3808 or have the host stuff.
How does this work with postgres? Currently the app tries to connect to postgres via the connection string in the DATABASE_URL env variable which doesn't seem like it would work here.
@schneidmaster Tried to make these changes but it just ceases to run. Perhaps you can try to help?
FROM ruby:2.4.5
# Install redis, sudo, nodejs, postgresql, and yarn
# redis & sudo
RUN apt-get update && apt-get -y install redis-server sudo
# node
RUN curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
RUN sudo apt-get install -y nodejs
# postgresql
RUN sudo apt-get -y install wget ca-certificates
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
RUN sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
RUN sudo apt-get update
RUN sudo apt-get -y install postgresql postgresql-contrib
# yarn
RUN npm install -g yarn
# Set ENV vars
ENV RAILS_ENV production
ENV TARGET production
ENV DATABASE_URL postgresql://localhost
# Set up working dir
RUN mkdir /app
WORKDIR /app
COPY . /app/
# Install app dependencies
RUN gem install foreman
RUN bundle install -j 8
RUN yarn install
# Run build
RUN npm run build
# Expose port 5000 from within the container to the world
EXPOSE 5000
# Start the Rails and webpack servers
CMD service postgresql start && redis-server --daemonize yes && bundle exec rails db:migrate && foreman start -f Procfile.dev
It just dies when running:
rails aborted!
URI::InvalidURIError: bad URI(is not URI?):
/usr/local/bundle/gems/sentry-raven-2.6.0/lib/raven/configuration.rb:212:in `server='
Sorry for the delay. I think the issue is this line:
which initializes Sentry for error reporting in production. That can likely be fixed by changing the conditional on the first line to if Rails.env.production? && ENV['SENTRY_DSN']
, i.e. don't try to initialize Sentry if there's no SENTRY_DSN
env var set.
Trying to Dockerize gitreports.com to make it easy to self-host
To run:
Then you can run:
And the service will be available at
http://localhost:5000