Skip to content

Commit 3336cc6

Browse files
feat: provision to use local db as data source for dockerized api (#441)
1 parent 9b13da5 commit 3336cc6

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

apps/api/docs/development-setup.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ This script will periodically call OsmoX APIs that facilitate the following proc
8282
- Provider Confirmation of all `Awaiting Confirmation` notifications
8383
- Archiving of all completed notifications in `notify_notifications` table
8484

85+
## ALTERNATIVELY – Dockerize the application and use a local database instead of the dockerized one
86+
87+
Follow this guide to [Dockerize the application and use local db instead of dockerized db](./use-local-db-instead-of-dockerized-db/README.md)
88+
8589
## Use the application
8690

8791
For details on using the application and making API calls, refer to our [Usage Guide](usage-guide.md).
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Use local db instead of dockerized db
2+
3+
Set up `osmox-api` docker container to use local postgres database
4+
5+
## Description
6+
7+
- Override the existing Docker Compose file to exclude creation of the PostgreSQL container and its associated volume
8+
- Utilize local PostgreSQL database as the data source for a Dockerized API
9+
10+
## Steps
11+
12+
1. Clone the repository:
13+
14+
```bash
15+
git clone https://github.com/OsmosysSoftware/osmo-x.git
16+
cd osmo-x/apps/api/docs/use-local-db-instead-of-dockerized-db/
17+
```
18+
19+
2. Create `docker-compose.override.yml` where `docker-compose.yml` exists and copy the contents of `docker-compose-override-script.txt` in it
20+
21+
```bash
22+
# copy script from .txt file and create override script in osmo-x/apps/api
23+
cp docker-compose-override-script.txt ../../docker-compose.override.yml
24+
```
25+
26+
3. Go to `osmo-x/apps/api` and create `.env` file (if not already created)
27+
28+
```bash
29+
# In osmo-x/apps/api/docs/use-local-db-instead-of-dockerized-db/
30+
cd ../..
31+
# In osmo-x/apps/api
32+
cp .env.example .env
33+
```
34+
35+
4. Update the `.env` variables to use postgres database on your local machine
36+
37+
1. You need to set `DB_HOST` to your machine's IP address:
38+
- This is the IP address that other devices on your local network (including Docker containers) can use to reach your machine.
39+
- You can simply set `DB_HOST=host.docker.internal` on most setups.
40+
- If that does not work for your Docker engine, fall back to using the machine’s IP address:
41+
2. How to find your host IP:
42+
- **Windows:** Open Command Prompt/PowerShell, type `ipconfig`, look for IPv4 Address.
43+
- **macOS/Linux:** Open Terminal, type `ip addr`, look for your active network interface (e.g., en0, eth0, docker0) IP address.
44+
3. Update the `.env` variables:
45+
46+
```env
47+
# Database configuration
48+
DB_TYPE=postgres
49+
DB_HOST=<IP-ADDRESS-USED-TO-REACH-YOUR-HOST-MACHINE> # Value "host.docker.internal" should work on most setups
50+
DB_PORT=<POSTGRES-PORT-FOR-LOCAL-MACHINE> # Set the port used by postgres of your local machine
51+
DB_USERNAME=your-username
52+
DB_PASSWORD=your-password
53+
DB_NAME=your-database
54+
DB_DOCKER_PORT=5433 # IGNORE. Will not be used for current setup
55+
```
56+
57+
5. Build and run the docker compose command
58+
59+
```bash
60+
# In osmo-x/apps/api
61+
docker compose up --build
62+
```
63+
64+
6. To dockerize the application normally, remove the override file and build the containers again
65+
66+
```bash
67+
docker compose down -v
68+
rm docker-compose.override.yml
69+
# Update the .env variables accordingly
70+
docker compose up --build
71+
```
72+
73+
For more details, go through the [osmo-x production setup using docker](../production-setup.md#using-docker)
74+
75+
## References
76+
77+
- https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/
78+
- https://docs.docker.com/reference/compose-file/merge/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
osmox-api:
3+
depends_on: !override
4+
osmox-redis:
5+
condition: service_healthy
6+
7+
osmox-postgres: !reset null
8+
9+
volumes:
10+
osmox-postgres-data-saas: !reset null

apps/api/scripts/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Before you begin, ensure you have the following software installed:
4242
```bash
4343
pip install -r requirements.txt
4444
```
45+
4546
3. Each script accepts arguments for log directory relative to the `scripts` folder.
4647
1. `--log-dir`: ../logs
4748
2. `--output-dir`: .

0 commit comments

Comments
 (0)