forked from littlemo/moear
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfabfile.py
More file actions
48 lines (41 loc) · 1.34 KB
/
fabfile.py
File metadata and controls
48 lines (41 loc) · 1.34 KB
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
# -*- coding: utf-8 -*-
from __future__ import with_statement
from fabric.api import *
import os
fabfile_dir = os.path.dirname(__file__)
build_path = os.path.join(fabfile_dir, 'build')
image_name = 'moear'
@task
def build(ver='dev'):
"""镜像构建"""
local(
'docker build --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` '
'--build-arg VCS_REF=`git rev-parse --short HEAD` '
'--build-arg VERSION=`git describe --tags --always` '
'-t littlemo/{name}:{ver} .'.format(
name=image_name,
ver=ver))
@task
def pack(ver='dev'):
"""镜像打包成.tar.gz"""
if not os.path.exists(build_path):
os.mkdir(build_path)
arg_dict = {
'ver': ver,
'build': build_path,
'name': image_name,
}
cmd_save = 'docker save littlemo/{name}:{ver} > ' + \
'mo-{name}-{ver}.tar'
with lcd(build_path):
try:
if os.path.exists('mo-{name}-{ver}.tar.gz'.format(**arg_dict)):
local('rm mo-{name}-{ver}.ta*'.format(**arg_dict))
except Exception:
pass
local('ls -alh')
local(cmd_save.format(**arg_dict))
local('tar czf mo-{name}-{ver}.tar.gz '
'mo-{name}-{ver}.tar'.format(**arg_dict))
local('ls -alh')
local('rm mo-{name}-{ver}.tar'.format(**arg_dict))