Comments (6)
Now I found it:
from s2i-python-container.
@GrahamDumpleton thanks for bringing this up!
I've done a quick review on our assemble scripts, unless I'm misreading it, we will also fail builds if the collectstatic step fails.
- We have
set -e
: assemble#L11 - We run
python $manage_file collectstatic --noinput
: assemble#L46 - The
DISABLE_COLLECTSTATIC
flag is documented in using_images/s2i_images/python.html#configuration.
Is there anything else we're missing?
from s2i-python-container.
@GrahamDumpleton bump
from s2i-python-container.
If you want to look at wider issues with this there are a couple.
1 - It is assumed that if manage.py
exists that it is for Django. This need not be the case as Flask-Script
also makes use of a manage.py
file for making it easier to start up a Flask application, along with support for management commands.
Your solution to this is to attempt a dry run of the command:
if ! python $manage_file collectstatic --dry-run --noinput &> /dev/null; then
echo "WARNING: could not run 'manage.py collectstatic'. To debug, run:"
echo " $ python $manage_file collectstatic --noinput"
echo "Ignore this warning if you're not serving static files with Django."
exit
fi
The problem with this is that if there was a mis-configuration in Django settings, you would mask it at this point and allow the build to continue with collectstatic
skipped. An actual problem with the configuration would only later manifest when the deployment occurred and the web application was started.
It would be much better to detect it during the build phase as then you wouldn't affect the already running web application if using Recreate
strategy and the old web application was pulled down first.
The better approach would be to try and validate that the manage.py
script was in fact for Django.
I do this by using:
if [ -f manage.py ]; then
if grep -q DJANGO_SETTINGS_MODULE manage.py; then
echo " -----> Collecting static files for Django"
django_collectstatic
fi
fi
So I don't use a dry run and instead if DJANGO_SETTINGS_MODULE
appears in the manage.py
file assume that should be good to assume it actually is the Django management script.
2 - Why even bother with running collectstatic
in the first place.
Because you are using the Django development server, it doesn't need to have collectstatic
actually run. This is because the way it handles serving of static files it pulls them in from the different locations of the different installed applications.
Even if you use gunicorn
, you would use Whitenoise
WSGI middleware, but that has Django integration and can do similar magic to the Django development server and sets up an internal map which references static files from their locations in installed applications and it doesn't need to have them copied into one location.
The only reason you would want to run collectstatic
would be if running mod_wsgi-express
or uWSGI
, both of which is non trivial for normal user with current S2I builder.
Only other reason would be if someone didn't use the Whitenoise
Django integration and relied on doing collectstatic
and then pointing Whitenoise
at that one directory.
So right now the value of running collectstatic
is very limited. Since it isn't readily necessary is questionable why you would do it. It may have been better to implement a proper actions hooks mechanism and just leave the task up to the user if they really needed it.
from s2i-python-container.
As far as I understand this, case number one is no longer a problem because collectstatic
in assemble
script is run only if Django is installed so if you use manage.py
for Flask configuration, you probably would not install Django in a container.
Case two can be solved by not running collectstatic
command when Django development server will be used for serving Django app - in other words - run collectstatic
only if you are going to use gunicorn as a web server.
Am I right? What do you think about this?
from s2i-python-container.
The check for django
being installed is not full proof, but chance of it being installed at same time as flask
is extremely slim. Better check may have been to look for DJANGO_SETTINGS_MODULE
string in manage.py
but the check for django
module is sufficient for now. Closing.
from s2i-python-container.
Related Issues (20)
- No Action Required !! Testing automation workflow HOT 1
- No Action Required !! Testing automation workflow HOT 4
- Remove verification of installed packages HOT 3
- 3.9 Readme Instructions unclear HOT 6
- Python 3.10 RHEL image missing in RHEL Container catalog? HOT 4
- Unable to build a Python image from scratch on MacOS HOT 1
- Python 3.9+ for Centos 7 docker images HOT 4
- tests: test case should fail early when the prepare function fails HOT 3
- Distgen errors HOT 11
- Incorrect py-3 image HOT 11
- Support gunicorn >=20.1.0 defaults (do not require APP_ environment variables) HOT 1
- Add RHEL images for Python 3.11 HOT 4
- ERROR: No matching distribution found for numpy==1.19.2 HOT 4
- Use PIP_INDEX_URL with pipenv HOT 1
- ubi9/python-311:latest is using python3.9-rpm HOT 2
- Publish arm64 images HOT 8
- rh-python38 failed on `'npm-virtualenv-uwsgi-test-app' run_s2i_build` & `'pin-pipenv-version-test-app' run_s2i_build` HOT 2
- python311-devel not found by microdnf in python 3.11 minimal EL8 and C9s variants HOT 1
- Documented pull example quay.io/sclorg/python-39-minimal isn't a valid URL HOT 5
- Cannot resolve internal host HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from s2i-python-container.