Skip to content

Commit b4bced7

Browse files
FIX check connection sql in local
1 parent b16e054 commit b4bced7

File tree

6 files changed

+45
-39
lines changed

6 files changed

+45
-39
lines changed

.env.api.local

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ API_HOST=0.0.0.0
1212
API_PORT=5000
1313

1414
# Database service configuration
15+
DATABASE=postgres
1516
BBDD_HOST=db_service
1617
BBDD_PORT=5432
17-
DATABASE=postgres
18+
POSTGRES_DB=db_dev
19+
POSTGRES_USER=db_user
20+
PGPASSWORD=db_password
21+
1822
DATABASE_TEST_URL=postgresql+psycopg2://db_user:db_password@db_service:5432/db_test
1923
DATABASE_URL=postgresql+psycopg2://db_user:db_password@db_service:5432/db_dev

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
FROM python:3.9-slim
22

3-
# Install nmap
4-
RUN apt-get update && apt-get install -y nmap
5-
63
WORKDIR /app
74

5+
# Update the package lists and install the PostgreSQL client
6+
RUN apt-get update && apt-get install -y postgresql-client
7+
88
COPY requirements.txt /app
99

1010
RUN pip install --upgrade pip

README.md

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -217,27 +217,31 @@ Containerized services separately with PostgreSQL databases (db), API (api) and
217217
1. Create **.env.api.local**, **.env.db.local** and **.env.cron.local** files and enter environment variables for
218218
each service. In the local environment there are 4 services (api, db, nginx, cron). For example:
219219
1. **.env.api.local**:
220-
```shell
221-
# APP configuration
222-
APP_NAME=[Name APP] # For example Flask API Rest Template
223-
APP_ENV=local
224-
225-
# Flask configuration
226-
API_ENTRYPOINT=app:app
227-
APP_SETTINGS_MODULE=config.LocalConfig
228-
APP_TEST_SETTINGS_MODULE=config.TestingConfig
229-
230-
# API service configuration
231-
API_HOST=<api_host> # For example 0.0.0.0
232-
API_PORT=<port_api> # For example 5000
233-
234-
# Database service configuration
235-
DB_HOST=<name_container_bbdd> # For example db (name service in docker-compose)
236-
DB_PORT=<port_container_bbdd> # For example 5432 (port service in docker-compose)
237-
DATABASE=postgres
238-
DATABASE_TEST_URL=<url database test> # For example postgresql+psycopg2://db_user:db_password@db:5432/db_test
239-
DATABASE_URL=<url database> # For example postgresql+psycopg2://db_user:db_password@db:5432/db_dev
240-
```
220+
```shell
221+
# APP configuration
222+
APP_NAME=[Name APP] # For example Flask API Rest Template
223+
APP_ENV=local
224+
225+
# Flask configuration
226+
API_ENTRYPOINT=app:app
227+
APP_SETTINGS_MODULE=config.LocalConfig
228+
APP_TEST_SETTINGS_MODULE=config.TestingConfig
229+
230+
# API service configuration
231+
API_HOST=<api_host> # For example 0.0.0.0
232+
API_PORT=<port_api> # For example 5000
233+
234+
# Database service configuration
235+
DATABASE=postgres
236+
DB_HOST=<name_container_bbdd> # For example db_service (name service in docker-compose)
237+
DB_PORT=<port_container_bbdd> # For example 5432 (port service in docker-compose)
238+
POSTGRES_DB=<name_database> # For example db_dev
239+
POSTGRES_USER=<name_user> # For example db_user
240+
PGPASSWORD=<password_user> # For example db_password
241+
242+
DATABASE_TEST_URL=<url database test> # For example postgresql+psycopg2://db_user:db_password@db_service:5432/db_test
243+
DATABASE_URL=<url database> # For example postgresql+psycopg2://db_user:db_password@db_service:5432/db_dev
244+
```
241245
2. **.env.db.local**:
242246
```shell
243247
POSTGRES_USER=<name_user> # For example db_user

entrypoint.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
#!/bin/sh
22

3-
if [[ -z "${APP_ENV}" ]]; then
4-
echo "Add environment variable in production"
5-
6-
source .env.pro;
7-
fi
3+
echo "Start run entrypoint script..."
84

95
echo "Database:" $DATABASE
106

117
if [ "$DATABASE" = "postgres" ]
128
then
139
echo "Waiting for postgres..."
1410

15-
while ! nmap -p $BBDD_PORT --open -oG - $BBDD_HOST ; do
16-
sleep 0.1
11+
while ! psql -h $BBDD_HOST -U $POSTGRES_USER -d $POSTGRES_DB
12+
do
13+
echo "Waiting for PostgreSQL..."
14+
sleep 0.5
1715
done
1816

1917
echo "PostgreSQL started"

services/cron/Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ RUN apk update \
77
&& apk upgrade \
88
&& apk add --no-cache postgresql-client
99

10-
# Copy entry.sh
11-
COPY entry.sh /app
10+
# Copy entrypoint.sh
11+
COPY entrypoint.sh /app
1212

13-
# Chmod to entry.sh
14-
RUN chmod +x ./entry.sh
13+
# Chmod to entrypoint.sh
14+
RUN chmod +x ./entrypoint.sh
1515

16-
# Run entry.sh
17-
ENTRYPOINT ["/app/entry.sh"]
16+
# Run entrypoint.sh
17+
ENTRYPOINT [ "/app/entrypoint.sh" ]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ then
1515
echo "Waiting for postgres..."
1616

1717
while ! nc -z $BBDD_HOST $BBDD_PORT; do
18-
sleep 0.1
18+
sleep 0.5
1919
done
2020

2121
echo "PostgreSQL started"

0 commit comments

Comments
 (0)