openedx / edx-django-utils

edX utilities for Django Application development.
https://edx.readthedocs.io/projects/edx-django-utils/en/latest/
Apache License 2.0
26 stars 20 forks source link

build: Demo of no-setup Makefile (standardized virtualenv handling) #347

Open timmc-edx opened 1 year ago

timmc-edx commented 1 year ago

This allows a developer to run make test or other targets without having to manually set up a virtualenv or install requirements. The virtualenv is set up for them as a hidden subdirectory and requirements are automatically installed as needed.

The goal here is larger: The new base.mk would be pulled in via git subtree from some centralized repository. Over time, this standardized base Makefile would grow and the Makefiles in regular repositories would shrink. By centralizing Makefile logic, we would gain the following:

robrap commented 1 year ago

@timmc-edx:

  1. I think you also had an idea for how you could use a shared docker file if one were wanted. Would that be a separate PR?
  2. I imagine getting the right Python version is still an issue for a new developer. Are there any ways to help there, or is that one advantage that a container would always have? Maybe that brings us back to point 1.
timmc-edx commented 1 year ago

I think the main use for a shared Docker image would be getting the right version of Python, yeah. That might be a separate PR, but it looks like we could add something like this to the Makefile:

SHELL := docker run --rm -v .:/edx/dev -w /edx/dev IMAGE_REF /bin/bash -c

with an image based on a Dockerfile that looks something like this:

FROM ubuntu:focal as minimal-system

RUN useradd -m --shell /bin/false app
WORKDIR /edx/dev
RUN chown app:app /edx/dev

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
    apt-get -y dist-upgrade && \
    apt-get -y install --no-install-recommends \
        # Base Python system
        python3.8 \
        python3.8-venv

USER app

Seems like it works based on some local testing -- make requirements runs on the host, but all of the actual commands run in the container. It could be made switchable so that the container is not required.

timmc-edx commented 1 year ago

As a branch: https://github.com/openedx/edx-django-utils/compare/timmc/demo-venv...timmc/demo-make-container