-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathkafe.lua
63 lines (42 loc) · 1.92 KB
/
kafe.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- This is a deployment file used to publish documentation pages.
-- See https://github.com/libkafe/kafe for documentation.
local k = require('kafe')
k.require_api(1)
local username = os.getenv('USER');
k.add_inventory(username, 'w03.ovh.0x3e.net', 22, 'production', 'docs')
k.task('deploy', function()
local version = os.time(os.date('!*t'))
k.define('deploy_to', '/var/www/docs.fluidplayer.com')
k.define('version', version)
k.local_within('./website/')
if not k.local_shell('[ ! -d ./build/ ] || rm -r ./build/')
then error('Failed to remove dist folder') end
if not k.local_shell('yarn build')
then error('Failed to build dist') end
local archive = k.archive_dir_tmp('build/fluid-player/')
local deploy = function()
k.shell('mkdir -p {{deploy_to}}')
k.within('{{deploy_to}}')
k.shell('mkdir -p releases/{{version}}/')
k.upload_file(archive, 'releases/{{version}}/upload.tar.gz')
if not k.shell('tar -xf releases/{{version}}/upload.tar.gz -C releases/{{version}}')
then error('Could not unpack uploaded archive') end
if not k.shell('rm releases/{{version}}/upload.tar.gz')
then error('Failed to remove uploaded archive') end
k.shell('chmod g+rw releases && chmod g+rw -Rf releases/')
end
local symlink = function()
k.within('{{deploy_to}}')
if not k.shell('ln -nsfv releases/{{version}}/ web')
then error('Failed to update the symlink to the new version') end
end
local remove_old_releases = function()
k.within('{{deploy_to}}/releases/')
if not k.shell('ls -1tr | head -n -3 | xargs -d \'\\n\' rm -rf --') then
error('Failed to remove old releases') end
end
if k.on('docs', deploy) then
k.on('docs', symlink)
k.on('docs', remove_old_releases)
end
end)