aboutsummaryrefslogtreecommitdiffstats
path: root/build/make_repo.sh
blob: c4afd4fa95db43c33a378161542aa9a3c9af9a7a (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/bash
set -ex

BUILD_PATH=$(cd "$(dirname "$0")"; pwd)
WORK_PATH=$(cd "$(dirname "$0")"/..; pwd)

function process_env()
{
    mkdir -p ${WORK_PATH}/work/repo/ ${WORK_PATH}/work/repo/pip

    set +e
    sudo docker info
    if [[ $? != 0 ]]; then
        wget -qO- https://get.docker.com/ | sh
    else
        echo "docker is already installed!"
    fi
    set -e

cat <<EOF >${WORK_PATH}/work/repo/cp_repo.sh
#!/bin/bash
set -ex
cp /*.tar.gz /result -f
EOF

cat << EOF >${WORK_PATH}/work/repo/elasticsearch.repo
[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=http://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
EOF

cat << EOF > ${WORK_PATH}/work/repo/logstash.repo
[logstash-2.0]
name=Logstash repository for 2.0.x packages
baseurl=http://packages.elastic.co/logstash/2.0/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
EOF

    sudo apt-get install python-yaml -y
    sudo apt-get install python-cheetah -y
}

function make_repo()
{
    rm -f ${WORK_PATH}/work/repo/install_packages.sh
    rm -f ${WORK_PATH}/work/repo/Dockerfile

    option=`echo "os-ver:,package-tag:,tmpl:,default-package:, \
            special-package:,special-package-script-dir:, \
            special-package-dir:,ansible-dir:,special-package-dir" | sed 's/ //g'`

    TEMP=`getopt -o h -l $option -n 'make_repo.sh' -- "$@"`

    if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi

    eval set -- "$TEMP"

    os_ver=""
    package_tag=""
    tmpl=""
    default_package=""
    special_package=""
    special_package_script_dir=""
    special_package_dir=""
    ansible_dir=""
    while :; do
        case "$1" in
            --os-ver) os_ver=$2; shift 2;;
            --package-tag) package_tag=$2; shift 2;;
            --tmpl) tmpl=$2; shift 2;;
            --default-package) default_package=$2; shift 2;;
            --special-package) special_package=$2; shift 2;;
            --special-package-script-dir) special_package_script_dir=$2; shift 2;;
            --special-package-dir) special_package_dir=$2; shift 2;;
            --ansible-dir) ansible_dir=$2; shift 2;;
            --) shift; break;;
            *) echo "Internal error! $1" ; exit 1 ;;
        esac
    done

    if [[ -n ${package_tag} && ${package_tag} == "pip" ]]; then
        make_pip_repo
        return
    fi

    if [[ -z ${os_ver} || -z ${package_tag} ]]; then
        echo "parameter is wrong"
        exit 1
    fi

    if [[ ${os_ver} == trusty ]]; then
        arch=Debian
        os_name=ubuntu
    fi

    if [[ ${os_ver} =~ rhel[0-9]*$ ]]; then
        arch=RedHat
        os_name=centos
    fi

    if [[ -z $arch ]]; then
        echo "unsupported ${os_ver} os"
        exit 1
    fi

    dockerfile=Dockerfile
    docker_tmpl=${BUILD_PATH}/os/${os_name}/${os_ver}/${package_tag}/${dockerfile}".tmpl"
    docker_tag="${os_ver}/${package_tag}"

    if [[ -z ${tmpl} ]]; then
        tmpl=${BUILD_PATH}/templates/${arch}_${package_tag}.tmpl
    fi

    python ${BUILD_PATH}/gen_ins_pkg_script.py "${ansible_dir}" "${arch}" "${tmpl}" \
          "${docker_tmpl}" "${default_package}" "${special_package}" \
          "${WORK_PATH}/work/repo/$arch/script/" \
          "${WORK_PATH}/work/repo/$arch/packages/"

    rm -rf ${WORK_PATH}/work/repo/$arch
    mkdir -p ${WORK_PATH}/work/repo/$arch/{script,packages}

    # copy default package script to wokr dir
    if [[ -d ${WORK_PATH}/build/arch/$arch ]]; then
        cp -rf ${WORK_PATH}/build/arch/$arch/* ${WORK_PATH}/work/repo/$arch/script/
    fi

    # copy make package script to work dir
    if [[ -n $special_package_script_dir && -d $special_package_script_dir ]]; then
        cp -rf $special_package_script_dir/*  ${WORK_PATH}/work/repo/$arch/script/
    fi

    # copy special package to work dir
    if [[ -n $special_package_dir && -d $special_package_dir ]]; then
        cp -rf $special_package_dir/*  ${WORK_PATH}/work/repo/$arch/packages/
    fi

    # copy docker file to work dir
    if [[ -n $os_ver && -d ${WORK_PATH}/build/os/$os_name/$os_ver ]]; then
        rm -rf ${WORK_PATH}/work/repo/$os_ver
        cp -rf ${WORK_PATH}/build/os/$os_name/$os_ver ${WORK_PATH}/work/repo
    fi

    # copy centos comps.xml to work dir
    if [[ $arch == RedHat && -f ${WORK_PATH}/build/os/$os_name/comps.xml ]]; then
        cp -rf ${WORK_PATH}/build/os/$os_name/comps.xml ${WORK_PATH}/work/repo
        cp -rf ${WORK_PATH}/build/os/$os_name/ceph_key_release.asc ${WORK_PATH}/work/repo
    fi

    sudo docker build -t ${docker_tag} -f ${WORK_PATH}/work/repo/${dockerfile} ${WORK_PATH}/work/repo/

    sudo docker run -t -v ${WORK_PATH}/work/repo:/result ${docker_tag}

    image_id=$(sudo docker images|grep ${docker_tag}|awk '{print $3}')

    sudo docker rmi -f ${image_id}
}

function make_pip_repo()
{
    source $WORK_PATH/build/build.conf

    if [[ $PIP_CONF == "" ]]; then
        return
    fi

    for i in $PIP_CONF; do
        curl --connect-timeout 10 -o $WORK_PATH/work/repo/pip/`basename $i` $i
    done

    cd $WORK_PATH/work/repo; tar -zcvf pip.tar.gz ./pip; cd -
}

function make_all_repo()
{
    make_repo --package-tag pip

    make_repo --os-ver rhel6 --package-tag compass \
              --tmpl "${WORK_PATH}/build/templates/compass_core.tmpl" \
              --default-package "epel-release python-yaml python-jinja2 python-paramiko elasticsearch logstash" \
              --special-package "kibana jdk"

    make_repo --os-ver trusty --package-tag juno \
              --ansible-dir $WORK_PATH/deploy/adapters/ansible \
              --default-package "openssh-server" \
              --special-package "openvswitch-datapath-dkms openvswitch-switch"

    make_repo --os-ver trusty --package-tag kilo \
              --ansible-dir $WORK_PATH/deploy/adapters/ansible \
              --default-package "openssh-server" \
              --special-package "openvswitch-datapath-dkms openvswitch-switch"

    make_repo --os-ver trusty --package-tag liberty \
              --ansible-dir $WORK_PATH/deploy/adapters/ansible \
              --default-package "openssh-server" \
              --special-package "openvswitch-datapath-dkms openvswitch-switch"

    make_repo --os-ver rhel7 --package-tag juno \
              --ansible-dir $WORK_PATH/deploy/adapters/ansible \
              --default-package "rsyslog-7.6.7-1.el7 strace net-tools wget vim openssh-server dracut-config-rescue-033-241.el7_1.3 dracut-network-033-241.el7_1.3"

    make_repo --os-ver rhel7 --package-tag kilo \
              --ansible-dir $WORK_PATH/deploy/adapters/ansible \
              --default-package "rsyslog-7.6.7-1.el7 strace net-tools wget vim openssh-server dracut-config-rescue-033-241.el7_1.5 dracut-network-033-241.el7_1.5"
}

function main()
{
    process_env

    if [[ $# -eq 0 ]]; then
        make_all_repo
    elif [ "$1" = "rhel7" ]; then
        echo "make rhel7"
        make_repo --os-ver rhel7 --package-tag juno \
                  --ansible-dir $WORK_PATH/deploy/adapters/ansible \
                  --default-package "rsyslog-7.6.7-1.el7 strace net-tools wget vim openssh-server dracut-config-rescue-033-241.el7_1.3 dracut-network-033-241.el7_1.3"
    elif [ "$1" = "rhel6" ]; then
        make_repo --os-ver rhel6 --package-tag compass \
              --tmpl "${WORK_PATH}/build/templates/compass_core.tmpl" \
              --default-package "epel-release python-yaml python-jinja2 python-paramiko elasticsearch logstash" \
              --special-package "kibana jdk"
    else
        make_repo $*
    fi
}

main $*