utensils / docker-lobsters

Lobsters in a minimal Docker container.
https://github.com/lobsters/
MIT License
60 stars 41 forks source link

already have nginx installed on server.... #4

Open ralyodio opened 5 years ago

ralyodio commented 5 years ago

How can I just expose the app on port 3000 so I can use my existing nginx proxy to server the application? Specifically what changes do I need to make to docker?

jamesbrink commented 5 years ago

I don't think you need to make any changes to the Dockerfile as it already exposes port 3000. If you are running nginx on your local host you can probably just alter the docker-compose to something like this, removing the nginx proxy and the depends_on statement under the app for nginx proxy.

version: '2.1'

services:
  database:
    image: mariadb
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_DATABASE=lobsters
    healthcheck:
      test: "/usr/bin/mysql --user=root --password=password --execute \"SHOW DATABASES;\""
      timeout: 5s
      retries: 20
    volumes:
      - 'lobsters_database:/var/lib/mysql'
  app:
    build:
      context: .
      args:
        developer_build: "false"
    environment:
      - MARIADB_HOST=database
      - MARIADB_PORT=3306
      - MARIADB_PASSWORD=password
      - MARIADB_USER=root
      - LOBSTER_DATABASE=lobsters
      - LOBSTER_SITE_NAME="Example News"
      - RAILS_ENV=development
      - LOBSTER_HOSTNAME=localhost
      - VIRTUAL_HOST=localhost
      - RAILS_MAX_THREADS=5
    ports:
      - "3000:3000"
    depends_on:
      database:
        condition: service_healthy

volumes:
  lobsters_database:
    driver: local
jamesbrink commented 5 years ago

@chovy let me know if the above works for you, if not please give some additional details on your environment.

ralyodio commented 5 years ago

I will try, another problem I'm having is I want to use a Mailgun SMTP server for sending email.

jamesbrink commented 5 years ago

I am not sure how to setup mailgun, but I just took some time to update this repo, so you might want to pull the new changes. I setup the build in circle-ci and updated the git submodule of lobsters to the most current git commit.

I did this as i noticed the old build was no longer working

jamesbrink commented 5 years ago

the docker-compose now uses the pre-built image from https://hub.docker.com/r/utensils/lobsters but it can be built locally use make. I will update the Readme tomorrow with the information.

jamesbrink commented 5 years ago

With these new updates, you could pull try the following docker-compose

version: '2.1'

services:
  database:
    image: mariadb
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_DATABASE=lobsters
    healthcheck:
      test: "/usr/bin/mysql --user=root --password=password --execute \"SHOW DATABASES;\""
      timeout: 5s
      retries: 20
    volumes:
      - 'lobsters_database:/var/lib/mysql'
  app:
    image: utensils/lobsters:latest
    build:
      context: .
      args:
        DEVELOPER_BUILD: "false"
    environment:
      - MARIADB_HOST=database
      - MARIADB_PORT=3306
      - MARIADB_PASSWORD=password
      - MARIADB_USER=root
      - LOBSTER_DATABASE=lobsters
      - LOBSTER_SITE_NAME="Example News"
      - RAILS_ENV=development
      - LOBSTER_HOSTNAME=localhost
      - VIRTUAL_HOST=localhost
      - RAILS_MAX_THREADS=5
    ports:
      - "3000:3000"
    depends_on:
      database:
        condition: service_healthy

volumes:
  lobsters_database:
    driver: local
ralyodio commented 5 years ago

I need to configure the SMTP server somehow.

jamesbrink commented 5 years ago

@chovy there are ENV variables setup for using SMTP

From the Dockerfile

    SMTP_HOST="127.0.0.1" \
    SMTP_PORT="25" \
    SMTP_STARTTLS_AUTO="true" \
    SMTP_USERNAME="lobsters" \
    SMTP_PASSWORD="lobsters"

So given the previous docker-compose example you could simply add those variables.

version: '2.1'

services:
  database:
    image: mariadb
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_DATABASE=lobsters
    healthcheck:
      test: "/usr/bin/mysql --user=root --password=password --execute \"SHOW DATABASES;\""
      timeout: 5s
      retries: 20
    volumes:
      - 'lobsters_database:/var/lib/mysql'
  app:
    image: utensils/lobsters:latest
    build:
      context: .
      args:
        DEVELOPER_BUILD: "false"
    environment:
      - MARIADB_HOST=database
      - MARIADB_PORT=3306
      - MARIADB_PASSWORD=password
      - MARIADB_USER=root
      - LOBSTER_DATABASE=lobsters
      - LOBSTER_SITE_NAME="Example News"
      - RAILS_ENV=development
      - LOBSTER_HOSTNAME=localhost
      - VIRTUAL_HOST=localhost
      - RAILS_MAX_THREADS=5
      - SMTP_HOST="your.smtp.host.com"
      - SMTP_PORT="25"
      - SMTP_STARTTLS_AUTO="true"
      - SMTP_USERNAME="yoursmtpusername"
      - SMTP_PASSWORD="yoursmtppass"
    ports:
      - "3000:3000"
    depends_on:
      database:
        condition: service_healthy

volumes:
  lobsters_database:
    driver: local
ralyodio commented 5 years ago

ahh ok. Trying now. Thanks.

ralyodio commented 5 years ago

I tried connection to localhost:3000 but it isn't up.

ralyodio commented 5 years ago

So I got it working, but mail still won't send. It says it can't find the config/initailizers/mail script

app_1_8dd569ff291a | ruby: No such file or directory -- script/mail_new_activity (LoadError)

jamesbrink commented 5 years ago

Ah I see this, i think the renamed the file upstream. I will fix this now

jamesbrink commented 5 years ago

if you pull the newest docker image docker pull utensils/lobsters:latest then start it up again it should be fixed. I did notice it throws an Nil Class error, but I think this stops erroring once their is content on the site. That mailer script runs every 5 minutes. I don't have an SMTP service setup to test and verify, but I was able to verify they did re-name the file so I just updated the entrypoint script.

ralyodio commented 5 years ago

Just an fyi, you can't use quotes in docker-compose for environemnt variables. They show up in the values.

Also I read that docker-compose will look for a .env file in the root so that would be a better way of adding environment variables.

I still get this error:

app_1_8dd569ff291a | ruby: No such file or directory -- script/mail_new_activity (LoadError)

ralyodio commented 5 years ago

app_1_8dd569ff291a | script/mail_new_activity.rb:146:in

': undefined method id' for nil:NilClass (NoMethodError)

jamesbrink commented 5 years ago

@chovy this is the NilClass error i mentioned earlier, i think you can safely ignore it. once you have stories and comments it stops erroring. I think they really just need to put in a check for nil in that script. I doub't they ever see it because it only happens on fresh empty site. I added a story locally, changed a few things and it stopped coming back with that error. like i said it runs every 5 minutes so it can be safely ignored.

jamesbrink commented 5 years ago

Also I read that docker-compose will look for a .env file in the root so that would be a better way of adding environment variables.

I will look into adding this, that is probably a better idea. This project could use some work, I no longer run this anymore, but I do try to maintain the repo for others. I did run it for a bit with no issues, now the biggest issue is just keeping it updated :)

ralyodio commented 5 years ago

did you have to make a lot of customizations to lobsters code?

ralyodio commented 5 years ago

I got mail working! I had to use smtp.mailgun.org port 587. Shit works now! thank you!

ralyodio commented 5 years ago

Something broke. I'm now getting this error.

sendmail: can't connect to remote host (127.0.0.1): Connection refused -- seems to be ignoring the docker-compose env. variables

XuebinMa commented 4 years ago

@chovy I got my smtp server worked .

  1. Edit the file: ~/docker-lobsters/Dockfile and change the variables like "SMPT_****".
  2. Edit the file: ~/docker-lobsters/lobsters/app/mailers/invitation_mailer.rb and change the "nobody" to your user name of your email address .
anon238 commented 3 years ago

Something broke. I'm now getting this error.

sendmail: can't connect to remote host (127.0.0.1): Connection refused -- seems to be ignoring the docker-compose env. variables

You cannot use localhost!!!