Add cleaning commands as "docker compose run" options, update documentation to reflect changes

clean-as-scripts
Peter Rauscher 2023-04-16 20:39:24 -04:00
parent 62a4598f7c
commit b0d611e1a5
8 changed files with 33 additions and 37 deletions

View File

@ -6,7 +6,6 @@ ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1
FROM base AS python-deps
# Install pipenv and compilation dependencies
@ -17,8 +16,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends libpq-dev build
COPY Pipfile .
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy --skip-lock --verbose
FROM base AS runtime
# Copy virtual env from python-deps stage
@ -26,7 +23,6 @@ COPY --from=python-deps /.venv /.venv
ENV PATH="/.venv/bin:$PATH"
ENV PATH="$PATH:/usr/local/bin"
RUN apt-get update && apt-get install libpq5 -y
# Create and switch to a new user
@ -48,4 +44,4 @@ RUN chmod -R +x scripts
USER appuser
# Run the application
ENTRYPOINT ["./scripts/test-and-run.sh"]
ENTRYPOINT ["./scripts/run.sh"]

View File

@ -4,19 +4,19 @@ When you make database changes, or add new stopwords, you'll want to completely
To erase & recreate the database _NOW_, you can run:
```bash
docker exec -it oapen-suggestion-service-oapen-engine-1 "/home/appuser/scripts/clean.sh"
docker compose run oapen-engine clean now
```
> *WARNING*: You will lose ALL database data! Reruns are resource-intensive and lengthy, be sure before running this. This _could_ cause unexpected errors if the running service is active, in which case you will need to restart with `docker compose up`.
> *WARNING*: You will lose ALL database data! Reruns are resource-intensive and lengthy, be sure before running this. This _could_ cause unexpected errors if the running service is active, in which case you will need to restart the container.
To erase & recreate the database _on the next run_, you can run:
```bash
docker exec -it oapen-suggestion-service-oapen-engine-1 "/home/appuser/scripts/mark-for-cleaning.sh"
docker compose run oapen-engine clean true
```
> *WARNING*: You will lose ALL database data! Reruns are resource-intensive and lengthy, be sure before running this. This is safer than the last command and should not cause any breakage, even if the database is being used by the service actively.
To cancel the operation above, so the database is _not_ erased on the next run, you can run:
```bash
docker exec -it oapen-suggestion-service-oapen-engine-1 "/home/appuser/scripts/do-not-clean.sh"
docker compose run oapen-engine clean false
```
### How it works

View File

@ -1,3 +0,0 @@
#!/bin/sh
python src/tasks/clean.py "now"

View File

@ -1,3 +0,0 @@
#!/bin/sh
python src/tasks/clean.py "false"

View File

@ -1,3 +0,0 @@
#!/bin/sh
python src/tasks/clean.py "true"

View File

@ -0,0 +1,23 @@
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Running tests..."
python src/test/data/run_tests.py
echo "Running app..."
python src/tasks/daemon.py
elif [ "$1" == "clean" ]; then
if [ "$2" == "now" ] || [ "$2" == "true" ] || [ "$2" == "false" ]; then
python src/tasks/clean.py $2
else
echo "Invalid arguments for clean. Valid options are 'now', 'true', or 'false'."
echo "
Usage: docker compose run oapen-engine clean [now/true/false]
Options:
now Clean the database now. Drops ALL DATA in the database!
true Clean the database on the next run of the service. Drops ALL DATA in the database!
false Do not clean the database on the next run. Leaves the database as it is."
exit 1
fi
else
echo "Invalid command. Valid commands are 'clean', or you can leave it blank to run the daemon."
exit 1
fi

View File

@ -1,9 +0,0 @@
#!/bin/sh
# exit when any command fails
set -e
echo "Running tests..." && \
python src/test/data/run_tests.py && \
echo "Running app" && \
python src/tasks/daemon.py

View File

@ -156,22 +156,17 @@ def run():
if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] in ["now", "true", "false"]:
connection = get_connection()
if sys.argv[1] == "now":
run()
elif sys.argv[1] == "true":
connection = get_connection()
mark_for_cleaning(connection)
logger.warning("WARNING: The database will be ERASED on the next run.")
connection.close()
elif sys.argv[1] == "false":
connection = get_connection()
mark_no_clean(connection)
logger.info("The database will not be cleaned on the next run.")
connection.close()
connection.close()
else:
logger.error("""
usage: clean.py [true or false]
options:
now Clean the database now. Drops ALL DATA in the database!
true Clean the database on the next run of the service. Drops ALL DATA in the database!
false Do not clean the database on the next run. Leaves the database as it is.
"""
)
logger.error("Invalid argument supplied to clean.py. Valid options are 'now', 'true', or 'false'.")