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

Update main with local changes and upstream #3

Open
wants to merge 60 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
46fe5b8
update pre-commit URLs and versions
helrond Feb 26, 2022
73d5839
update python and dependencies
helrond Feb 26, 2022
9bdb549
update travis configs
helrond Feb 26, 2022
8271d2b
replace health_check with asterism view
helrond Feb 26, 2022
ac24771
linting
helrond Feb 26, 2022
c1b6d31
Merge pull request #157 from RockefellerArchiveCenter/py310
helrond Mar 1, 2022
169465e
Merge pull request #158 from RockefellerArchiveCenter/development
helrond Mar 16, 2022
45e5f9c
update requirements
helrond May 9, 2022
adc12a7
Merge pull request #161 from RockefellerArchiveCenter/development
helrond May 9, 2022
23ab4a0
update rac_es
helrond May 13, 2022
82e84fa
Merge pull request #162 from RockefellerArchiveCenter/issue-160
helrond May 13, 2022
cfd9619
Merge pull request #163 from RockefellerArchiveCenter/development
helrond May 13, 2022
75419c0
add gh-actions file, remove dependabot
HaSistrunk Jul 21, 2022
fc07219
update requirements
HaSistrunk Jul 21, 2022
65ac21f
Merge pull request #165 from RockefellerArchiveCenter/gh-actions
HaSistrunk Jul 21, 2022
46d2710
Merge pull request #166 from RockefellerArchiveCenter/development
HaSistrunk Jul 21, 2022
48a98de
Dependency updates
HaSistrunk Aug 1, 2022
23430b5
Merge pull request #167 from RockefellerArchiveCenter/dependency-updates
helrond Aug 2, 2022
750c086
Merge pull request #168 from RockefellerArchiveCenter/development
helrond Aug 2, 2022
07a201a
#170: set cron returns to recent string values
ctgraham Aug 16, 2022
4d94f23
#170: move cron sucess messages into try
ctgraham Aug 16, 2022
0a590d5
Merge pull request #171 from ulsdevteam/issue-170
helrond Aug 17, 2022
e49880c
formatting
helrond Aug 17, 2022
71127e0
Merge pull request #172 from RockefellerArchiveCenter/issue-170
helrond Aug 17, 2022
a192994
Merge pull request #173 from RockefellerArchiveCenter/development
helrond Aug 17, 2022
46d4215
Dependency updates
HaSistrunk Sep 1, 2022
429f170
#175: Production-ready docker configuration
ctgraham Sep 2, 2022
f23e947
Update django version
p-galligan Sep 6, 2022
2588a18
Merge pull request #174 from RockefellerArchiveCenter/dependency-updates
p-galligan Sep 7, 2022
16d7a39
Merge pull request #176 from RockefellerArchiveCenter/development
p-galligan Sep 7, 2022
8246de7
Dependency updates
HaSistrunk Oct 1, 2022
c1ca094
Merge pull request #177 from RockefellerArchiveCenter/dependency-updates
HaSistrunk Oct 4, 2022
780fd15
Merge pull request #178 from RockefellerArchiveCenter/development
HaSistrunk Oct 5, 2022
9e93aac
Dependency updates
HaSistrunk Nov 1, 2022
6bfddbf
Merge pull request #179 from RockefellerArchiveCenter/dependency-updates
helrond Nov 7, 2022
b0c5ad4
Merge pull request #180 from RockefellerArchiveCenter/development
helrond Nov 7, 2022
e4e18eb
Dependency updates
HaSistrunk Dec 1, 2022
f88235d
Merge pull request #181 from RockefellerArchiveCenter/dependency-updates
helrond Dec 5, 2022
ae618eb
Merge pull request #182 from RockefellerArchiveCenter/development
helrond Dec 5, 2022
53ee7ec
security patch
p-galligan Dec 9, 2022
66c6592
Merge pull request #184 from RockefellerArchiveCenter/security-patch
p-galligan Dec 9, 2022
8e9c193
Merge pull request #185 from RockefellerArchiveCenter/development
p-galligan Dec 9, 2022
1a5c22b
Dependency updates
HaSistrunk Jan 1, 2023
6f243e6
Update pre-commit conifg
p-galligan Jan 3, 2023
88d4186
Merge pull request #186 from RockefellerArchiveCenter/dependency-updates
p-galligan Jan 3, 2023
da759ec
Merge pull request #187 from RockefellerArchiveCenter/development
p-galligan Jan 3, 2023
52dd4b7
Implement cron as separate container #1
kcloud Jan 28, 2023
0df1a30
Add Docker production config #2
kcloud Jan 28, 2023
a553f11
Dependency updates
HaSistrunk Feb 1, 2023
1621556
Update dependencies.yml
helrond Feb 1, 2023
4fce046
bump django
helrond Feb 6, 2023
da53bb8
updating
helrond Feb 6, 2023
7c516d5
Merge pull request #188 from RockefellerArchiveCenter/dependency-updates
helrond Feb 6, 2023
53dee7c
Merge pull request #190 from RockefellerArchiveCenter/development
helrond Feb 6, 2023
64fcb15
Merge remote-tracking branch 'origin/docker-prod' into wip
kcloud Feb 6, 2023
3fdf463
Merge remote-tracking branch 'origin/cron' into wip
kcloud Feb 6, 2023
7835471
update django
helrond Feb 16, 2023
ccfa0bf
Merge pull request #192 from RockefellerArchiveCenter/django
helrond Feb 16, 2023
27a0db2
Merge pull request #193 from RockefellerArchiveCenter/development
helrond Feb 16, 2023
72cb2c6
Merge remote-tracking branch 'upstream/base' into wip
kcloud Feb 24, 2023
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
41 changes: 41 additions & 0 deletions .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: update dependencies
on:

schedule:
- cron: '0 0 1 * *'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: development

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: pip

- name: Install pre-commit and pip-tools
run: pip install pre-commit pip-tools

- name: Run pre-commit autoupdate
run: pre-commit autoupdate

- name: Run pip-compile
run: pip-compile --upgrade

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: development
branch: dependency-updates
delete-branch: true
title: Dependency Updates
commit-message: Dependency updates
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
repos:
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5
rev: v2.0.1
hooks:
- id: autopep8
args:
- --diff
- --in-place
- --aggressive
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: git://github.com/doublify/pre-commit-isort
rev: v4.3.0
- repo: https://github.com/pycqa/isort
rev: 5.11.4
hooks:
- id: isort
- repo: https://github.com/jazzband/pip-tools
rev: 6.2.0
rev: 6.12.1
hooks:
- id: pip-compile
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
dist: bionic
language: python
python: "3.10"
cache:
directories:
- $HOME/.cache/pip
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.6
FROM python:3.10

ENV PYTHONUNBUFFERED 1
RUN mkdir /code
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile.cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.10

ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get install -y cron && which cron && rm -rf /etc/cron.*/*
RUN apt-get -y install python3-pip
RUN pip install --upgrade pip

RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install --upgrade pip && pip install -r requirements.txt
ADD . /code/
RUN chmod +x /code

RUN ln -s /usr/local/bin/python3 /code/scorpio/python
ADD ./cron/scorpio_cron /etc/cron.d/scorpio_cron
RUN chmod 644 /etc/cron.d/scorpio_cron
RUN crontab /etc/cron.d/scorpio_cron
RUN mkdir -p /var/log/scorpio-cron
ENTRYPOINT ["/code/cron/entrypoint.sh"]
CMD ["cron","-f","-l","2"]
36 changes: 36 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM python:3.10

ENV PYTHONUNBUFFERED 1
ARG SCORPIO_DNS
ARG APPLICATION_PORT
RUN apt-get update
RUN apt-get install --yes apache2 apache2-dev
RUN apt-get install --yes postgresql
RUN apt-get -y install python3-pip
RUN pip install --upgrade pip

RUN wget https://github.com/GrahamDumpleton/mod_wsgi/archive/refs/tags/4.9.0.tar.gz \
&& tar xvfz 4.9.0.tar.gz \
&& cd mod_wsgi-4.9.0 \
&& ./configure --with-apxs=/usr/bin/apxs --with-python=/usr/local/bin/python \
&& make \
&& make install \
&& make clean

ADD ./apache/000-scorpio.conf /etc/apache2/sites-available/000-scorpio.conf
RUN sed "s/ENV_SCORPIO_DNS/${SCORPIO_DNS}/" -i /etc/apache2/sites-available/000-scorpio.conf
RUN sed "s/ENV_SCORPIO_PORT/${APPLICATION_PORT}/" -i /etc/apache2/sites-available/000-scorpio.conf
ADD ./apache/wsgi.load /etc/apache2/mods-available/wsgi.load
RUN a2dissite 000-default
RUN a2ensite 000-scorpio.conf
RUN a2enmod headers
RUN a2enmod rewrite
RUN a2enmod wsgi

COPY . /var/www/scorpio
WORKDIR /var/www/scorpio
RUN pip install -r requirements.txt
RUN ./manage.py collectstatic

EXPOSE ${APPLICATION_PORT}
CMD ["apache2ctl", "-D", "FOREGROUND"]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Scorpio configurations are stored in `/scorpio/config.py`. This file is excluded

The first time the container is started, the example config file (`/scorpio/config.py.example`) will be copied to create the config file if it doesn't already exist.

Deployment using the `Dockerfile.prod` file is intended to bring up a production image (based on Apache/WSGI) which is ready to be proxied by an apache, nginx, traefik or similar frontend. Dockerfile.prod expects two environment arguments to be available at build time: `SCORPIO_DNS` and `APPLICATION_PORT`. Apache will Listen on `${APPLICATION_PORT}` with a ServerName of `${SCORPIO_DNS}`. If you don't anticipate exposing the Scorpio web UI publicly, a `SCORPIO_DNS` value of your container name or "localhost" is just fine. Deployment of the `Dockerfile.cron` will launch a container which will run Scorpio tasks automatically, per `/cron/scorpio_cron`.


## Services

Expand Down
20 changes: 20 additions & 0 deletions apache/000-scorpio.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Listen ENV_SCORPIO_PORT
<VirtualHost *:ENV_SCORPIO_PORT>
ErrorLog /var/log/apache2/scorpio_error_log
CustomLog /var/log/apache2/scorpio_access_log combined
ServerName ENV_SCORPIO_DNS
DocumentRoot /var/www/html
Alias /static /var/www/scorpio/static
<Directory /var/www/scorpio/static>
Options Includes FollowSymLinks MultiViews
Require all granted
</Directory>
<Directory /var/www/scorpio/scorpio>
WSGIProcessGroup scorpio
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
WSGIDaemonProcess scorpio home=/var/www/scorpio
WSGIProcessGroup scorpio
WSGIScriptAlias / /var/www/scorpio/scorpio/wsgi.py
</VirtualHost>
1 change: 1 addition & 0 deletions apache/wsgi.load
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
7 changes: 7 additions & 0 deletions cron/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

env >> environment

# execute CMD
echo "$@"
exec "$@"
7 changes: 7 additions & 0 deletions cron/scorpio_cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Don't remove empty line at end of file. It is required for cron to run.
SCORPIO_ROOT=/code/scorpio
00,30 * * * * $SCORPIO_ROOT/python -u /code/manage.py runcrons "indexer.cron.IndexAgents" >> /var/log/scorpio-cron/scorpio-agents.txt 2>&1
10,40 * * * * $SCORPIO_ROOT/python -u /code/manage.py runcrons "indexer.cron.IndexCollections" >> /var/log/scorpio-cron/scorpio-collections.txt 2>&1
20,50 * * * * $SCORPIO_ROOT/python -u /code/manage.py runcrons "indexer.cron.IndexObjects" >> /var/log/scorpio-cron/scorpio-objects.txt 2>&1
5 0,12 * * * $SCORPIO_ROOT/python -u /code/manage.py runcrons "indexer.cron.CleanUpCompleted" >> /var/log/scorpio-cron/scorpio-cleanupcompleted.txt 2>&1

7 changes: 0 additions & 7 deletions dependabot.yml

This file was deleted.

6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ version: '3'

services:
scorpio-db:
image: postgres:10.4
image: postgres:14.4
environment:
- POSTGRES_USER=postgres # name of the application database user
- POSTGRES_PASSWORD=postgres # name of the application database user
- POSTGRES_DB=postgres # name of the application database
volumes:
- scorpiodbvolume:/var/lib/postgresql/data/
networks:
Expand Down
20 changes: 12 additions & 8 deletions indexer/cron.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from datetime import datetime

from django_cron import CronJobBase, Schedule
Expand All @@ -12,20 +13,21 @@ class BaseCron(CronJobBase):
clean = False

def do(self):
result = False
result = ''
start = datetime.now()
action = "Full" if self.clean else "Incremental"
object_type = self.object_type if self.object_type else "all"
indexed = []
print("{} indexing of {} records started at {}".format(action, object_type, start))
try:
indexed = Indexer().add(object_type=self.object_type, clean=self.clean)
end = datetime.now()
print("{} records indexed in {}".format(len(indexed), end - start))
result = "{} index of {} records complete at {}\n".format(action, object_type, end)
except Exception as e:
result = str(e)
print(e)
end = datetime.now()
print("{} records indexed in {}".format(len(indexed), end - start))
print("{} index of {} records complete at {}\n".format(action, object_type, end))
result = True
print(result)
return result


Expand Down Expand Up @@ -92,7 +94,9 @@ class CleanUpCompleted(CronJobBase):

def do(self):
try:
return IndexRun.objects.filter(indexrunerror__isnull=True, status=IndexRun.FINISHED).delete()
retval = IndexRun.objects.filter(indexrunerror__isnull=True, status=IndexRun.FINISHED).delete()
result = json.dumps(retval)
except Exception as e:
print("Error cleaning up completed IndexRun objects: {}".format(e))
return False
result = "Error cleaning up completed IndexRun objects: {}".format(e)
print(result)
return result
1 change: 1 addition & 0 deletions indexer/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from electronbonder.client import ElectronBond
from rac_es.documents import (Agent, BaseDescriptionComponent, Collection,
Object, Term)

from scorpio import settings

from .models import IndexRun, IndexRunError
Expand Down
5 changes: 5 additions & 0 deletions indexer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from elasticsearch_dsl import connections
from rac_es.documents import BaseDescriptionComponent
from rest_framework.test import APIClient, APIRequestFactory

from scorpio import settings

from .cron import (CleanUpCompleted, IndexAgents, IndexAgentsClean, IndexAll,
Expand Down Expand Up @@ -104,3 +105,7 @@ def test_cleanup(self):
def test_process(self):
self.index_objects()
self.delete_objects()

def test_ping_view(self):
response = self.client.get(reverse('ping'))
self.assertEqual(response.status_code, 200)
23 changes: 11 additions & 12 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
asterism==0.7.2
Django==3.2.10
django-cron==0.5.1
djangorestframework==3.12.4
elasticsearch==7.13.1
elasticsearch-dsl==7.3.0
ElectronBonder==0.7.2
health-check==3.4.1
odin==1.7.0
psycopg2-binary==2.9.1
rac-es==0.17.2
requests==2.25.1
asterism~=0.9
Django~=4.1
django4-cron~=0.5
djangorestframework~=3.13
elasticsearch~=7.17
elasticsearch-dsl~=7.4
ElectronBonder~=1.1
odin~=1.7
psycopg2-binary~=2.9
rac-es~=1.0
requests~=2.28
Loading