Skip to content

Commit 40c5c74

Browse files
committed
Dockerize the stop import script
1 parent 587d5e1 commit 40c5c74

File tree

5 files changed

+24
-32
lines changed

5 files changed

+24
-32
lines changed

README.md

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -534,42 +534,17 @@ creates the source MSSQL database (_docker/mssql_init/populate.sql_) was changed
534534
535535
---
536536
537-
## Jore3 stop import script
537+
## Jore 3 stop import script
538538
539539
### Requirements
540540
541-
You need to have Python 3 installed on your system to run the script
542-
543-
#### Virtual environment
544-
545-
To run Python scripts with required libraries you should setup a virtual environment which contains the requirements for the script. To setup an environment, run:
546-
547-
`python3 -m venv LOCATION/OF/ENVIRONMENT/HERE`
548-
549-
Where you should replace the location with one you want to use. For example a directory under your home directory.
550-
To use the environment you can either source the virtual environment by running:
551-
552-
`source LOCATION/OF/ENVIRONMENT/HERE/bin/activate`
553-
554-
Which allows you to use the binaries directly as `python importer.py`
555-
556-
Or you can use the virtual environment python directly: `LOCATION/OF/ENVIRONMENT/HERE/bin/python importer.py`
557-
558-
#### Script setup
559-
560-
You need to run the `import.py` script using Python 3 and it requires the following libraries:
561-
562-
- pymssql
563-
- requests
564-
- simplejson
565-
566-
They can be installed by running `pip install -r requirements.txt`
541+
You need to have Docker installed on your system to run the script
567542
568543
### How to use
569544
570-
To run the stop registry importer script you need to have a Jore3 database, a populated Jore4 routes database, Jore4 Hasura and Jore4 Tiamat running.
545+
To run the stop registry importer script you need to have a Jore 3 database, a populated Jore 4 routes database and the `jore4-hasura` and `jore4-tiamat` microservices running.
571546
572-
By default the script runs from the local jore3 test database and uses the base local Jore4 Hasura instance as the target.
547+
By default the script runs from the local Jore 3 `mssqltestdb` database and uses the base local `jore4-hasura` service as the target.
573548
You can change the source database and target Hasura instance by creating a `.env` file in the same directory as the script.
574549
575550
Set the values for variables you want to set:
@@ -583,6 +558,8 @@ JORE3_DATABASE_URL=
583558
JORE3_DATABASE_NAME=
584559
```
585560
586-
You should have run the base Jore3 importer first which ensures the Jore4 database has the required scheduled stop points. Then run the stop registry import script which will match scheduled stop points in the Jore4 routes database with stops in the Jore3 database and generate GraphQL mutations to Hasura/Tiamat according to the data. The script will also link the generated stop registry stops with the scheduled stop points by their NeTEx ID using Hasura for the mutation.
561+
You should have run the base Jore 3 importer first which ensures the Jore 4 database has the required scheduled stop points. Then run the stop registry import script which will match scheduled stop points in the Jore 4 routes database with stops in the Jore 3 database and generate GraphQL mutations to Hasura/Tiamat according to the data. The script will also link the generated stop registry stops with the scheduled stop points by their NeTEx ID using Hasura for the mutation.
562+
563+
Running the script will produce multiple errors as there are many stops in the Jore 3 database with overlapping validity. These can be ingored as only the most recent one is the one which ends up being imported.
587564
588-
Running the script will produce multiple errors as there are many stops in the Jore3 database with overlapping validity. These can be ingored as only the most recent one is the one which ends up being imported.
565+
To run the script simply run `run-stop-registry-importer.sh` in the stop-registry-importer directory, this will create and run a Docker container with the environment set up.

stop-registry-importer/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM python:3.12
2+
3+
WORKDIR /app
4+
COPY requirements.txt .
5+
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
8+
COPY importer.py .
9+
COPY .env .
10+
11+
CMD ["python", "importer.py"]

importer.py renamed to stop-registry-importer/importer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
JORE3_DATABASE_NAME=(str,'jore3testdb')
1616
)
1717

18-
environ.Env.read_env(os.path.dirname(os.path.join(os.path.dirname(os.path.abspath(__file__)), '.env')))
18+
environ.Env.read_env('.env')
1919

2020
graphql = env('GRAPHQL_URL')
2121
secret = env('GRAPHQL_SECRET')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
docker build -t stop-registry-importer .
4+
docker run --network="host" stop-registry-importer

0 commit comments

Comments
 (0)