File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -65,10 +65,11 @@ before_install:
65
65
66
66
# Setup environment
67
67
- " export MYSQL_DATABASE=node_mysql"
68
+ - " export MYSQL_PORT=$(node tool/free-port.js)"
68
69
- " export MYSQL_USER=root"
69
70
70
71
install :
71
- - " docker run -d --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e MYSQL_DATABASE=$MYSQL_DATABASE $DOCKER_MYSQL_TYPE:$DOCKER_MYSQL_VERSION"
72
+ - " docker run -d --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e MYSQL_DATABASE=$MYSQL_DATABASE -p $MYSQL_PORT:3306 $DOCKER_MYSQL_TYPE:$DOCKER_MYSQL_VERSION"
72
73
- " npm install"
73
74
- " docker run --link mysql:db -e CHECK_PORT=3306 -e CHECK_HOST=db giorgos/takis"
74
75
Original file line number Diff line number Diff line change
1
+ var Net = require ( 'net' ) ;
2
+
3
+ var PORT_END = 60000 ;
4
+ var PORT_START = 1000 ;
5
+ var TCP_TIMEOUT = 1000 ;
6
+
7
+ process . nextTick ( run ) ;
8
+
9
+ function check ( port , callback ) {
10
+ var socket = Net . createConnection ( port , 'localhost' ) ;
11
+ var timer = setTimeout ( function ( ) {
12
+ socket . destroy ( ) ;
13
+ callback ( undefined ) ;
14
+ } , TCP_TIMEOUT ) ;
15
+
16
+ socket . on ( 'connect' , function ( ) {
17
+ clearTimeout ( timer ) ;
18
+ socket . destroy ( ) ;
19
+ callback ( true ) ;
20
+ } ) ;
21
+
22
+ socket . on ( 'error' , function ( err ) {
23
+ clearTimeout ( timer ) ;
24
+ if ( err . syscall === 'connect' && err . code === 'ECONNREFUSED' ) {
25
+ callback ( false ) ;
26
+ } else {
27
+ callback ( undefined ) ;
28
+ }
29
+ } ) ;
30
+ }
31
+
32
+ function run ( ) {
33
+ function next ( ) {
34
+ var port = PORT_START + Math . floor ( Math . random ( ) * ( PORT_END - PORT_START + 1 ) ) ;
35
+
36
+ check ( port , function ( used ) {
37
+ if ( used === false ) {
38
+ console . log ( '%d' , port ) ;
39
+ process . exit ( 0 ) ;
40
+ } else {
41
+ setTimeout ( next , 0 ) ;
42
+ }
43
+ } ) ;
44
+ }
45
+
46
+ next ( ) ;
47
+ }
You can’t perform that action at this time.
0 commit comments