Skip to content

Commit a43487d

Browse files
committed
change running command and Init database.
1 parent b8141ff commit a43487d

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

docker/cms-dev.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,21 @@
22
set -x
33

44
GIT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD | tr A-Z a-z)
5+
PROJECT_NAME="cms-$GIT_BRANCH_NAME"
6+
COMPOSE_FILE="docker/docker-compose.dev.yml"
57

6-
docker compose -p cms-$GIT_BRANCH_NAME -f docker/docker-compose.dev.yml run --build --rm --service-ports devcms
8+
# 1. Start Containers ในโหมด Detached (--build: build image ถ้าจำเป็น)
9+
# คำสั่งนี้จะสร้าง/เริ่มต้น Container ทั้ง devdb และ devcms และปล่อยให้รันอยู่เบื้องหลัง
10+
echo "Starting containers in detached mode: $PROJECT_NAME"
11+
docker compose -p "$PROJECT_NAME" -f "$COMPOSE_FILE" up -d --build
12+
13+
# 2. รอให้ Database พร้อม (เพิ่มความมั่นใจในการเชื่อมต่อ)
14+
# ใช้ wait-for-it หรือเพียงแค่ sleep สั้นๆ
15+
# (เนื่องจาก 'wait-for-it' ในไฟล์ compose ของคุณถูกรันใน command ของ devcms
16+
# ดังนั้นเราจะข้ามไปใช้ exec เลย แต่ต้องแน่ใจว่า devdb มีเวลา start)
17+
sleep 5
18+
19+
# 3. เข้าสู่ Container devcms เพื่อทำงาน (ใช้ exec แทน run --rm)
20+
# exec จะทำให้คุณเข้าสู่ Container ที่รันอยู่แล้ว ข้อมูลจึงยังคงอยู่
21+
echo "Attaching to devcms container..."
22+
docker compose -p "$PROJECT_NAME" -f "$COMPOSE_FILE" exec devcms bash

docker/docker-compose.dev.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
environment:
55
POSTGRES_HOST_AUTH_METHOD: trust
66
volumes:
7-
- "../.dev/postgres-data:/var/lib/postgresql/data"
7+
- "devdb_data:/var/lib/postgresql/data"
88

99
devcms:
1010
build: ..
@@ -17,9 +17,11 @@ services:
1717
- "..:/home/cmsuser/src"
1818
privileged: true
1919
cgroup: host
20-
command: >
21-
wait-for-it devdb:5432 -- bash
20+
command: ["tail", "-f", "/dev/null"]
2221
ports:
2322
- 8888:8888
2423
- 8889:8889
2524
- 8890:8890
25+
26+
volumes:
27+
devdb_data:

0 commit comments

Comments
 (0)