Skip to content

Commit bc3cca6

Browse files
authored
Merge pull request #11 from finmars-platform/PLAT-1843
Update make file commands
2 parents 4f8bf57 + 23539b8 commit bc3cca6

File tree

8 files changed

+140
-46
lines changed

8 files changed

+140
-46
lines changed

.env.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ DB_NAME=finmars_dev
22
DB_USER=postgres
33
DB_PASSWORD=postgres
44
DB_HOST=172.17.0.1
5-
DB_PORT=5434
5+
DB_PORT=5432
66
DEBUG=False
77
LOCAL=1
88
AWS_STORAGE_BUCKET_NAME=YOUR_AWS_STORAGE_BUCKET_NAME

Makefile

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,8 @@ help:
1919
@echo " make manage - Run manage.py command"
2020
@echo " make manage-help - Show available manage.py commands"
2121

22-
env:
23-
@if [ -f .env ]; then \
24-
read -p ".env already exists. Overwrite? (y/N): " ans; \
25-
if [ "$$ans" = "y" ] || [ "$$ans" = "Y" ]; then \
26-
cp .env.sample .env; \
27-
echo ".env overwritten."; \
28-
else \
29-
echo "Skipped creating .env."; \
30-
fi; \
31-
else \
32-
cp .env.sample .env; \
33-
echo ".env created from .env.sample."; \
34-
fi
22+
generate-env:
23+
./generate_env.sh
3524

3625
venv:
3726
python3 -m venv $(VENV_NAME)
@@ -48,6 +37,12 @@ test:
4837
lint:
4938
$(COMPOSE) exec -i $(SERVICE) ruff format --exclude '**/migrations/*.py'
5039

40+
migrate:
41+
./migrate.sh
42+
43+
import-sql:
44+
./import-sql.sh
45+
5146
up:
5247
$(COMPOSE) up --build
5348

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,11 @@ basename="import_csv",
318318
* `main` - Start when PR merge in `main` branch. Increment patch version and publish release candidate image.
319319
* `release` - Start manually from `main` branch. Increment minor version and publish stable image
320320
* `patch_release` - Start manually from `main` branch. Publish current version stable image
321+
322+
323+
# First start
324+
325+
1) make generate-env
326+
2) make import-sql (fror demo or restore db from dump)
327+
3) make migrate
328+
4) make up

docker-compose.override.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

docker-compose.yml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ services:
55
- .env
66
volumes:
77
- ./poms:/var/app/poms
8+
depends_on:
9+
- db
10+
- rabbitmq
11+
- redis
812
restart: always
913
ports:
1014
- "8000:8080"
@@ -16,6 +20,10 @@ services:
1620
environment:
1721
- DJANGO_SETTINGS_MODULE=poms_app.settings # remove after change manage.py location
1822
- INSTANCE_TYPE=worker
23+
depends_on:
24+
- db
25+
- rabbitmq
26+
- redis
1927

2028
scheduler:
2129
build: .
@@ -24,13 +32,49 @@ services:
2432
environment:
2533
- DJANGO_SETTINGS_MODULE=poms_app.settings # remove after change manage.py location
2634
- INSTANCE_TYPE=beat
35+
depends_on:
36+
- db
37+
- rabbitmq
38+
- redis
2739

2840
migration:
2941
build: .
3042
env_file:
3143
- .env
3244
environment:
33-
- INSTANCE_TYPE=job
45+
- DJANGO_SETTINGS_MODULE=poms_app.settings # remove after change manage.py location
46+
- INSTANCE_TYPE=job
47+
depends_on:
48+
- db
49+
- redis
50+
51+
db:
52+
image: postgres:13-alpine
53+
environment:
54+
POSTGRES_USER: postgres
55+
POSTGRES_PASSWORD: postgres
56+
POSTGRES_DB: finmars_dev
57+
POSTGRESQL_MAX_OPEN_CONNS: 500
58+
stdin_open: true
59+
tty: true
60+
ports:
61+
- "5432:5432"
62+
volumes:
63+
- ./postgres_data:/var/lib/postgresql/data
64+
65+
rabbitmq:
66+
image: rabbitmq
67+
ports:
68+
- "5672:5672"
69+
stdin_open: true
70+
tty: true
71+
72+
redis:
73+
image: redis
74+
ports:
75+
- "6379:6379"
76+
stdin_open: true
77+
tty: true
3478

3579
volumes:
3680
postgres_data:

generate_env.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
ENV_FILE=".env"
4+
ENV_SAMPLE_FILE=".env.sample"
5+
6+
if [ -f "$ENV_FILE" ]; then
7+
read -p "$ENV_FILE already exists. Overwrite? (y/N): " ans
8+
if [[ "$ans" != "y" && "$ans" != "Y" ]]; then
9+
echo "Skipped creating $ENV_FILE."
10+
exit 0
11+
fi
12+
fi
13+
14+
cp "$ENV_SAMPLE_FILE" "$ENV_FILE"
15+
16+
SECRET_KEY=$(openssl rand -base64 64 | tr -dc 'a-zA-Z0-9!@#$%^&*(-_=+)' | head -c 50)
17+
18+
sed -i.bak "s|YOUR_DJANGO_SECRET_KEY|$SECRET_KEY|" "$ENV_FILE"
19+
rm "${ENV_FILE}.bak"
20+
21+
echo "$ENV_FILE created with new SECRET_KEY."

import-sql.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "🚀 Starting PostgreSQL container..."
5+
docker compose up -d db
6+
7+
echo "⏳ Waiting for PostgreSQL to be ready..."
8+
until docker exec $(docker compose ps -q db) pg_isready -U postgres > /dev/null 2>&1; do
9+
sleep 1
10+
done
11+
12+
echo "✅ PostgreSQL is ready."
13+
14+
echo "📦 Creating database..."
15+
echo "🔍 Checking if database 'core_realm00000' exists..."
16+
if docker exec -i $(docker compose ps -q db) psql -U postgres -tAc "SELECT 1 FROM pg_database WHERE datname = 'core_realm00000'" | grep -q 1; then
17+
echo "✅ Database 'core_realm00000' already exists."
18+
else
19+
echo "➕ Creating database 'core_realm00000'..."
20+
docker exec -i $(docker compose ps -q db) psql -U postgres -c "CREATE DATABASE core_realm00000;"
21+
fi
22+
23+
echo "🚚 Importing from data from dump"
24+
docker exec -i $(docker compose ps -q db) psql -U postgres -d core_realm00000 < ./core.sql
25+
26+
docker compose down
27+
echo "✅ Done!"

migrate.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "🚀 Starting Redis container..."
5+
docker compose up -d redis
6+
7+
echo "🚀 Starting PostgreSQL container..."
8+
docker compose up -d db
9+
10+
echo "⏳ Waiting for PostgreSQL to be ready..."
11+
until docker exec $(docker compose ps -q db) pg_isready -U postgres > /dev/null 2>&1; do
12+
sleep 1
13+
done
14+
15+
echo "✅ PostgreSQL is ready."
16+
17+
echo "📦 Creating database..."
18+
echo "🔍 Checking if database 'core_realm00000' exists..."
19+
if docker exec -i $(docker compose ps -q db) psql -U postgres -tAc "SELECT 1 FROM pg_database WHERE datname = 'core_realm00000'" | grep -q 1; then
20+
echo "✅ Database 'core_realm00000' already exists."
21+
else
22+
echo "➕ Creating database 'core_realm00000'..."
23+
docker exec -i $(docker compose ps -q db) psql -U postgres -c "CREATE DATABASE core_realm00000;"
24+
fi
25+
26+
echo "🚚 Running migration"
27+
docker compose run --build --rm migration
28+
29+
docker compose down
30+
echo "✅ Done!"

0 commit comments

Comments
 (0)