forked from cfg/s3fs
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathci
executable file
·164 lines (144 loc) · 5.48 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/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="centos7 rockylinux8 amazonlinux2018.03 amazonlinux2 amazonlinux2023"
# Use podman by default as container engine
CENGINE='podman'
# Default registry
REGISTRY='docker.io'
# 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 the container"
echo " --docker Use docker instead of podman"
echo " --registry=<REGISTRY> Specify an image registry. If absent, docker.io"
echo " will be used by default"
echo ""
}
remove_container() {
${CENGINE} 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
}
container_run() {
if [ ! -z ${3} ]; then
local COMMAND_USER="-u ${3}"
fi
local COMMAND="${CENGINE} 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:,docker:,registry: -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;;
--docker) CENGINE='docker'; shift 1;;
--registry) REGISTRY="${2}"; shift 2;;
--) shift ; break ;;
*) print_incorrect_syntax; exit 1;;
esac
done
# Check distribution
case "${DISTRO}" in
centos7) CONTAINER_IMAGE="${REGISTRY}/centos:centos7" ;;
rockylinux8) CONTAINER_IMAGE="${REGISTRY}/rockylinux:8" ;;
amazonlinux2018.03) CONTAINER_IMAGE="${REGISTRY}/amazonlinux:2018.03" ;;
amazonlinux2) CONTAINER_IMAGE="${REGISTRY}/amazonlinux:2" ;;
amazonlinux2023) CONTAINER_IMAGE="${REGISTRY}/amazonlinux:2023" ;;
*) print_error_unsupported_distro
exit 1;;
esac
# Check name
if [ -z ${CONTAINER_NAME} ]; then
CONTAINER_NAME="s3fs-fuse-rpm-${DISTRO}-$(date +'%s')"
fi
if [ "${CENGINE}" == "podman" ]; then
EXTRA_FLAGS="--userns=keep-id"
fi
print_info "Starting container ${CONTAINER_NAME}..."
${CENGINE} container run -i ${TTY} --name "${CONTAINER_NAME}" -v ${PWD}:/tmp/s3fs-fuse-rpm:Z --cap-add SYS_ADMIN --device /dev/fuse -w /tmp/s3fs-fuse-rpm -d ${EXTRA_FLAGS} ${CONTAINER_IMAGE} /bin/bash -c 'while [ 1 -eq 1 ]; do sleep 60; done'
print_info "Cleaning up"
container_run "${CONTAINER_NAME}" "./clean"
if [ "${DISTRO}" == "centos7" ]; then
print_info "Adjusting CentOS7 repositories to use the vault..."
mkdir ${PWD}/${CONTAINER_NAME}/
podman cp ${CONTAINER_NAME}:/etc/yum.repos.d/ ${PWD}/${CONTAINER_NAME}/
sed -i -e '/^mirrorlist/d;/^#baseurl=/{s,^#,,;s,/mirror,/vault,;}' ${PWD}/${CONTAINER_NAME}/yum.repos.d/CentOS*.repo
podman cp ${PWD}/${CONTAINER_NAME}/yum.repos.d/ ${CONTAINER_NAME}:/etc/
rm -rf ${PWD}/${CONTAINER_NAME}/
fi
print_info "Installing required dependencies..."
container_run "${CONTAINER_NAME}" "./install-buildrequires" "root" # Build Dependencies
container_run "${CONTAINER_NAME}" "/usr/bin/yum -q -y install initscripts kernel mailcap openssl grep" "root" # Other dependencies only needed for containers
if [ "${CENGINE}" == "docker" ]; then
print_info "Configuring user ci..."
container_run "${CONTAINER_NAME}" "/usr/sbin/groupadd -g $(id -g) ${USER}" "root"
container_run "${CONTAINER_NAME}" "/usr/sbin/useradd -m -d /home/${USER} -u ${UID} -g $(id -g) ${USER}" "root"
container_run "${CONTAINER_NAME}" "/bin/chown ci:ci /home/${USER}" "root"
fi
print_info "Installing fuse..."
container_run "${CONTAINER_NAME}" "/usr/bin/yum -q -y install fuse fuse-libs fuse-devel" "root" # fuse
print_info "Building s3fs-fuse package..."
container_run "${CONTAINER_NAME}" "./s3fs-build-rpm" "${USER}"
print_info "Installing s3fs-fuse package..."
container_run "${CONTAINER_NAME}" "/bin/rpm -e fuse-devel" "root"
container_run "${CONTAINER_NAME}" "/bin/rpm -i RPMS/$HOSTTYPE/s3fs-fuse-*.*.$HOSTTYPE.rpm" "root"
print_info "Removing s3fs-fuse package..."
container_run "${CONTAINER_NAME}" "/bin/rpm -e s3fs-fuse" "root"
print_info "Removing container..."
remove_container ${CONTAINER_NAME}
print_ok "Everything OK"