forked from juliogonzalez/s3fs-fuse-rpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci
executable file
·145 lines (128 loc) · 4.73 KB
/
ci
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
#!/bin/bash
# Language (force it so getopt messages are always in english, as the script)
LANG=en_EN
# Get script name
SCRIPT=$(basename ${0})
# Supported distributions
SUPPORTEDDISTROS="centos6 centos7 amazon2017.03"
# Allocate tty by default
TTY='-t'
print_info() {
echo -e "\033[1;36m[INFO] ${1}\033[0m"
}
print_error() {
echo -e "\033[1;31m[ERROR] ${1}\033[0m"
}
print_ok() {
echo -e "\033[1;32m[INFO] ${1}\033[0m"
}
print_incorrect_syntax() {
print_error "Incorrect syntax. Use ${SCRIPT} -h for help"
}
print_error_unsupported_distro() {
print_error "Unsupported distro. Use ${SCRIPT} -h for help"
}
print_help() {
echo ""
echo "Script to perform s3fs-fuse-rpm CI"
echo ""
echo "Syntax: "
echo ""
echo "${SCRIPT} <ARGUMENTS>"
echo ""
echo "Mandatory arguments:"
echo ""
echo " --distro=<$(echo ${1}|tr ' ' '|')>"
echo ""
echo "Optional arguments:"
echo ""
echo " --name=<CONTAINER_NAME> Define the container name"
echo " If undefined, container name will be"
echo " s3fs-fuse-rpm-<DISTRO>-<TIMESTAMP>"
echo " --remove-on-error If present, remove the container on errors"
echo " --notty If present, does not allocate a tty for docker"
echo ""
}
remove_container() {
docker container rm -f ${1}
}
exit_error() {
if [ ${1} -ne 0 ]; then
print_error "An error happened! Check log!"
if [ ! -z ${REMOVE_ON_ERROR} ]; then
remove_container ${CONTAINER_NAME}
fi
exit 1
fi
}
docker_run() {
if [ ! -z ${3} ]; then
local COMMAND_USER="-u ${3}"
fi
local COMMAND="docker container exec -i ${TTY} ${COMMAND_USER} ${1} ${2}"
${COMMAND}
exit_error ${?}
}
# read the options
ARGS=$(getopt -o h --long help,remove-on-error,notty,distro:,name: -n "${SCRIPT}" -- "$@")
if [ $? -ne 0 ];
then
print_incorrect_syntax
exit 1
fi
eval set -- "${ARGS}"
# extract options and their arguments into variables
while true ; do
case "${1}" in
-h|--help) print_help "${SUPPORTEDDISTROS}"; exit 1;;
--remove-on-error) REMOVE_ON_ERROR="TRUE"; shift 1 ;;
--notty) TTY=""; shift 1 ;;
--distro) DISTRO="${2}"; shift 2;;
--name) CONTAINER_NAME="${2}"; shift 2;;
--) shift ; break ;;
*) print_incorrect_syntax; exit 1;;
esac
done
# Check distribution
case "${DISTRO}" in
centos6) DOCKER_IMAGE='centos:centos6'
BUILD_FUSE='TRUE' ;;
centos7) DOCKER_IMAGE='centos:centos7' ;;
amazon2017.03) DOCKER_IMAGE='amazonlinux:2017.03' ;;
*) print_error_unsupported_distro
exit 1;;
esac
# Check name
if [ -z ${CONTAINER_NAME} ]; then
CONTAINER_NAME="s3fs-fuse-rpm-${DISTRO}-$(date +'%s')"
fi
print_info "Starting container ${CONTAINER_NAME}..."
docker container run -i ${TTY} --name "${CONTAINER_NAME}" -v ${PWD}:/tmp/s3fs-fuse-rpm --cap-add SYS_ADMIN --device /dev/fuse -w /tmp/s3fs-fuse-rpm -d ${DOCKER_IMAGE} /bin/bash -c 'while [ 1 -eq 1 ]; do sleep 60; done'
print_info "Cleaning up"
docker_run "${CONTAINER_NAME}" "./clean"
print_info "Installing required dependencies..."
docker_run "${CONTAINER_NAME}" "/usr/bin/yum -q -y install automake make git rpm-build" # Common dependencies
docker_run "${CONTAINER_NAME}" "/usr/bin/yum -q -y install gcc-c++ libcurl-devel libxml2-devel openssl-devel" # s3fs dependencies
docker_run "${CONTAINER_NAME}" "/usr/bin/yum -q -y install initscripts kernel mailcap openssl" # Other dependencies only needed at docker
print_info "Configuring user ci..."
docker_run "${CONTAINER_NAME}" "/usr/sbin/groupadd -g $(id -g) ci"
docker_run "${CONTAINER_NAME}" "/usr/sbin/useradd -m -d /home/ci -u ${UID} -g $(id -g) ci"
docker_run "${CONTAINER_NAME}" "/bin/chown ci:ci /home/ci"
if [ ! -z ${BUILD_FUSE} ]; then
print_info "Installing fuse build dependencies..."
docker_run "${CONTAINER_NAME}" "/usr/bin/yum -q -y install gcc libselinux-devel libtool gettext-devel kernel-devel" # fuse dependencies
print_info "Building fuse (required by ${DISTRO})..."
docker_run "${CONTAINER_NAME}" "./fuse-rpm" "ci"
print_info "Installing fuse..."
docker_run "${CONTAINER_NAME}" "/bin/rpm -i RPMS/$HOSTTYPE/fuse-2.8.5-99.vitki.03.*.$HOSTTYPE.rpm RPMS/$HOSTTYPE/fuse-devel-2.8.5-99.vitki.03.*.$HOSTTYPE.rpm RPMS/$HOSTTYPE/fuse-libs-2.8.5-99.vitki.03.*.$HOSTTYPE.rpm"
else
print_info "Installing fuse..."
docker_run "${CONTAINER_NAME}" "/usr/bin/yum -q -y install fuse fuse-devel" # fuse
fi
print_info "Building s3fs-fuse package..."
docker_run "${CONTAINER_NAME}" "./s3fs-build-rpm" "ci"
print_info "Installing s3fs-fuse package..."
docker_run "${CONTAINER_NAME}" "/bin/rpm -i RPMS/$HOSTTYPE/s3fs-fuse-*.*.$HOSTTYPE.rpm"
print_info "Removing container..."
remove_container ${CONTAINER_NAME}
print_ok "Everything OK"