Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
persona
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hexang 息壤平台
persona
Commits
6762511c
Commit
6762511c
authored
13 years ago
by
Lloyd Hilaiel
Browse files
Options
Downloads
Patches
Plain Diff
partial impl of a server to deploy dev on commit
parent
4ce2d401
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/deploy/git.js
+31
-3
31 additions, 3 deletions
scripts/deploy/git.js
scripts/deploy_server.js
+148
-0
148 additions, 0 deletions
scripts/deploy_server.js
with
179 additions
and
3 deletions
scripts/deploy/git.js
+
31
−
3
View file @
6762511c
...
...
@@ -53,6 +53,16 @@ exports.currentSHA = function(dir, cb) {
});
};
function
splitAndEmit
(
chunk
,
cb
)
{
if
(
chunk
)
chunk
=
chunk
.
toString
();
if
(
typeof
chunk
===
'
string
'
)
{
chunk
.
split
(
'
\n
'
).
forEach
(
function
(
line
)
{
line
=
line
.
trim
();
if
(
line
.
length
)
cb
(
line
);
});
}
}
exports
.
push
=
function
(
dir
,
host
,
pr
,
cb
)
{
if
(
typeof
host
===
'
function
'
&&
cb
===
undefined
)
{
cb
=
pr
;
...
...
@@ -62,9 +72,27 @@ exports.push = function(dir, host, pr, cb) {
}
var
p
=
spawn
(
'
git
'
,
[
'
push
'
,
'
app@
'
+
host
+
"
:git
"
,
'
dev:master
'
],
{
cwd
:
dir
});
p
.
stdout
.
on
(
'
data
'
,
pr
);
p
.
stderr
.
on
(
'
data
'
,
pr
);
p
.
stdout
.
on
(
'
data
'
,
function
(
c
)
{
splitAndEmit
(
c
,
pr
);
});
p
.
stderr
.
on
(
'
data
'
,
function
(
c
)
{
splitAndEmit
(
c
,
pr
);
});
p
.
on
(
'
exit
'
,
function
(
code
,
signal
)
{
return
cb
(
code
=
0
);
});
};
exports
.
pull
=
function
(
dir
,
remote
,
branch
,
pr
,
cb
)
{
var
p
=
spawn
(
'
git
'
,
[
'
pull
'
,
"
-f
"
,
remote
,
branch
],
{
cwd
:
dir
});
p
.
stdout
.
on
(
'
data
'
,
function
(
c
)
{
splitAndEmit
(
c
,
pr
);
});
p
.
stderr
.
on
(
'
data
'
,
function
(
c
)
{
splitAndEmit
(
c
,
pr
);
});
p
.
on
(
'
exit
'
,
function
(
code
,
signal
)
{
return
cb
(
code
=
0
);
});
};
\ No newline at end of file
}
exports
.
init
=
function
(
dir
,
cb
)
{
var
p
=
spawn
(
'
git
'
,
[
'
init
'
],
{
cwd
:
dir
});
p
.
on
(
'
exit
'
,
function
(
code
,
signal
)
{
return
cb
(
code
=
0
);
});
};
This diff is collapsed.
Click to expand it.
scripts/deploy_server.js
0 → 100755
+
148
−
0
View file @
6762511c
#!/usr/bin/env node
const
temp
=
require
(
'
temp
'
),
path
=
require
(
'
path
'
),
util
=
require
(
'
util
'
),
events
=
require
(
'
events
'
),
git
=
require
(
'
./deploy/git.js
'
),
https
=
require
(
'
https
'
);
// a class capable of deploying and emmitting events along the way
function
Deployer
()
{
events
.
EventEmitter
.
call
(
this
);
// a directory where we'll keep code
this
.
_codeDir
=
'
/tmp/fuck
'
;
// temp.mkdirSync();
console
.
log
(
"
code dir is:
"
,
this
.
_codeDir
);
var
self
=
this
;
/*
git.init(this._codeDir, function(err) {
if (err) {
console.log("can't init code dir:", err);
process.exit(1);
}
self.emit('ready');
});
*/
// a directory where we'll deployment logs
this
.
_deployLogDir
=
temp
.
mkdirSync
();
console
.
log
(
"
deployment log dir is:
"
,
this
.
_deployLogDir
);
process
.
nextTick
(
function
()
{
self
.
emit
(
'
ready
'
);
});
}
util
.
inherits
(
Deployer
,
events
.
EventEmitter
);
Deployer
.
prototype
.
_getLatestRunningSHA
=
function
(
cb
)
{
// failure is not fatal. maybe nothing is running?
function
fail
(
err
)
{
self
.
emit
(
'
info
'
,
{
msg
:
"
can't get current running sha
"
,
reason
:
err
});
cb
(
null
,
null
);
}
var
self
=
this
;
https
.
get
({
host
:
'
dev.diresworb.org
'
,
path
:
'
/ver.txt
'
},
function
(
res
)
{
var
buf
=
""
;
res
.
on
(
'
data
'
,
function
(
c
)
{
buf
+=
c
});
res
.
on
(
'
end
'
,
function
()
{
try
{
var
sha
=
buf
.
split
(
'
'
)[
0
];
if
(
sha
.
length
==
7
)
{
self
.
emit
(
'
info
'
,
'
latest running is
'
+
sha
);
return
cb
(
null
,
sha
);
}
fail
(
'
malformed ver.txt:
'
+
buf
);
}
catch
(
e
)
{
fail
(
e
);
}
});
}).
on
(
'
error
'
,
function
(
err
)
{
fail
(
err
);
});
}
Deployer
.
prototype
.
_cleanupOldVMs
=
function
()
{
this
.
emit
(
'
error
'
,
"
not yet implemented
"
);
}
Deployer
.
prototype
.
_deployNewCode
=
function
(
cb
)
{
function
splitAndEmit
(
chunk
)
{
if
(
chunk
)
chunk
=
chunk
.
toString
();
if
(
typeof
chunk
===
'
string
'
)
{
chunk
.
split
(
'
\n
'
).
forEach
(
function
(
line
)
{
line
=
line
.
trim
();
if
(
line
.
length
)
self
.
emit
(
'
progress
'
,
line
);
});
}
}
var
p
=
spawn
(
'
scripts/deploy_dev.js
'
,
{
cwd
:
self
.
_codeDir
});
p
.
stdout
.
on
(
'
data
'
,
splitAndEmit
);
p
.
stderr
.
on
(
'
data
'
,
splitAndEmit
);
p
.
on
(
'
exit
'
,
function
(
code
,
signal
)
{
return
cb
(
code
=
0
);
});
};
Deployer
.
prototype
.
_pullLatest
=
function
(
cb
)
{
var
self
=
this
;
git
.
pull
(
this
.
_codeDir
,
'
git@github.com:mozilla/browserid
'
,
'
dev
'
,
function
(
l
)
{
self
.
emit
(
l
);
},
function
(
err
)
{
if
(
err
)
return
self
.
emit
(
'
error
'
,
err
);
git
.
currentSHA
(
self
.
_codeDir
,
function
(
err
,
latest
)
{
if
(
err
)
return
self
.
emit
(
'
error
'
,
err
);
self
.
emit
(
'
info
'
,
'
latest available sha is
'
+
latest
);
self
.
_getLatestRunningSHA
(
function
(
err
,
running
)
{
if
(
latest
!=
running
)
{
self
.
emit
(
'
deployment_begins
'
,
{
sha
:
latest
,
});
var
startTime
=
new
Date
();
self
.
_deployNewCode
(
function
(
err
,
res
)
{
if
(
err
)
return
self
.
emit
(
'
error
'
,
err
);
// deployment is complete!
self
.
emit
(
'
deployment_complete
'
,
{
sha
:
latest
,
time
:
(
startTime
-
new
Date
())
});
// finally, let's clean up old servers
self
.
_cleanUpOldVMS
();
});
}
else
{
self
.
emit
(
'
info
'
,
'
up to date
'
);
cb
(
null
,
null
);
}
});
});
});
}
// may be invoked any time we suspect updates have occured to re-deploy
// if needed
Deployer
.
prototype
.
checkForUpdates
=
function
(
cb
)
{
var
self
=
this
;
self
.
_pullLatest
(
function
(
err
,
sha
)
{
if
(
!
err
)
{
console
.
log
(
sha
);
}
});
}
var
deployer
=
new
Deployer
();
[
'
info
'
,
'
ready
'
,
'
error
'
,
'
deployment_begins
'
,
'
deployment_complete
'
,
'
progress
'
].
forEach
(
function
(
evName
)
{
deployer
.
on
(
evName
,
function
(
data
)
{
console
.
log
(
evName
+
"
:
"
,
data
)
});
});
deployer
.
on
(
'
ready
'
,
function
()
{
deployer
.
checkForUpdates
();
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment