Skip to content

Commit 4a5cf55

Browse files
authored
Separated migration (#21)
1 parent b6cbb7e commit 4a5cf55

File tree

5 files changed

+140
-65
lines changed

5 files changed

+140
-65
lines changed
Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
11
#!/bin/sh
22

3-
43
echo " _____ __________.___"
54
echo " / _ \\______ \ |"
65
echo " / /_\ \| ___/ |"
76
echo "/ | \ | | |"
87
echo "\____|__ /____| |___|"
98
echo " \/"
109

11-
1210
set -e
1311

14-
printf "Checking database connection...\n\n"
15-
mysql_ready() {
16-
mysqladmin ping --host="$DB_HOST" --user="$DB_USER" --password="$DB_PASSWORD" > /dev/null 2>&1
17-
}
18-
19-
while ! (mysql_ready)
20-
do
21-
sleep 3
22-
echo "Waiting for database connection ..."
23-
done
24-
25-
echo "Database is ready..."
26-
27-
echo "Starting migration..."
28-
npm run migrate:up
29-
echo "Finished migration..."
30-
3112
exec "$@"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
echo " _____ .__ __ .__ "
4+
echo " / \ |__| ________________ _/ |_|__| ____ ____ "
5+
echo " / \ / \| |/ ___\_ __ \__ \\ __\ |/ _ \ / \ "
6+
echo "/ Y \ / /_/ > | \// __ \| | | ( <_> ) | \ "
7+
echo "\____|__ /__\___ /|__| (____ /__| |__|\____/|___| / "
8+
echo " \/ /_____/ \/ \/ "
9+
10+
set -e
11+
12+
printf "Checking database connection...\n\n"
13+
mysql_ready() {
14+
mysqladmin ping --host="$DB_HOST" --user="$DB_USER" --password="$DB_PASSWORD" > /dev/null 2>&1
15+
}
16+
17+
while ! (mysql_ready)
18+
do
19+
sleep 3
20+
echo "Waiting for database connection ..."
21+
done
22+
23+
echo "Database is ready..."
24+
25+
echo "Starting migration..."
26+
npm run migrate:up
27+
echo "Finished migration..."
28+

docker-compose.actions.yml

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,47 @@ services:
1616
ports:
1717
- 80:80
1818

19+
mysql:
20+
container_name: mysql
21+
image: mysql:8.0
22+
networks:
23+
- internal
24+
ports:
25+
- 3307:3306
26+
volumes:
27+
- ./mysql/conf.d:/etc/mysql/conf.d
28+
- mysql_data:/var/lib/mysql
29+
command: --default-authentication-plugin=mysql_native_password
30+
environment:
31+
- MYSQL_ROOT_PASSWORD=root
32+
- MYSQL_DATABASE=boilerplate
33+
- TZ=Australia/Melbourne
34+
35+
migration:
36+
container_name: migration
37+
image: $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:api-dev
38+
depends_on:
39+
- mysql
40+
networks:
41+
- internal
42+
environment:
43+
- DB_HOST=mysql
44+
- DB_PORT=3306
45+
- DB_USER=root
46+
- DB_PASSWORD=root
47+
- DB_NAME=boilerplate
48+
- DB_CONNECTION_LIMIT=10
49+
- DB_DEBUG=true
50+
- TZ=Australia/Melbourne
51+
command:
52+
- /usr/local/bin/migration.sh
53+
1954
api:
2055
container_name: api
2156
image: $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:api-dev
2257
depends_on:
2358
- mysql
59+
- migration
2460
networks:
2561
- internal
2662
environment:
@@ -81,21 +117,6 @@ services:
81117
- API_URL=http://api:3000
82118
command: npm run serve
83119

84-
mysql:
85-
container_name: mysql
86-
image: mysql:8.0
87-
networks:
88-
- internal
89-
ports:
90-
- 3307:3306
91-
volumes:
92-
- ./mysql/conf.d:/etc/mysql/conf.d
93-
- mysql_data:/var/lib/mysql
94-
command: --default-authentication-plugin=mysql_native_password
95-
environment:
96-
- MYSQL_ROOT_PASSWORD=root
97-
- MYSQL_DATABASE=boilerplate
98-
- TZ=Australia/Melbourne
99120

100121
mailhog:
101122
container_name: mailhog

docker-compose.prod.yml

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,47 @@ services:
1616
ports:
1717
- 80:80
1818

19+
mysql:
20+
container_name: mysql
21+
image: mysql:8.0
22+
networks:
23+
- internal
24+
ports:
25+
- 3307:3306
26+
volumes:
27+
- ./mysql/conf.d:/etc/mysql/conf.d
28+
- mysql_data:/var/lib/mysql
29+
command: --default-authentication-plugin=mysql_native_password
30+
environment:
31+
- MYSQL_ROOT_PASSWORD=root
32+
- MYSQL_DATABASE=boilerplate
33+
- TZ=Australia/Melbourne
34+
35+
migration:
36+
container_name: migration
37+
image: $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:api-latest
38+
depends_on:
39+
- mysql
40+
networks:
41+
- internal
42+
environment:
43+
- DB_HOST=mysql
44+
- DB_PORT=3306
45+
- DB_USER=root
46+
- DB_PASSWORD=root
47+
- DB_NAME=boilerplate
48+
- DB_CONNECTION_LIMIT=10
49+
- DB_DEBUG=true
50+
- TZ=Australia/Melbourne
51+
command:
52+
- /usr/local/bin/migration.sh
53+
1954
api:
2055
container_name: api
2156
image: $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:api-latest
2257
depends_on:
2358
- mysql
59+
- migration
2460
networks:
2561
- internal
2662
environment:
@@ -79,22 +115,6 @@ services:
79115
environment:
80116
- API_URL=http://$SERVICE_DOMAIN/api
81117

82-
mysql:
83-
container_name: mysql
84-
image: mysql:8.0
85-
networks:
86-
- internal
87-
ports:
88-
- 3307:3306
89-
volumes:
90-
- ./mysql/conf.d:/etc/mysql/conf.d
91-
- mysql_data:/var/lib/mysql
92-
command: --default-authentication-plugin=mysql_native_password
93-
environment:
94-
- MYSQL_ROOT_PASSWORD=root
95-
- MYSQL_DATABASE=boilerplate
96-
- TZ=Australia/Melbourne
97-
98118
mailhog:
99119
container_name: mailhog
100120
image: mailhog/mailhog

docker-compose.yml

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,53 @@ services:
1616
ports:
1717
- 80:80
1818

19+
mysql:
20+
container_name: mysql
21+
image: mysql:8.0
22+
networks:
23+
- internal
24+
ports:
25+
- 3307:3306
26+
volumes:
27+
- ./mysql/conf.d:/etc/mysql/conf.d
28+
- mysql_data:/var/lib/mysql
29+
command: --default-authentication-plugin=mysql_native_password
30+
environment:
31+
- MYSQL_ROOT_PASSWORD=root
32+
- MYSQL_DATABASE=boilerplate
33+
- TZ=Australia/Melbourne
34+
35+
migration:
36+
container_name: migration
37+
build:
38+
context: ./api
39+
target: dev-stage
40+
depends_on:
41+
- mysql
42+
networks:
43+
- internal
44+
# volumes:
45+
# - ./api:/srv
46+
environment:
47+
- DB_HOST=mysql
48+
- DB_PORT=3306
49+
- DB_USER=root
50+
- DB_PASSWORD=root
51+
- DB_NAME=boilerplate
52+
- DB_CONNECTION_LIMIT=10
53+
- DB_DEBUG=true
54+
- TZ=Australia/Melbourne
55+
command:
56+
- /usr/local/bin/migration.sh
57+
1958
api:
2059
container_name: api
2160
build:
2261
context: ./api
2362
target: dev-stage
2463
depends_on:
2564
- mysql
65+
- migration
2666
networks:
2767
- internal
2868
# volumes:
@@ -100,21 +140,6 @@ services:
100140
- BASE_URL=/backend/
101141
- API_URL=http://localhost/api
102142

103-
mysql:
104-
container_name: mysql
105-
image: mysql:8.0
106-
networks:
107-
- internal
108-
ports:
109-
- 3307:3306
110-
volumes:
111-
- ./mysql/conf.d:/etc/mysql/conf.d
112-
- mysql_data:/var/lib/mysql
113-
command: --default-authentication-plugin=mysql_native_password
114-
environment:
115-
- MYSQL_ROOT_PASSWORD=root
116-
- MYSQL_DATABASE=boilerplate
117-
- TZ=Australia/Melbourne
118143

119144
mailhog:
120145
container_name: mailhog

0 commit comments

Comments
 (0)