Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #27

Merged
merged 9 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
file: deploy/django/Dockerfile
tags: ${{ env.REGISTRY }}/${{ github.repository }}/live_data_server:${{ steps.latest_tag.outputs.latest_tag }}
push: true

Expand All @@ -92,6 +92,6 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
file: deploy/django/Dockerfile
tags: ${{ env.REGISTRY }}/${{ github.repository }}/live_data_server:${{ steps.tag.outputs.tag }}
push: true
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: Start docker containers
run: |
cp ./deploy-config/docker-compose.envlocal.yml docker-compose.yml
cp ./deploy/docker-compose.envlocal.yml docker-compose.yml
docker compose up --build -d

- name: Sleep, wait for containers to start up
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ target/

#Ipython Notebook
.ipynb_checkpoints

# Ruff cache
.ruff_cache
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.6
rev: v0.6.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
14 changes: 0 additions & 14 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ docker/compose/validate: ## validate the version of the docker-compose command.
@./scripts/docker-compose_validate.sh $(DOCKER_COMPOSE)

docker/compose/local: docker/compose/validate ## compose and start the service locally
\cp ./deploy-config/docker-compose.envlocal.yml docker-compose.yml
\cp ./deploy/docker-compose.envlocal.yml docker-compose.yml
$(DOCKER_COMPOSE) up --build

.PHONY: clean
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Developer documentation at <https://livedata-ornl.readthedocs.io/en/latest/>
make docker/compose/local
```

This command will copy `deploy-config/docker-compose.envlocal.yml` into `docker-compose.yml` before composing all the services.
This command will copy `deploy/docker-compose.envlocal.yml` into `docker-compose.yml` before composing all the services.

Type `make help` to learn about other macros available as make targets.
For instance, `make docker/pruneall` will stop all containers, then remove all containers, images, networks, and volumes.
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ coverage:
default:
target: 80%
threshold: 10%
ignore:
- "src/apps/plots/migrations"
31 changes: 31 additions & 0 deletions deploy/django/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM continuumio/miniconda3:23.10.0-1 AS base

### System dependencies and cron job setup
RUN apt-get update -y && \
# apt upgrade -y && \
apt-get install -y \
vim cron

# Set up cron job to purge expired data once a month
COPY scripts/periodic-purge.sh /var/opt/
RUN echo "0 0 1 * * /var/opt/periodic-purge.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/root && \
chmod 0644 /etc/cron.d/root && \
crontab /etc/cron.d/root && \
touch /var/log/cron.log

### Environment setup
FROM base AS build

COPY environment.yml .
RUN conda env create

WORKDIR /var/www/livedata
COPY src app
RUN mkdir ./static

### Final image
FROM build AS final

COPY deploy/django/docker-entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/docker-entrypoint.sh
ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "livedata", "/usr/bin/docker-entrypoint.sh"]
6 changes: 5 additions & 1 deletion docker-entrypoint.sh → deploy/django/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/bin/sh
set -e

# start cron, export root env variables
service cron start
env >>/etc/environment

# wait for database
until PGPASSWORD=${DATABASE_PASS} psql -h "${DATABASE_HOST}" -U "${DATABASE_USER}" -d "${DATABASE_NAME}" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
echo >&2 "Postgres is unavailable - sleeping"
sleep 1
done

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ services:
- "443:443"
volumes:
- web-static:/var/www/livedata/static
- ./deploy-config/nginx/envlocal.conf:/etc/nginx/conf.d/nginx.conf
- ./deploy/nginx/envlocal.conf:/etc/nginx/conf.d/nginx.conf
depends_on:
django:
condition: service_healthy

django:
build:
context: .
dockerfile: Dockerfile
dockerfile: deploy/django/Dockerfile
network: host
environment:
APP_DEBUG: 1 # 0 for False, otherwise will evaluate to True
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/developer/config_for_local_use.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ After the secrets are set, you can start the server with:

make docker/compose/local

This command will copy ``deploy-config/docker-compose.envlocal.yml`` into ``./docker-compose.yml`` before composing all the services.
This command will copy ``deploy/docker-compose.envlocal.yml`` into ``./docker-compose.yml`` before composing all the services.

| Run ``make help`` to learn about other macros available as make targets.
| For instance, ``make docker/pruneall`` will stop all containers, then remove all containers, images, networks, and volumes.
Expand Down
4 changes: 2 additions & 2 deletions docs/developer/troubleshoot/unresponsive.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ The logs indicate a problem with the certificate files.
An additional test is to substitute the
`nginx.conf file for the testing environment <https://code.ornl.gov/sns-hfir-scse/deployments/livedata-deploy/-/blob/main/test/nginx.conf?ref_type=heads>`_
with the
`local environment one <https://github.com/neutrons/live_data_server/blob/next/deploy-config/nginx/envlocal.conf>`_,
`local environment one <https://github.com/neutrons/live_data_server/blob/next/deploy/nginx/envlocal.conf>`_,
which does not contain SSL certificates. Don't forget to change
`the server name <https://github.com/neutrons/live_data_server/blob/next/deploy-config/nginx/envlocal.conf#L4>`_
`the server name <https://github.com/neutrons/live_data_server/blob/next/deploy/nginx/envlocal.conf#L4>`_
from `"localhost"` to `"testfixture02-test.ornl.gov"`.
Redeploy after this. If the http://testfixture02-test.ornl.gov/admin (notice the `http` instead of `https`) app is
served now, then it's a problem of the secure connection.
Expand Down
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies:
- psycopg=3.2
- gunicorn
- pytest
- build
- versioningit
- toml
- pre-commit
Expand Down
6 changes: 6 additions & 0 deletions scripts/periodic-purge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
. /opt/conda/etc/profile.d/conda.sh
printf "=%.0s" {1..88}
printf "\nStarting periodic purge - $(date)\n"
conda run -n livedata python /var/www/livedata/app/manage.py purge_expired_data
printf "=%.0s" {1..88}; printf "\n"
3 changes: 2 additions & 1 deletion src/apps/plots/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from apps.plots.models import DataRun, Instrument, PlotData
from django.contrib import admin

from apps.plots.models import DataRun, Instrument, PlotData


class PlotDataAdmin(admin.ModelAdmin):
readonly_fields = ("data_run",)
Expand Down
1 change: 1 addition & 0 deletions src/apps/plots/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

class PlotsConfig(AppConfig):
name = "apps.plots"
default_auto_field = "django.db.models.BigAutoField"
6 changes: 5 additions & 1 deletion src/apps/plots/management/commands/purge_expired_data.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from apps.plots.models import DataRun
from django.core.management.base import BaseCommand
from django.utils import timezone

from apps.plots.models import DataRun


class Command(BaseCommand):
help = "Delete expired runs and related plots"

def handle(self, *args, **options): # noqa: ARG002
runs = DataRun.objects.all()
expired_runs = 0
for run in runs:
if run.expiration_date < timezone.now():
expired_runs += 1
run.delete()
self.stdout.write(self.style.SUCCESS(f"Deleted {expired_runs} expired runs"))
27 changes: 27 additions & 0 deletions src/apps/plots/migrations/0003_alter_default_auto_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.15 on 2024-08-23 14:47

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("plots", "0002_datarun_expiration_date"),
]

operations = [
migrations.AlterField(
model_name="datarun",
name="id",
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
),
migrations.AlterField(
model_name="instrument",
name="id",
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
),
migrations.AlterField(
model_name="plotdata",
name="id",
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
),
]
3 changes: 2 additions & 1 deletion src/apps/plots/view_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
from datetime import datetime
from typing import Optional

from apps.plots.models import DataRun, Instrument, PlotData
from django.conf import settings
from django.http import HttpResponse
from django.utils import timezone

from apps.plots.models import DataRun, Instrument, PlotData


def generate_key(instrument, run_id):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/apps/plots/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import logging
from datetime import timedelta

from apps.plots.models import DataRun, Instrument, PlotData
from django.conf import settings
from django.contrib.auth import authenticate, login
from django.http import HttpResponse, HttpResponseNotFound, JsonResponse
Expand All @@ -15,6 +14,8 @@
from django.views.decorators.cache import cache_page
from django.views.decorators.csrf import csrf_exempt

from apps.plots.models import DataRun, Instrument, PlotData

from . import view_util


Expand Down
Loading