Hi I am using docker to deploy my rails app using phusion/passenger image. Here is my Dockerfile:
FROM phusion/passenger-ruby22:0.9.19
# set correct environment variables
ENV HOME /root
ENV RAILS_ENV production
# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]
# Expose Nginx HTTP service
EXPOSE 80
# Start Nginx / Passenger
RUN rm -f /etc/service/nginx/down
# Remove the default site
RUN rm /etc/nginx/sites-enabled/default
# Add the nginx site and config
ADD nginx.conf /etc/nginx/sites-enabled/nginx.conf
ADD rails-env.conf /etc/nginx/main.d/rails-env.conf
# Let ensure these packages are already installed
# otherwise install them anyways
RUN apt-get update && apt-get install -y build-essential \
nodejs \
libpq-dev
# bundle gem and cache them
WORKDIR /tmp
ADD Gemfile /tmp/
ADD Gemfile.lock /tmp/
RUN gem install bundler
RUN bundle install
# Add rails app
ADD . /home/app/webapp
WORKDIR /home/app/webapp
RUN touch log/delayed_job.log log/production.log log/
RUN chown -R app:app /home/app/webapp
RUN RAILS_ENV=production rake assets:precompile
# Clean up APT and bundler when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
I am getting permission issue for tmp and log files.
web_1 | [ 2016-07-19 08:45:12.6653 31/7ff812726700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /home/app/webapp: An error occurred while starting up the preloader.
web_1 | Error ID: 42930e85
web_1 | Error details saved to: /tmp/passenger-error-9DeJ86.html
web_1 | Message from application: Permission denied # rb_sysopen - log/logentries.log (Errno::EACCES)
web_1 | /usr/lib/ruby/2.2.0/logger.rb:628:in `initialize'
web_1 | /usr/lib/ruby/2.2.0/logger.rb:628:in `open'
web_1 | /usr/lib/ruby/2.2.0/logger.rb:628:in `open_logfile'
web_1 | /usr/lib/ruby/2.2.0/logger.rb:584:in `initialize'
web_1 | /usr/lib/ruby/2.2.0/logger.rb:318:in `new'
web_1 | /usr/lib/ruby/2.2.0/logger.rb:318:in `initialize'
web_1 | /var/lib/gems/2.2.0/gems/le-2.7.2/lib/le/host/http.rb:37:in `new'
web_1 | /var/lib/gems/2.2.0/gems/le-2.7.2/lib/le/host/http.rb:37:in `initialize'
I tried to give chmod -R 665/775/777 log/ and still didn't fixed the problem.
Thanks
Rearrange your line RUN RAILS_ENV=production rake assets:precompile first then RUN chown -R app:app /home/app/webapp(after your rake task) So, It should be something like this:
RUN RAILS_ENV=production rake assets:precompile
RUN chown -R app:app /home/app/webapp
Related
I am new to linunx and pipenv. I tried to install django on my new environment with "pipenv install django" and this happend:
Installing django…
Adding django to Pipfile's [packages]…
✔ Installation Succeeded
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✔ Success!
Updated Pipfile.lock (4f9dd2)!
Installing dependencies from Pipfile.lock (4f9dd2)…
An error occurred while installing asgiref==3.2.5 --hash=sha256:3e4192eaec0758b99722f0b0666d5fbfaa713054d92e8de5b58ba84ec5ce696f --hash=sha256:c8f49dd3b42edcc51d09dd2eea8a92b3cfc987ff7e6486be734b4d0cbfd5d315! Will try again.
An error occurred while installing django==3.0.4 --hash=sha256:50b781f6cbeb98f673aa76ed8e572a019a45e52bdd4ad09001072dfd91ab07c8 --hash=sha256:89e451bfbb815280b137e33e454ddd56481fdaa6334054e6e031041ee1eda360! Will try again.
An error occurred while installing pytz==2019.3 --hash=sha256:1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d --hash=sha256:b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be! Will try again.
An error occurred while installing sqlparse==0.3.1 --hash=sha256:022fb9c87b524d1f7862b3037e541f68597a730a8843245c349fc93e1643dc4e --hash=sha256:e162203737712307dfe78860cc56c8da8a852ab2ee33750e33aeadf38d12c548! Will try again.
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 4/4 — 00:00:00
Installing initially failed dependencies…
☤ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 4/4 — 00:00:00
[pipenv.exceptions.InstallError]: File "/home/codrut/.local/lib/python3.7/site-packages/pipenv/cli/command.py", line 254, in install
[pipenv.exceptions.InstallError]: editable_packages=state.installstate.editables,
[pipenv.exceptions.InstallError]: File "/home/codrut/.local/lib/python3.7/site-packages/pipenv/core.py", line 1992, in do_install
[pipenv.exceptions.InstallError]: skip_lock=skip_lock,
[pipenv.exceptions.InstallError]: File "/home/codrut/.local/lib/python3.7/site-packages/pipenv/core.py", line 1253, in do_init
[pipenv.exceptions.InstallError]: pypi_mirror=pypi_mirror,
[pipenv.exceptions.InstallError]: File "/home/codrut/.local/lib/python3.7/site-packages/pipenv/core.py", line 862, in do_install_dependencies
[pipenv.exceptions.InstallError]: _cleanup_procs(procs, False, failed_deps_queue, retry=False)
[pipenv.exceptions.InstallError]: File "/home/codrut/.local/lib/python3.7/site-packages/pipenv/core.py", line 681, in _cleanup_procs
[pipenv.exceptions.InstallError]: raise exceptions.InstallError(c.dep.name, extra=err_lines)
[pipenv.exceptions.InstallError]: []
[pipenv.exceptions.InstallError]: ['Traceback (most recent call last):', ' File "/home/codrut/.local/share/virtualenvs/Django-B9r4LqTh/bin/pip", line 5, in <module>', ' from pip._internal.cli.main import main', "ModuleNotFoundError: No module named 'pip'"]
ERROR: ERROR: Package installation failed...
To mention that a few minutes ago I installed django on a wrong folder and everything worked..
Please help! Thank you!
In the main directory root add the following command to create the environment:
$ python3 -m venv venv this code will create a folder called venv in the root. Which basically is the virtual environment folder.
Then add the following command to activate the virtual environment:
$ source venv/bin/activate
your_project_folder/
|
|-- your_main_app_folder/
| |
| |--Folder_with_controllers/
| | settings.py
| | urls.py
| | ...
| |
| |--App_folder/
| |--Other_app_folder/
|
|--venv/
If the code works fine your bash should look like this:
(venv) <the_path_for_the_folder> your_project_folder %
After activated your environment you can now install django and other packages.
Ps: make sure you instal and activate the virtual environment folder not in the your_main_app_folder.
I have a django app which runs fine on local. But when I build the docker image and run the app from within the container, it runs fine and return status 200, but after some time it again returns status 400 with message, input fields are blank.
Operations to perform:
Apply all migrations: admin, auth, authtoken, contenttypes, sessions
Running migrations:
No migrations to apply.
No changes detected
Performing system checks...
System check identified no issues (0 silenced).
March 25, 2020 - 12:09:24
Django version 1.11.23, using settings 'TestSop.settings'
Starting development server at http://0.0.0.0:8016/
Quit the server with CONTROL-C.
[25/Mar/2020 12:09:35] "GET /TestSopApiView/ HTTP/1.1" 405 12315
[25/Mar/2020 12:09:41] "GET /TestSopApiView/ HTTP/1.1" 405 12315
[25/Mar/2020 12:10:03] "POST /TestSopApiView/ HTTP/1.1" 200 205
[25/Mar/2020 12:11:23] "POST /TestSopApiView/ HTTP/1.1" 400 189
{"field1":["This field may not be blank."],"field2":["This field may not be blank."],"field3":["This field may not be blank."],"field4":["This field may not be blank."]}
This is my Dockerfile-
FROM python:3.7
#Create Directory in Container
ADD . /TestSop
WORKDIR /TestSop
COPY entrypoint.sh entrypoint.sh
RUN pip install -r requirements.txt
EXPOSE 8016
RUN apt-get -y update && apt-get -y upgrade && apt-get install -y curl && apt-get install -y jq
RUN chmod +x /TestSop/entrypoint.sh
RUN touch /TestSop/TestSop.log
RUN chmod 777 /TestSop/TestSop.log
ENTRYPOINT ["/TestSop/entrypoint.sh"]
entrypoint.sh -
#!/bin/sh
python /TestSop/manage.py makemigrations &
python /TestSop/manage.py migrate &
python /TestSop/manage.py runserver 0.0.0.0:8016 &
sleep 2m
curl_output=$(curl -X POST -s -H "Content-Type: application/json" -d '{"field1": "'"$field1"'","field2":"'"$field2"'","field3":"'"$field3"'","field4":"'"$field4"'"}' http://127.0.0.1:8016/TestSopApiView/)
echo $curl_output
result=$(echo $curl_output | jq ".result")
if [ "${result}" = "\"fail\"" ]
then
exit 255
else
exit 0
fi
exec "$#"
Can you tell me why there is this second run happening with 400 status inside the container? It does not seem to cause any error though. Thank you in advance.
I'm running a Django app with uWSGI in Docker with docker-compose. I get the same error every time I:
Send a POST request with AJAX
In handling said request in my view, I use python's requests module, i.e. r = requests.get(some_url)
uWSGI says the following:
!!! uWSGI process 13 got Segmentation Fault !!!
DAMN ! worker 1 (pid: 13) died :( trying respawn ...
Respawned uWSGI worker 1 (new pid: 24)
spawned 4 offload threads for uWSGI worker 1
The console in the browser says net::ERR_EMPTY_RESPONSE
I've tried using the requests module in different places, and wherever I put it I get the same Segmentation Fault error. I'm also able to run everything fine outside of docker with no errors, so I've narrowed it down to: docker + requests module = errror.
Is there something that could be blocking the requests sent with the requests module from within the docker container? Thanks in advance for your help.
Here's my uwsgi.ini file:
[uwsgi]
chdir = %d
module = my_project.wsgi:application
master = true
processes = 2
http = 0.0.0.0:8000
vacuum = true
pidfile = /tmp/my_project.pid
daemonize = %d/my_project.log
check-static = %d
static-expires = /* 7776000
offload-threads = %k
uid = 1000
gid = 1000
# there is no /etc/mime.types on the docker Arch Linux image
mime-file = %d/mime.types
Dockerfile:
FROM alpine:3.8
ENV PYTHONUNBUFFERED 1
RUN mkdir /my_project
WORKDIR /my_project
RUN apk add build-base python3-dev py3-pip python3
# deps for python cryptography
RUN apk add libffi-dev musl-dev openssl-dev
# dep for uwsgi
RUN apk add linux-headers
ADD requirements.txt /my_project/
RUN pip3 install -r requirements.txt
ADD . /my_project/
ENTRYPOINT ./start.sh
docker-compose.yml:
version: '3'
services:
web:
build: .
entrypoint: ./start.sh
volumes:
- .:/my_project
ports:
- "8000:8000"
environment:
- DEBUG_LEVEL=INFO
network_mode: "host"
start.sh:
#!/bin/sh
echo '' > logfile.log
uwsgi --ini uwsgi.ini
tail -f logfile.log
Solution: Change base image to Ubuntu 16.04 and everything works fine now.
I have a problem with my configuration supervisor, my file is in etc/supervisor/conf.d/realtimecolonybit.conf,
When I try command supervisorctl reread, show me the "No config updates to processes" and when I try the other command like this
supervisorctl status realtimecolonybit
Shows me this error
realtimecolonybit FATAL can't find command '/home/ubuntu/realtimecolonybit/bin/start.sh;'
And when try the supervisorctl start realtimecolonybit
show me this error
realtimecolonybit: ERROR (no such file)
My configuration in my file realtimecolonybit.conf is below
[program:realtimecolonybit]
command = /home/ubuntu/realtimecolonybit/bin/start.sh;
user = root
stdout_logfile = /home/ubuntu/realtimecolonybit/logs/realtimecolonybit.log;
redirect_strderr = true;
My configuration from my file start.sh is below
#!/bin/bash
NAME="realtimecolonybit"
DJANGODIR=/home/ubuntu/realtimecolonybit/colonybit
SOCKFILE=/home/ubuntu/realtimecolonybit/run/gunicorn.sock
USER=root
GROUP=root
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=colonybit.settings
echo "Starting $NAME as `whoami`"
cd $DJANGODIR
source /home/ubuntu/realtimecolonybit/bin/activate
# workon realtimecolonybit
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPAHT=$DJANGODIR:$PYTHONPATH
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
exec daphne -b 0.0.0.0 -p 8001 colonybit.asgi:application
When I run without supervisor like this
(realtimecolonybit)realtimecolonybit/#/ ./bin/start.sh
it's run ok and working well, but sometimes down the server
I try to run a Django 1.11 and django_channel with supervisor my app is in aws.
I solve my problem, the error was in file .conf, I remove ; and remove the .sh, change the start.sh to start
wrong command
command = /home/ubuntu/realtimecolonybit/bin/start.sh;
correct command
command = /home/ubuntu/realtimecolonybit/bin/start
I am trying to deploy a test site which made using Django and virtualenvwrapper. I want to use nginx for requests.I used Taskbuster's tutorial. So my project layer is similar as below :
--abctasarim **main folder
--manage.py **django manage file
----/yogavidya ** project folder
----/yogavidya/wsgi.py **wsgi file
----/yogavidya/settings/base.py ***settings
I prepared a script to use with gunicorn. I addressed virtualenv to virtualenvwrapper envs
#!/bin/bash
NAME="yogavidya" #Name of the application (*)
DJANGODIR=/home/ytsejam/public_html/abctasarim # Django project directory (*)
SOCKFILE=/home/ytsejam/public_html/abctasarim/run/gunicorn.sock # we will communicate using this unix socket (*)
USER=ytsejam # the user to run as (*)
GROUP=webdata # the group to run as (*)
NUM_WORKERS=1 # how many worker processes should Gunicorn spawn (*)
DJANGO_SETTINGS_MODULE=yogavidya.settings.base # which settings file should Django use (*)
DJANGO_WSGI_MODULE=yogavidya.wsgi # WSGI module name (*)
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source /home/ytsejam/.virtualenvs/yv_dev/bin/activate
#export /home/ytsejam/.virtualenvs/yv_dev/bin/postactivate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec /home/ytsejam/public_html/abctasarim/gunicorn \
--name $NAME \
--workers $NUM_WORKERS \
--env DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE \
--pythonpath $DJANGODIR \
--user $USER \
--bind=unix:$SOCKFILE yogavidya.wsgi:application
When I try to run it , I am getting an error for my service file :
...
ImportError: No module named ' '
...
How can I fix my script to serve the site correctly ?
Thanks
virtualenvwrapper is supposed to be what you use in development. You want to deploy using the package that virtualenvwrapper is built on—the virtualenv package. The best suggestion I have for you for how to make this work would be to try the steps that you would normally use to start your virtualenvwrapper environment, namely sourcing the shell script and then using workon:
NAME="yogavidya" #Name of the application (*)
DJANGODIR=/home/ytsejam/public_html/abctasarim # Django project directory (*)
SOCKFILE=/home/ytsejam/public_html/abctasarim/run/gunicorn.sock # we will communicate using this unix socket (*)
USER=ytsejam # the user to run as (*)
GROUP=webdata # the group to run as (*)
NUM_WORKERS=1 # how many worker processes should Gunicorn spawn (*)
DJANGO_SETTINGS_MODULE=yogavidya.settings.base # which settings file should Django use (*)
DJANGO_WSGI_MODULE=yogavidya.wsgi # WSGI module name (*)
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGO_DIR
source /path/to/virtualenvwrapper.sh
workon yv_dev
You should also just try invoking gunicorn from the command line after activating your virtualenv.
Here’s how you can do it with virtualenv:
cd /home/ytsejam/public_html/abctasarim
sudo pip install virtualenv
virtualenv .
. bin/activate
pip install -r requirements.txt
pip install gunicorn
gunicorn script:
NAME="yogavidya" #Name of the application (*)
DJANGODIR=/home/ytsejam/public_html/abctasarim # Django project directory (*)
SOCKFILE=/home/ytsejam/public_html/abctasarim/run/gunicorn.sock # we will communicate using this unix socket (*)
USER=ytsejam # the user to run as (*)
GROUP=webdata # the group to run as (*)
NUM_WORKERS=1 # how many worker processes should Gunicorn spawn (*)
cd $DJANGO_DIR
. bin/activate
# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
exec /home/ytsejam/public_html/abctasarim/bin/gunicorn \
--name $NAME \
--workers $NUM_WORKERS \
--user $USER \
--bind=unix:$SOCKFILE yogavidya.wsgi:application