-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd42512
commit 1dc4588
Showing
1 changed file
with
30 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,21 +26,24 @@ cd <repository-directory> | |
|
||
Decide whether you're connecting to a **local PostgreSQL container** (using Docker) or a **remote PostgreSQL instance**. Configure this using `.env` files. | ||
|
||
#### **For Local PostgreSQL (Docker-based)**: | ||
#### **For Local PostgreSQL (Docker-based)** | ||
|
||
- Create a `.env.local` file based on the template below and specify `POSTGRES_HOST=postgres`. | ||
|
||
#### **For Remote PostgreSQL**: | ||
#### **For Remote PostgreSQL** | ||
|
||
- Create a `.env.remote-db` file and set `POSTGRES_HOST` to the external IP or hostname of the remote PostgreSQL instance. | ||
|
||
Example `.env.local`: | ||
|
||
```env | ||
POSTGRES_USER=refactor | ||
POSTGRES_PASSWORD=password | ||
POSTGRES_DB=refactor | ||
POSTGRES_HOST=postgres | ||
POSTGRES_PORT=5432 | ||
POSTGRES_SCHEMA=refactor_platform | ||
DATABASE_URL=postgres://refactor:password@postgres:5432/refactor_platform | ||
DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB | ||
SERVICE_PORT=4000 | ||
SERVICE_INTERFACE=0.0.0.0 | ||
USERNAME=appuser | ||
|
@@ -49,14 +52,15 @@ USER_GID=1000 | |
PLATFORM=linux/arm64 | ||
``` | ||
|
||
Example `.env.remote-db`: | ||
**Example** `.env.remote-db`: | ||
|
||
```env | ||
POSTGRES_USER=remote_refactor | ||
POSTGRES_PASSWORD=remote_password | ||
POSTGRES_DB=refactor | ||
POSTGRES_HOST=postgres.example.com | ||
POSTGRES_SCHEMA=refactor_platform | ||
DATABASE_URL=postgres://remote_refactor:[email protected]:5432/refactor_platform | ||
DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB | ||
POSTGRES_PORT=5432 | ||
SERVICE_PORT=4000 | ||
SERVICE_INTERFACE=0.0.0.0 | ||
|
@@ -98,7 +102,7 @@ services: | |
DATABASE_URL: ${POSTGRES_HOST}://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB} | ||
SERVICE_PORT: ${SERVICE_PORT} | ||
ports: | ||
- "${SERVIE_PORT}:4000" | ||
- "${SERVICE_PORT}:4000" | ||
depends_on: | ||
- postgres | ||
volumes: | ||
|
@@ -120,16 +124,18 @@ This builds the image for both `amd64` and `arm64` architectures. Use the `--pla | |
### **2. Build and Run with Docker Compose** | ||
|
||
#### For Local PostgreSQL: | ||
|
||
```bash | ||
docker-compose --env-file .env.local up --build | ||
``` | ||
|
||
#### For Remote PostgreSQL: | ||
|
||
```bash | ||
docker-compose --env-file .env.remote-db up --build | ||
``` | ||
|
||
The web API will be accessible at `http://localhost:<SERVICE_PORT>` . | ||
The web API will be accessible at `http://localhost:<SERVICE_PORT>` | ||
|
||
--- | ||
|
||
|
@@ -150,6 +156,11 @@ docker-compose run rust-app seed-db | |
### **Convert DBML to SQL** | ||
|
||
If you have a DBML file (`schema.dbml`), convert it to SQL: | ||
|
||
```bash | ||
docker-compose run -v $(pwd)/sql:/app/sql -v $(pwd)/schema.dbml:/app/schema.dbml rust-app dbml2sql | ||
``` | ||
|
||
```bash | ||
docker-compose run -v $(pwd)/sql:/app/sql -v $(pwd)/schema.dbml:/app/schema.dbml rust-app dbml2sql | ||
``` | ||
|
@@ -177,35 +188,41 @@ docker-compose down -v | |
### **Cannot Connect to PostgreSQL** | ||
|
||
1. Verify PostgreSQL is running: | ||
|
||
```bash | ||
docker-compose ps | ||
``` | ||
|
||
2. Check logs for PostgreSQL: | ||
|
||
```bash | ||
docker-compose logs postgres | ||
``` | ||
|
||
### **Web API Not Accessible** | ||
|
||
1. Verify the container is running: | ||
|
||
```bash | ||
docker-compose ps | ||
``` | ||
|
||
2. Check logs for the Rust app: | ||
|
||
```bash | ||
docker-compose logs rust-app | ||
``` | ||
|
||
3. Confirm the correct port in `.env`: | ||
|
||
```bash | ||
SERVICE_PORT=4000 | ||
``` | ||
|
||
### **Port Conflicts** | ||
|
||
Change the ports in `.env` or `docker-compose.yaml`: | ||
|
||
```yaml | ||
services: | ||
postgres: | ||
|
@@ -227,6 +244,7 @@ docker-compose up | |
### **Database Persistence** | ||
|
||
Ensure volumes are configured in `docker-compose.yaml`: | ||
|
||
```yaml | ||
volumes: | ||
postgres_data: | ||
|
@@ -237,16 +255,19 @@ volumes: | |
## Development Tips | ||
- Run containers in detached mode: | ||
```bash | ||
docker-compose up -d | ||
``` | ||
|
||
- Access a running container: | ||
|
||
```bash | ||
docker exec -it <container_name> bash | ||
``` | ||
|
||
- Restart a single service: | ||
|
||
```bash | ||
docker-compose restart rust-app | ||
``` | ||
|
@@ -256,11 +277,13 @@ volumes: | |
## Interactive Testing | ||
|
||
- Test interactively: | ||
|
||
```bash | ||
docker run -it rust-backend:latest | ||
``` | ||
|
||
- Debug inside the container: | ||
|
||
```bash | ||
docker run -it --entrypoint /bin/bash rust-backend:latest | ||
``` |