error with docker-compose and django - python

I am trying to get started with docker and django. I followed the directions of docker-compose and created an image with a simple requirements.txt.
I now want to actually build out my app more and add templates and actual code.
1) i installed some modules on the host machine and added them to the requirements.txt file
2) i run (again) docker-compose run web django-admin.py startproject exampleproject. All my new requirements get downloaded but then i get this error:
/code/manage.py already exists, overlaying a project or app into an existing directory won't replace conflicting files
I am using the exact Dockerfile and docker-compose.yml as here:
http://docs.docker.com/compose/django/
how am i supposed to update the container/image with new templates/views &c and new modules as i am developing my app?
am i using docker wrong?
thanks.

I needed to remove the manage.py from the directory where i had my project (the directory where the docker-compose.yml is in).
I guess once you start a project, you install new requirements on the container itself and add them to requirements.txt for the next time you build your project from scratch.

Sorry for the late addition but I thought it might help someone. I had also encountered this same problem and inspite of removing manage.py from the folder where my .yml and Dockerfile existed, it gave me same error.
I have no idea where it made the code directory which had the manage.py file. But I worked around it presently by changing the service name in the yml file and restarting the project with the new service name.
docker-compose run newservicenm django-admin.py startproject projectname directoryname
This worked as a new container!

Related

Running move and delete commands on Heroku CLI

I've recently deployed an application to Heroku. Due to the constraints of the file system I'm looking to replace two css files within a Flask Package upon the application starting.
My main goal is to take a file from the app directory (the file is part of the git repo) and use it to replace a python package file located in the site packages directory.
I've tried to run the following from the Heroku CLI but nothing seems to happen.
heroku run mv ./bootstrap.css ./.heroku/python/lib/python3.6/site-packages/flask_bootstrap/static/css/bootstrap.css
I've also tried to remove the files from the site packages directory using RM but again nothing happens.
Could you please let me know if standard unix commands work on Heroku?
Fork and edit flask_bootstrap and add that to requirements.txt file like this.
Heroku using ephemeral filesystem. Whatever change you made to your filesystem only last until the dyno is restarted.
So my opinion is to change the file in your local repo and push to heroku again.
Source : https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted

Python requirements.txt use local git dependency

I have a small python flask app on a CentOS-7 VM that runs in docker, along with an nginx reverse proxy. The requirements.txt pulls in several external utilities using git+ssh such as:
git+ssh://path-to-our-repo/some-utility.git
I had to make a change to the utility, so I cloned it locally, and I need the app to use my local version.
Say the cloned and modified utility is in a local directory:
/var/work/some-utility
In the requirements.txt I changed the entry to:
git+file:///var/work/some-utility
But when I try to run the app with
sudo docker-compose up
I get the error message
Invalid requirement: 'git+file:///var/work/some-utility'
it looks like a path. Does it exist ?
How can I get it to use my local copy of "some-utility" ?
I also tried:
git+file:///var/work/some-utility#egg=someutility
but that produced the same error.
I looked at PIP install from local git repository.
This is related to this question:
https://stackoverflow.com/questions/7225900/how-to-pip-install-packages-according-to-requirements-txt-from-a-local-directory?rq=1
I suppose most people would say why not just check in a development branch of some-utility to the corporate git repo, but in my case I do not have privileges for that.
Or maybe my problem is related to docker, and I need to map the some-utility folder into the docker container, and then use that path? I am a docker noob.
--- Edit ---
Thank you larsks for your answer. I tried to add the some-utility folder to the docker-compose.yml:
volumes:
- ./some-utility:/usr/local/some-utility
and then changed the requirements.txt to
git+file:///usr/local/some-utility
but our local git repo just went down for maintenance, so I will have to wait a bit for it to come back up to try this.
=== Edit 2 ===
After I made the above changes, I get the following error when running docker-compose when it tries to build my endpoint app:
Cloning file:///usr/local/some-utility to /tmp/pip-yj9xxtae-build
fatal: '/usr/local/some-utility' does not appear to be a git repository
But the /usr/local/some-utility folder does contain the cloned some-utility repo, and I can go there and run git status.
If you're running pip install inside a container, then of course /var/work/some-utility needs to be available inside the container.
You can expose the directory inside your container using a host volume mount, like this:
docker run -v /var/work/some-utility:/var/work/some-utility ...

added build pack and it's not showing up

I'm trying to use Heroku buildpacks to allow me to run PhantomJS from a Flask app. I've tried to follow the advice here and after I add the buildpacks and push, I still only see heroku/python when I check with heroku buidpacks at the command line.
After some research it seemed maybe multiple buildpacks is not supported and I needed to try what this site recommended. I added the
$ heroku config:
add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
created the .buildpacks file in the project root with the following:
https://github.com/heroku/heroku-buildpack-python
https://github.com/stomita/heroku-buildpack-phantomjs
and modified the path, as recommended:
$ heroku config:add LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib:/app/vendor/phantomjs/lib
after pushing, still I see only heroku/python when i try heroku buildpacks.
Also, for what it's worth the below test doesn't work for me, because there is no vendor directory. I'm not sure where that directory even comes from, but it was never in my project, so I can only assume that the buildpacks are suppose to create it? I found countless references to this directory, and adding this directory to the Heroku path, but not a single one explained it's origin, other than to say that is where the phantomJS buidpack installs to
$ heroku run bash
$ vendor/phantomjs/bin/phantomjs
For anyone who gets stuck on this...
Rather than this:
$ heroku config:
add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
You actually need to do the this: (as outlined here):
$ heroku buildpacks:
set https://github.com/ddollar/heroku-buildpack-multi.git

Launching an app in heroku? What is procfile? 'web:' command?

I was referring to this site as i am learning python/flask and trying to use heroku.
http://ryaneshea.com/lightweight-python-apps-with-flask-twitter-bootstrap-and-heroku
Let me explain what all I did, so that any one who is stuck like me can get the picture.
I am using Linux Backtrack command line .
1. I started virtualenv and then installed flask
virtualenv --distribute
pip install flask
Then, connected heroku and github, created a repo also in the github.
Wrote a simple script and saved it in app.py
Then, asked to create a procfile!
web: python app.py
Questions.
1. What is procfile in layman terms?
2. When i type web: python app.py, it says 'web:: command not found'
Please elaborate how this works?
I have one more doubt, sudo is supreme user right?
We are not supposed to use it in virtualenv?
And for what exactly are we using virtualenv? A simple example.
Questions are pretty basic. DO bare.
the Procfile tells Heroku what commands should be run (https://devcenter.heroku.com/articles/procfile).
You are able to define difference process types, such as web (the only one which will autostart by default), workers, etc...
So basically a Procfile containing
web: python app.py
is telling Heroku to started a named process called web, and to run python app.py when it starts.
There is Python specific documentation for Heroku at https://devcenter.heroku.com/articles/getting-started-with-python#declare-process-types-with-procfile

Heroku Django: Reconnecting and Updating

I've finished the Heroku tutorial on how to upload and launch a basic django based web app using the following:
https://devcenter.heroku.com/articles/django#gitignore
Can anybody provide steps or a link to documentation on how to re-connect to Heroku and properly upload changes you've made to your site? Starting from a fresh terminal and cd'ing into the folder where your manage.py and procfiles live, what would the following steps be?
I then do:
$ virtualenv venv --distribute
$ source venv/bin/activate
after this i try to run $python manage.py runserver but it can't find django modules etc...
Do I need to reinstall django everytime I go to git push an update on the server?
To answer your question:
Heroku is just git, basically. At least on your computer.
So you don't need to "connect" to Heroku. You just cd to your source folder and use it as you would a normal git repository.
If you're using a virtualenv (which you should be), after you cd to your directory, you'll need to reactivate the virtualenv. If you followed heroku's Django tutorial, it'll probably be the command source venv/bin/activate
If you want to dig into some of herokus commands, download the Toolbelt.
To test whether your Procfile is working, use Honcho. It's a python version of foreman, Heroku's Ruby-based local Procfile runner.
To see which files are on your Heroku app:
Launch the bash on heroku by typing this command on your terminal:
heroku run bash --app appname
From there just ls and see your folders.

Categories