Skip to content

Commit 0dab3f4

Browse files
committed
flatten (re)pyinstaller
1 parent e3a1982 commit 0dab3f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2634
-1035
lines changed

package-requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pyinstaller
2+
pyinstaller-hooks

pkg/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
osquery

pkg/amazonlinux2016.09/Dockerfile

+26-63
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# To run the container: docker run -it --rm -v `pwd`:/data <image_name>
77
# Requires docker 17.05 or higher
88

9-
# Set this arguement to "local" if you want to build osquery for local code.
9+
# Set this argument to "local" if you want to build osquery for local code.
1010
# In that case, osquery folder must exist besides Dockerfile
1111
ARG OSQUERY_BUILD_ENV=remote
1212

@@ -29,7 +29,7 @@ ONBUILD RUN cd / \
2929
&& echo "Fetching osquery from git"
3030

3131

32-
#--------------- TEMP CONTAINER FOR OSQUERY ( BASED ON ARGUMENT ) --------------
32+
#--------------- TEMP CONTAINER FOR OSQUERY ( BASED ON ARGUMENT ) ---------------
3333
FROM osquery_"$OSQUERY_BUILD_ENV" as osquery_image
3434

3535

@@ -40,7 +40,6 @@ RUN yum makecache fast && yum -y update
4040

4141
#paths that hubble or hubble parts need in the package
4242
RUN mkdir -p /etc/hubble/hubble.d /opt/hubble /opt/osquery /var/log/hubble_osquery/backuplogs
43-
4443
#osquery build start
4544
#osquery should be built first since requirements for other packages can interfere with osquery dependencies
4645
#to build, osquery scripts want sudo and a user to sudo with.
@@ -74,10 +73,9 @@ RUN ls -lahR /opt/osquery/ && /opt/osquery/osqueryi --version
7473

7574
#install packages that should be needed for ligbit2 compilation and successful pyinstaller run
7675
RUN yum -y install \
77-
python27-devel libffi-devel openssl-devel libssh2-devel autoconf automake libtool \
78-
libxml2-devel libxslt-devel libjpeg-devel \
79-
zlib-devel make cmake python27-setuptools \
80-
gcc python-devel python-setuptools wget openssl
76+
libffi-devel openssl-devel libffi libssh2-devel autoconf automake libtool \
77+
libxml2-devel libxslt-devel libjpeg-devel zlib-devel \
78+
make cmake gcc python-devel python-setuptools wget openssl
8179

8280
#libcurl install start
8381
#install libcurl to avoid depending on host version
@@ -136,27 +134,29 @@ RUN mkdir -p "$LIBGIT2TEMP" \
136134
&& make \
137135
&& make install
138136

137+
#fpm package making requirements start
138+
RUN yum install -y ruby ruby-devel rpmbuild rpm-build rubygems gcc make \
139+
&& gem install --no-ri --no-rdoc fpm
140+
141+
# things we may need to build a python
142+
RUN yum install -y bzip2-devel
143+
139144
# use pyenv
140145
ARG PYENV_VERSION=3.6.10
141146
ENV PYENV_INSTALLER_URL=https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer
142-
ENV PYENV_ROOT=/usr/local/pyenv
147+
ENV PYENV_ROOT=/opt/hubble/pyenv
143148
ENV PATH=$PYENV_ROOT/bin:$PATH
149+
ENV PYTHON_CONFIGURE_OPTS="--enable-shared"
144150
RUN umask 022 \
145151
&& curl -s -S -L "$PYENV_INSTALLER_URL" -o /usr/bin/pyenv-installer \
146152
&& chmod 0755 /usr/bin/pyenv-installer \
147153
&& /usr/bin/pyenv-installer \
148154
&& eval "$(pyenv init -)" \
149-
&& env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install $PYENV_VERSION \
155+
&& pyenv install $PYENV_VERSION \
150156
&& pyenv global $PYENV_VERSION
151157

152-
COPY pyinstaller-requirements.txt /
153158
RUN eval "$(pyenv init -)" \
154-
&& pip -v install --upgrade pip \
155-
&& pip -v install -r pyinstaller-requirements.txt
156-
157-
#fpm package making requirements start
158-
RUN yum install -y ruby ruby-devel rpmbuild rpm-build rubygems gcc make \
159-
&& gem install --no-ri --no-rdoc fpm
159+
&& pip -v install --upgrade pip
160160

161161
#pyinstaller start
162162
#commands specified for ENTRYPOINT and CMD are executed when the container is run, not when the image is built
@@ -173,58 +173,21 @@ ENV _HOOK_DIR="./pkg/"
173173
ENV _BINARY_LOG_LEVEL="INFO"
174174
ENV _INCLUDE_PATH=""
175175
ENV LD_LIBRARY_PATH=/opt/hubble/lib:/lib:/lib64:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64
176-
RUN git clone "$HUBBLE_GIT_URL" "$HUBBLE_SRC_PATH" \
176+
RUN set -x; git clone "$HUBBLE_GIT_URL" "$HUBBLE_SRC_PATH" \
177177
&& cd "$HUBBLE_SRC_PATH" \
178178
&& git checkout -B hubble-build && git reset --hard "$HUBBLE_CHECKOUT" && git clean -dfx \
179179
&& cp -rf "$HUBBLE_SRC_PATH" /hubble_build \
180180
&& sed -i "s/BRANCH_NOT_SET/${HUBBLE_CHECKOUT}/g" /hubble_build/hubblestack/__init__.py \
181181
&& sed -i "s/COMMIT_NOT_SET/`git describe`/g" /hubble_build/hubblestack/__init__.py
182+
RUN eval "$(pyenv init -)" \
183+
&& cd "$HUBBLE_SRC_PATH" \
184+
&& python setup.py egg_info \
185+
&& pip install --upgrade \
186+
-r hubblestack.egg-info/requires.txt \
187+
-r optional-requirements.txt \
188+
-r package-requirements.txt
182189
RUN mkdir /data
183190
VOLUME /data
184191
WORKDIR /hubble_build
185-
ENTRYPOINT [ "/bin/bash", "-o", "xtrace", "-c" ]
186-
CMD [ "if [ -f /data/hubble_buildinfo ] ; then echo \"\" >> /hubble_build/hubblestack/__init__.py ; cat /data/hubble_buildinfo >> /hubble_build/hubblestack/__init__.py; fi \
187-
&& eval \"$(pyenv init -)\" \
188-
&& pyinstaller --onedir --noconfirm --log-level ${_BINARY_LOG_LEVEL} --additional-hooks-dir=${_HOOK_DIR} --runtime-hook=pkg/pyinstaller-runtimehooks/pathopthubble.py hubble.py \
189-
&& mkdir -p /var/log/hubble_osquery/backuplogs \
190-
# hubble default configuration file
191-
&& cp -rf /hubble_build/conf/hubble /etc/hubble/ \
192-
&& cp -rf /hubble_build/conf/hubble-profile.sh /etc/profile.d/ \
193-
&& cp -pr /hubble_build/dist/hubble /opt/hubble/hubble-libs \
194-
&& ln -s /opt/hubble/hubble-libs/hubble /opt/hubble/hubble \
195-
# make sure rpm shared libs are taken out to avoid mismatch between rpm database and shared libs that pyinstaller includes
196-
&& rm -rf /opt/hubble/hubble-libs/librpm* \
197-
#rpm pkg start
198-
&& tar -cPvzf /data/hubblestack-${HUBBLE_VERSION}.tar.gz /etc/hubble /opt/hubble /opt/osquery /etc/profile.d/hubble-profile.sh /var/log/hubble_osquery/backuplogs \
199-
&& mkdir -p /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION} \
200-
&& tar -xzvf /data/hubblestack-${HUBBLE_VERSION}.tar.gz -C /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION} \
201-
&& mkdir -p /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/etc/init.d \
202-
&& if [ -f /data/hubble-autostart ] ; then mkdir -p /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/etc/cron.d ; fi \
203-
&& cp /hubble_build/pkg/hubble /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/etc/init.d/ \
204-
&& if [ -f /data/hubble-autostart ] ; then cp /hubble_build/pkg/hubble-autostart /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/etc/cron.d/ ; fi \
205-
&& cp -f /hubble_build/conf/hubble /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/etc/hubble/ \
206-
#during container run, if a configuration file exists in a /data copy it over the existing one so it would be
207-
#possile to optionally include a custom one with the package
208-
&& if [ -f /data/hubble ] ; then cp /data/hubble /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/etc/hubble/ ; fi \
209-
#also bring in anything from a /data/opt/ directory so we can bundle other executables if needed
210-
&& if [ -d /data/opt ] ; then cp -r /data/opt/* /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/opt/ ; fi \
211-
&& cd /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION} \
212-
&& mkdir -p usr/bin \
213-
#symlink to have hubble binary in path
214-
&& ln -s /opt/hubble/hubble usr/bin/hubble \
215-
#fpm start
216-
&& fpm -s dir -t rpm \
217-
-n hubblestack \
218-
-v ${HUBBLE_VERSION} \
219-
--iteration ${HUBBLE_ITERATION} \
220-
--url ${HUBBLE_URL} \
221-
--description \"${HUBBLE_DESCRIPTION}\" \
222-
--rpm-summary \"${HUBBLE_SUMMARY}\" \
223-
--after-install /hubble_build/conf/afterinstall.sh \
224-
--after-upgrade /hubble_build/conf/afterupgrade.sh \
225-
--before-remove /hubble_build/conf/beforeremove.sh \
226-
etc opt usr /var/log/hubble_osquery/backuplogs \
227-
#edit to change iteration number, if necessary
228-
&& cp hubblestack-${HUBBLE_VERSION}-${HUBBLE_ITERATION}.x86_64.rpm /data/hubblestack-${HUBBLE_VERSION}-${HUBBLE_ITERATION}.al1609.x86_64.rpm \
229-
&& openssl dgst -sha256 /data/hubblestack-${HUBBLE_VERSION}-${HUBBLE_ITERATION}.al1609.x86_64.rpm \
230-
> /data/hubblestack-${HUBBLE_VERSION}-${HUBBLE_ITERATION}.al1609.x86_64.rpm.sha256" ]
192+
COPY entrypoint.sh /entrypoint.sh
193+
ENTRYPOINT [ "/bin/bash", "/entrypoint.sh" ]

pkg/amazonlinux2016.09/entrypoint.sh

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/bin/bash
2+
3+
eval "$(pyenv init -)"
4+
5+
# locate some pyenv things
6+
pyenv_prefix="$(pyenv prefix)"
7+
python_binary="$(pyenv which python)"
8+
while [ -L "$python_binary" ]
9+
do python_binary="$(readlink -f "$python_binary")"
10+
done
11+
12+
# if ENTRYPOINT is given a CMD other than nothing
13+
# abort here and do that other CMD
14+
if [ $# -gt 0 ]
15+
then exec "$@"
16+
fi
17+
18+
# from now on, exit on error (rather than && every little thing)
19+
PS4=$'-------------=: '
20+
set -x -e
21+
22+
cp -rf "$HUBBLE_SRC_PATH"/* /hubble_build/
23+
24+
# possibly replace the version file
25+
if [ -f /data/hubble_buildinfo ]; then
26+
echo >> /hubble_build/hubblestack/__init__.py
27+
cat /data/hubble_buildinfo >> /hubble_build/hubblestack/__init__.py
28+
fi 2>/dev/null
29+
30+
31+
cd /hubble_build
32+
33+
# we may have preinstalled requirements that may need upgrading
34+
# pip install . might not upgrade/downgrade the requirements
35+
python setup.py egg_info
36+
pip install --upgrade \
37+
-r hubblestack.egg-info/requires.txt \
38+
-r optional-requirements.txt \
39+
-r package-requirements.txt
40+
41+
[ -f ${_HOOK_DIR:-./pkg}/hook-hubblestack.py ] || exit 1
42+
43+
rm -rf build dist /opt/hubble/hubble-libs /hubble_build/hubble.spec
44+
export LD_LIBRARY_PATH=$pyenv_prefix/lib:/opt/hubble/lib:/opt/hubble-libs
45+
export LD_RUN_PATH=$LD_LIBRARY_PATH
46+
pyinstaller --onedir --noconfirm --log-level ${_BINARY_LOG_LEVEL:-INFO} \
47+
--additional-hooks-dir ${_HOOK_DIR:-./pkg} \
48+
--runtime-hook pkg/runtime-hooks.py \
49+
./hubble.py 2>&1 | tee /tmp/pyinstaller.log
50+
51+
cp -pr dist/hubble /opt/hubble/hubble-libs
52+
53+
cat > /opt/hubble/hubble << EOF
54+
#!/bin/bash
55+
exec /opt/hubble/hubble-libs/hubble "\$@"
56+
exit 1
57+
EOF
58+
chmod 0755 /opt/hubble/hubble
59+
60+
[ -d /data/last-build.4 ] && rm -rf /data/last-build.4
61+
[ -d /data/last-build.3 ] && mv -v /data/last-build.3 /data/last-build.4
62+
[ -d /data/last-build.2 ] && mv -v /data/last-build.2 /data/last-build.3
63+
[ -d /data/last-build.1 ] && mv -v /data/last-build.1 /data/last-build.2
64+
cp -va build/ /data/last-build.1
65+
mv /tmp/pyinstaller.log /data/last-build.1
66+
cp -va /entrypoint.sh /data/last-build.1
67+
68+
mkdir -p /var/log/hubble_osquery/backuplogs
69+
70+
mkdir -p /usr/lib/systemd/system
71+
mkdir -p /etc/profile.d
72+
mkdir -p /etc/hubble
73+
74+
cp -v /hubble_build/pkg/hubble.service /usr/lib/systemd/system/
75+
cp -v /hubble_build/conf/hubble-profile.sh /etc/profile.d/
76+
77+
if [ -f /data/hubble ]
78+
then cp -v /data/hubble /etc/hubble/
79+
else cp -v /hubble_build/conf/hubble /etc/hubble/
80+
fi
81+
82+
if [ "X$TEST_BINARIES" = X1 ]; then
83+
# weakly test the new bin
84+
./dist/hubble/hubble --version
85+
86+
# does it still work if we call it in its new home?
87+
/opt/hubble/hubble-libs/hubble --version
88+
89+
# how about if it's via non-home location?
90+
/opt/hubble/hubble --version
91+
92+
# lastly, can we actually use salt grains and other lazy loader items?
93+
/opt/hubble/hubble-libs/hubble -vvv grains.get hubble_version
94+
/opt/hubble/hubble -vvv grains.get hubble_version
95+
fi
96+
97+
if [ "X$NO_TAR" = X1 ]; then
98+
echo "exiting (as requested by NO_TAR=$NO_TAR) without pre-tar-ing package"
99+
exit 0
100+
fi 2>/dev/null
101+
102+
# rpm pkg start
103+
tar -cSPvvzf /data/hubblestack-${HUBBLE_VERSION}.tar.gz \
104+
--exclude opt/hubble/pyenv \
105+
/etc/hubble /opt/hubble /opt/osquery \
106+
/etc/profile.d/hubble-profile.sh \
107+
/usr/lib/systemd/system/hubble.service \
108+
/var/log/hubble_osquery/backuplogs \
109+
2>&1 | tee /hubble_build/rpm-pkg-start-tar.log
110+
111+
PKG_STRUCT_DIR=/hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}
112+
mkdir -p /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}
113+
tar -xSzvvf /data/hubblestack-${HUBBLE_VERSION}.tar.gz -C $PKG_STRUCT_DIR
114+
115+
# also bring in anything from a /data/opt/ directory so we can bundle other executables if needed
116+
if [ -d /data/opt ]
117+
then cp -r /data/opt/* /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/opt/
118+
fi
119+
120+
# symlink to have hubble binary in path
121+
cd /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}
122+
mkdir -p usr/bin
123+
ln -s /opt/hubble/hubble usr/bin/hubble
124+
125+
if [ "X$NO_FPM" = X1 ]; then
126+
echo "exiting (as requested by NO_FPM=$NO_FPM) without building package"
127+
exit 0
128+
fi
129+
130+
# fpm start
131+
fpm -s dir -t rpm \
132+
-n hubblestack \
133+
-v ${HUBBLE_VERSION} \
134+
--iteration ${HUBBLE_ITERATION} \
135+
--url ${HUBBLE_URL} \
136+
--description "${HUBBLE_DESCRIPTION}" \
137+
--rpm-summary "${HUBBLE_SUMMARY}" \
138+
--after-install /hubble_build/conf/afterinstall-systemd.sh \
139+
--after-upgrade /hubble_build/conf/afterupgrade-systemd.sh \
140+
--before-remove /hubble_build/conf/beforeremove.sh \
141+
etc/hubble opt usr /var/log/hubble_osquery/backuplogs
142+
143+
# edit to change iteration number, if necessary
144+
PKG_BASE_NAME=hubblestack-${HUBBLE_VERSION}-${HUBBLE_ITERATION}
145+
PKG_OUT_EXT=x86_64.rpm
146+
PKG_FIN_EXT=all609.$PKG_OUT_EXT
147+
PKG_ONAME="$PKG_BASE_NAME.$PKG_OUT_EXT"
148+
PKG_FNAME="$PKG_BASE_NAME.$PKG_FIN_EXT"
149+
150+
cp -va "$PKG_ONAME" /data/"$PKG_FNAME"
151+
openssl dgst -sha256 /data/"$PKG_FNAME" > /data/"$PKG_FNAME".sha256

pkg/amazonlinux2016.09/pyinstaller-requirements.txt

-22
This file was deleted.

0 commit comments

Comments
 (0)