diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3644c6db..c2b70602 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,6 @@ jobs: image: redis ports: - 6379:6379 - options: --entrypoint redis-server steps: - name: Set up repo diff --git a/.gitignore b/.gitignore index 76e2db25..999d6145 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ docs/source/reference/ # from prettier node_modules/ + +celerybeat-schedule diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..916f61e3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM python:3.11-slim-bookworm + +# reduce the number of celery warnings +RUN useradd celery + +ENV PIPENV_VENV_IN_PROJECT=1 + +COPY Pipfile . +COPY Pipfile.lock . + +RUN pip install pipenv && \ + pipenv install --dev + +ENV PATH="/.venv/bin:$PATH" + +WORKDIR /app diff --git a/Pipfile b/Pipfile index 1d4fc93f..8668ae13 100644 --- a/Pipfile +++ b/Pipfile @@ -34,6 +34,7 @@ furo = "*" myst-parser = "*" sphinx-copybutton = "*" sphinxcontrib-django = "*" +watchfiles = "*" [ci] pytest-cov = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 1146c0f7..7f904069 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "7166c4869eb2cd41a33c94506f400bd896b76974d50b73fe4cde1d7afd93a6bc" + "sha256": "312b4fbcdfae56920a795688929d3b5db792c1d2b80ab44566e91a8ada4bd040" }, "pipfile-spec": 6, "requires": { @@ -1254,6 +1254,14 @@ "markers": "python_version >= '3.10'", "version": "==1.0.0" }, + "anyio": { + "hashes": [ + "sha256:1d9fe889df5212298c0c0723fa20479d1b94883a2df44bd3897aa91083316f7a", + "sha256:b5011f270ab5eb0abf13385f851315585cc37ef330dd88e27ec3d34d651fd47a" + ], + "markers": "python_version >= '3.9'", + "version": "==4.8.0" + }, "asgiref": { "hashes": [ "sha256:3e1e3ecc849832fe52ccf2cb6686b7a55f82bb1d6aee72a58826471390335e47", @@ -1466,11 +1474,11 @@ }, "idna": { "hashes": [ - "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc", - "sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0" + "sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9", + "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3" ], - "markers": "python_version >= '3.5'", - "version": "==3.7" + "markers": "python_version >= '3.6'", + "version": "==3.10" }, "imagesize": { "hashes": [ @@ -1745,6 +1753,14 @@ "markers": "python_version >= '3.8'", "version": "==2.32.3" }, + "sniffio": { + "hashes": [ + "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2", + "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc" + ], + "markers": "python_version >= '3.7'", + "version": "==1.3.1" + }, "snowballstemmer": { "hashes": [ "sha256:09b16deb8547d3412ad7b590689584cd0fe25ec8db3be37788be3810cbf19cb1", @@ -1864,7 +1880,8 @@ "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d", "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8" ], - "markers": "python_version < '3.12'", + "index": "pypi", + "markers": "python_version >= '3.8'", "version": "==4.12.2" }, "urllib3": { @@ -1883,6 +1900,84 @@ "index": "pypi", "markers": "python_version >= '3.7'", "version": "==20.26.3" + }, + "watchfiles": { + "hashes": [ + "sha256:02a526ee5b5a09e8168314c905fc545c9bc46509896ed282aeb5a8ba9bd6ca27", + "sha256:05d341c71f3d7098920f8551d4df47f7b57ac5b8dad56558064c3431bdfc0b74", + "sha256:076f293100db3b0b634514aa0d294b941daa85fc777f9c698adb1009e5aca0b1", + "sha256:0799ae68dfa95136dde7c472525700bd48777875a4abb2ee454e3ab18e9fc712", + "sha256:0986902677a1a5e6212d0c49b319aad9cc48da4bd967f86a11bde96ad9676ca1", + "sha256:0bc80d91ddaf95f70258cf78c471246846c1986bcc5fd33ccc4a1a67fcb40f9a", + "sha256:13c2ce7b72026cfbca120d652f02c7750f33b4c9395d79c9790b27f014c8a5a2", + "sha256:1941b4e39de9b38b868a69b911df5e89dc43767feeda667b40ae032522b9b5f1", + "sha256:1eacd91daeb5158c598fe22d7ce66d60878b6294a86477a4715154990394c9b3", + "sha256:229e6ec880eca20e0ba2f7e2249c85bae1999d330161f45c78d160832e026ee2", + "sha256:22bb55a7c9e564e763ea06c7acea24fc5d2ee5dfc5dafc5cfbedfe58505e9f90", + "sha256:278aaa395f405972e9f523bd786ed59dfb61e4b827856be46a42130605fd0899", + "sha256:2a9f93f8439639dc244c4d2902abe35b0279102bca7bbcf119af964f51d53c19", + "sha256:308ac265c56f936636e3b0e3f59e059a40003c655228c131e1ad439957592303", + "sha256:31f1a379c9dcbb3f09cf6be1b7e83b67c0e9faabed0471556d9438a4a4e14202", + "sha256:32b026a6ab64245b584acf4931fe21842374da82372d5c039cba6bf99ef722f3", + "sha256:342622287b5604ddf0ed2d085f3a589099c9ae8b7331df3ae9845571586c4f3d", + "sha256:39f4914548b818540ef21fd22447a63e7be6e24b43a70f7642d21f1e73371590", + "sha256:3f68d8e9d5a321163ddacebe97091000955a1b74cd43724e346056030b0bacee", + "sha256:43b168bba889886b62edb0397cab5b6490ffb656ee2fcb22dec8bfeb371a9e12", + "sha256:47eb32ef8c729dbc4f4273baece89398a4d4b5d21a1493efea77a17059f4df8a", + "sha256:4810ea2ae622add560f4aa50c92fef975e475f7ac4900ce5ff5547b2434642d8", + "sha256:4e997802d78cdb02623b5941830ab06f8860038faf344f0d288d325cc9c5d2ff", + "sha256:4ebbeca9360c830766b9f0df3640b791be569d988f4be6c06d6fae41f187f105", + "sha256:4f8c4998506241dedf59613082d1c18b836e26ef2a4caecad0ec41e2a15e4226", + "sha256:55ccfd27c497b228581e2838d4386301227fc0cb47f5a12923ec2fe4f97b95af", + "sha256:5717021b199e8353782dce03bd8a8f64438832b84e2885c4a645f9723bf656d9", + "sha256:5c11ea22304d17d4385067588123658e9f23159225a27b983f343fcffc3e796a", + "sha256:5e0227b8ed9074c6172cf55d85b5670199c99ab11fd27d2c473aa30aec67ee42", + "sha256:62c9953cf85529c05b24705639ffa390f78c26449e15ec34d5339e8108c7c407", + "sha256:6ba473efd11062d73e4f00c2b730255f9c1bdd73cd5f9fe5b5da8dbd4a717205", + "sha256:740d103cd01458f22462dedeb5a3382b7f2c57d07ff033fbc9465919e5e1d0f3", + "sha256:74cb3ca19a740be4caa18f238298b9d472c850f7b2ed89f396c00a4c97e2d9ff", + "sha256:7b75fee5a16826cf5c46fe1c63116e4a156924d668c38b013e6276f2582230f0", + "sha256:7cf684aa9bba4cd95ecb62c822a56de54e3ae0598c1a7f2065d51e24637a3c5d", + "sha256:8012bd820c380c3d3db8435e8cf7592260257b378b649154a7948a663b5f84e9", + "sha256:857f5fc3aa027ff5e57047da93f96e908a35fe602d24f5e5d8ce64bf1f2fc733", + "sha256:8b1f135238e75d075359cf506b27bf3f4ca12029c47d3e769d8593a2024ce161", + "sha256:8d0d0630930f5cd5af929040e0778cf676a46775753e442a3f60511f2409f48f", + "sha256:90192cdc15ab7254caa7765a98132a5a41471cf739513cc9bcf7d2ffcc0ec7b2", + "sha256:95b42cac65beae3a362629950c444077d1b44f1790ea2772beaea95451c086bb", + "sha256:9745a4210b59e218ce64c91deb599ae8775c8a9da4e95fb2ee6fe745fc87d01a", + "sha256:9d1ef56b56ed7e8f312c934436dea93bfa3e7368adfcf3df4c0da6d4de959a1e", + "sha256:9eea33ad8c418847dd296e61eb683cae1c63329b6d854aefcd412e12d94ee235", + "sha256:9f25d0ba0fe2b6d2c921cf587b2bf4c451860086534f40c384329fb96e2044d1", + "sha256:9fe37a2de80aa785d340f2980276b17ef697ab8db6019b07ee4fd28a8359d2f3", + "sha256:a38320582736922be8c865d46520c043bff350956dfc9fbaee3b2df4e1740a4b", + "sha256:a462490e75e466edbb9fc4cd679b62187153b3ba804868452ef0577ec958f5ff", + "sha256:a5ae5706058b27c74bac987d615105da17724172d5aaacc6c362a40599b6de43", + "sha256:aa216f87594f951c17511efe5912808dfcc4befa464ab17c98d387830ce07b60", + "sha256:ab0311bb2ffcd9f74b6c9de2dda1612c13c84b996d032cd74799adb656af4e8b", + "sha256:ab594e75644421ae0a2484554832ca5895f8cab5ab62de30a1a57db460ce06c6", + "sha256:aee397456a29b492c20fda2d8961e1ffb266223625346ace14e4b6d861ba9c80", + "sha256:b045c800d55bc7e2cadd47f45a97c7b29f70f08a7c2fa13241905010a5493f94", + "sha256:b77d5622ac5cc91d21ae9c2b284b5d5c51085a0bdb7b518dba263d0af006132c", + "sha256:ba5bb3073d9db37c64520681dd2650f8bd40902d991e7b4cfaeece3e32561d08", + "sha256:bdef5a1be32d0b07dcea3318a0be95d42c98ece24177820226b56276e06b63b0", + "sha256:c2acfa49dd0ad0bf2a9c0bb9a985af02e89345a7189be1efc6baa085e0f72d7c", + "sha256:c7cce76c138a91e720d1df54014a047e680b652336e1b73b8e3ff3158e05061e", + "sha256:cc27a65069bcabac4552f34fd2dce923ce3fcde0721a16e4fb1b466d63ec831f", + "sha256:cdbd912a61543a36aef85e34f212e5d2486e7c53ebfdb70d1e0b060cc50dd0bf", + "sha256:cdcc92daeae268de1acf5b7befcd6cfffd9a047098199056c72e4623f531de18", + "sha256:d3452c1ec703aa1c61e15dfe9d482543e4145e7c45a6b8566978fbb044265a21", + "sha256:d6097538b0ae5c1b88c3b55afa245a66793a8fec7ada6755322e465fb1a0e8cc", + "sha256:d8d3d9203705b5797f0af7e7e5baa17c8588030aaadb7f6a86107b7247303817", + "sha256:e0611d244ce94d83f5b9aff441ad196c6e21b55f77f3c47608dcf651efe54c4a", + "sha256:f12969a3765909cf5dc1e50b2436eb2c0e676a3c75773ab8cc3aa6175c16e902", + "sha256:f44a39aee3cbb9b825285ff979ab887a25c5d336e5ec3574f1506a4671556a8d", + "sha256:f9ce064e81fe79faa925ff03b9f4c1a98b0bbb4a1b8c1b015afa93030cb21a49", + "sha256:fb2c46e275fbb9f0c92e7654b231543c7bbfa1df07cdc4b99fa73bedfde5c844", + "sha256:fc2eb5d14a8e0d5df7b36288979176fbb39672d45184fc4b1c004d7c3ce29317" + ], + "index": "pypi", + "markers": "python_version >= '3.9'", + "version": "==1.0.4" } } } diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 00000000..14dcd41f --- /dev/null +++ b/compose.yaml @@ -0,0 +1,50 @@ +services: + redis: + image: redis:latest + networks: + - tin-network + expose: + - "6379" + + celery: + image: tin-base + user: celery + entrypoint: + - watchfiles + - --filter + - python + - celery -A tin worker + - /app/tin + networks: + - tin-network + depends_on: + - redis + volumes: + - .:/app + environment: + IN_DOCKER: true + + django: + container_name: tin_django + build: . + image: tin-base + restart: on-failure + networks: + - tin-network + ports: + - 8000:8080 + volumes: + - .:/app + entrypoint: + - ./manage.py + - runserver + - 0.0.0.0:8080 + healthcheck: + test: ["CMD", "curl", "-f", "http://0.0.0.0:8000"] + environment: + IN_DOCKER: true + +networks: + tin-network: + driver: bridge + name: tin-dev-network diff --git a/docs/source/contributing/setup.rst b/docs/source/contributing/setup.rst index b5845c12..ad0cbdff 100644 --- a/docs/source/contributing/setup.rst +++ b/docs/source/contributing/setup.rst @@ -43,21 +43,12 @@ Now you're all set! Try running the development server Head on over to `http://127.0.0.1:8000 `_, and login as ``admin`` and the password you just entered. +Docker +------ +If you prefer, you can also run the development setup with `Docker `_. To do so, +``cd`` into the project directory and run:: + docker compose build + docker compose up -NixOS Setup ------------ -A ``flake.nix`` file is provided for NixOS users. To use it, first enable the redis service globally. -Place the following in your ``/etc/nixos/configuration.nix``:: - - services.redis.server."".enable = true - -This will start a systemd service called ``redis``. After that, you can start the flake with:: - - nix develop - -You can then install dependencies, setup the database, and run the development server as described above. - -.. tip:: - - You may also need to set ``nix.settings.experimental-features = ["nix-command" "flakes"];`` in your ``configuration.nix``. +The latter command will start up the django development server, as well as celery tasks for submissions. diff --git a/flake.lock b/flake.lock deleted file mode 100644 index ac889842..00000000 --- a/flake.lock +++ /dev/null @@ -1,62 +0,0 @@ -{ - "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1726560853, - "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1730963269, - "narHash": "sha256-rz30HrFYCHiWEBCKHMffHbMdWJ35hEkcRVU0h7ms3x0=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "83fb6c028368e465cd19bb127b86f971a5e41ebc", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-24.05", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} - diff --git a/flake.nix b/flake.nix deleted file mode 100644 index aaeec4f1..00000000 --- a/flake.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ - description = "A flake for running Tin"; - - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; - flake-utils.url = "github:numtide/flake-utils"; - }; - - outputs = { self, nixpkgs, flake-utils, ... }: - flake-utils.lib.eachSystem flake-utils.lib.allSystems (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - in - { - devShells.default = pkgs.mkShell { - buildInputs = [ - pkgs.pyenv - pkgs.pipenv - pkgs.python3 - ]; - }; - }); -} diff --git a/tin/settings/__init__.py b/tin/settings/__init__.py index c213a0cf..2b7748d3 100644 --- a/tin/settings/__init__.py +++ b/tin/settings/__init__.py @@ -28,6 +28,8 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True +IN_DOCKER = os.environ.get("IN_DOCKER", False) + ALLOWED_HOSTS = [ "127.0.0.1", "localhost", @@ -106,7 +108,11 @@ CHANNEL_LAYERS = { "default": { "BACKEND": "channels_redis.core.RedisChannelLayer", - "CONFIG": {"hosts": [("localhost", 6379)]}, + "CONFIG": { + "hosts": [ + ("redis" if IN_DOCKER else "localhost", 6379), + ] + }, }, } @@ -234,7 +240,13 @@ CELERY_RESULT_BACKEND = "django-db" -CELERY_BROKER_URL = "redis://localhost:6379/1" +if IN_DOCKER: + CELERY_BROKER_URL = "redis://redis:6379/0" +else: + CELERY_BROKER_URL = "redis://localhost:6379/1" + + +CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True # Markdown