By mswaringen9
There is an ongoing issue with using Python Cloud Native buildpacks on the App platform with very long or indefinite build times as noted by multiple users.
A working solution is using a Docker build process instead. Simply including a Dockerfile in the root of the app will kick off a Docker build process which completes fairly quickly.
I banged my head on the wall for a while trying to get a Django working on DO App, hopefully this solution will save others the headache.
Example Dockerfile: https://github.com/wagtail/docker-wagtail-develop/blob/master/Dockerfile
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello,
Switching to a Docker-based build process on the DigitalOcean App Platform can indeed be a good workaround for issues related to build times or other limitations with Cloud Native Buildpacks, especially for Python and Django applications. Using Docker offers more control over the environment and dependencies, potentially leading to faster and more predictable builds.
Here’s a simplified step-by-step guide to setting up a Django application with a Dockerfile, inspired by the example you mentioned:
In the root of your Django project, create a Dockerfile that specifies how to build your application. Here’s a basic example that you can adapt:
# Use an official Python runtime as a parent image
FROM python:3.8-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set work directory
WORKDIR /app
# Install dependencies
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
# Copy the current directory contents into the container at /app
COPY . /app/
# Collect static files
RUN python manage.py collectstatic --noinput
# Run the application
CMD gunicorn your_project_name.wsgi:application --bind 0.0.0.0:$PORT
Make sure to replace your_project_name with the name of your Django project. This Dockerfile uses Gunicorn as the WSGI HTTP Server to serve the Django application. Ensure Gunicorn is included in your requirements.txt.
requirements.txtEnsure you have a requirements.txt file in your project root that lists all your Python dependencies, including Django and Gunicorn.
Django>=3.0,<4.0
gunicorn>=20.0,<21.0
# Other dependencies
Dockerfile and requirements.txt, is pushed to a Git repository.Dockerfile and configure the build accordingly.DJANGO_SECRET_KEY or database credentials), add them in the App Platform’s settings under the Environment Variables section.After deploying, monitor the build and deployment process in the DigitalOcean App Platform dashboard. If there are any issues, the logs provided there can be very helpful for troubleshooting.
Using Docker can not only resolve issues related to build times but also provides a more flexible environment that might be closer to your production setup or specific requirements. This approach is particularly useful when dealing with complex dependencies or when you need to ensure consistency across development, testing, and production environments.
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.