Rewrote the build system to be more flexible / cross platform.
We can now build the CLI in a cross platform way (linux/mac/windows) all from the Makefile with relocatable VENV, DIST, and TOX directories. We can also optionally build in a docker container on platforms where docker is available.
This commit is contained in:
38
Makefile
38
Makefile
@@ -1,16 +1,34 @@
|
||||
all: env test packages
|
||||
all: env packages doc test
|
||||
all-docker: env-docker packages-docker doc-docker test-docker
|
||||
|
||||
clean:
|
||||
bin/clean.sh
|
||||
@bash bin/clean.sh
|
||||
|
||||
distclean: clean
|
||||
@bash bin/distclean.sh
|
||||
|
||||
env:
|
||||
bin/env.sh
|
||||
|
||||
test: env
|
||||
bin/test.sh
|
||||
|
||||
doc: env
|
||||
bin/doc.sh
|
||||
@bash bin/env.sh
|
||||
|
||||
packages: env
|
||||
bin/packages.sh
|
||||
@bash bin/packages.sh
|
||||
|
||||
doc: env
|
||||
@bash bin/doc.sh
|
||||
|
||||
test: env
|
||||
@bash bin/test.sh
|
||||
|
||||
env-docker:
|
||||
@bash bin/docker.sh env
|
||||
|
||||
packages-docker: env-docker
|
||||
@bash bin/docker.sh packages
|
||||
|
||||
doc-docker: env-docker
|
||||
@bash bin/docker.sh doc
|
||||
|
||||
test-docker: env-docker
|
||||
@bash bin/docker.sh test
|
||||
|
||||
.PHONY: env env-docker
|
||||
|
||||
18
bin/clean.sh
18
bin/clean.sh
@@ -1,10 +1,14 @@
|
||||
#!/bin/bash -e
|
||||
#!/bin/bash
|
||||
|
||||
set -o errexit -o nounset
|
||||
CURRDIR=$(dirname "${0}")
|
||||
source ${CURRDIR}/common.sh
|
||||
|
||||
BASEDIR=`dirname $0`/..
|
||||
|
||||
rm -rf $BASEDIR/.tox $BASEDIR/env $BASEDIR/dist $BASEDIR/build
|
||||
find $BASEDIR -name '*.pyc' -delete || true
|
||||
rm -rf ${BUILDDIR}/${VENV} \
|
||||
${BUILDDIR}/${VENV_DOCKER} \
|
||||
${BUILDDIR}/${TOX} \
|
||||
${BUILDDIR}/${TOX_DOCKER} \
|
||||
${BASEDIR}/build \
|
||||
${BASEDIR}/*.egg-info \
|
||||
${BASEDIR}/.coverage \
|
||||
${BASEDIR}/.cache
|
||||
echo "Deleted virtualenv and test artifacts."
|
||||
|
||||
|
||||
27
bin/common.sh
Normal file
27
bin/common.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
set -o errexit -o nounset
|
||||
if [ "$(uname)" != "Windows_NT" ]; then
|
||||
set -o pipefail
|
||||
fi
|
||||
|
||||
: ${PROMPT:="(dcos-cli) "}
|
||||
|
||||
: ${BUILDDIR:=$(pwd -P)}
|
||||
: ${VENV:=env}
|
||||
: ${DIST:=dist}
|
||||
: ${TOX:=.tox}
|
||||
: ${VENV_DOCKER:=env-docker}
|
||||
: ${DIST_DOCKER:=dist-docker}
|
||||
: ${TOX_DOCKER:=.tox-docker}
|
||||
|
||||
if [ "$(uname)" = "Windows_NT" ]; then
|
||||
BIN=Scripts
|
||||
EXE=.exe
|
||||
: ${PYTHON:=python${EXE}}
|
||||
: ${VIRTUALENV:=virtualenv${EXE}}
|
||||
else
|
||||
BIN=bin
|
||||
EXE=
|
||||
: ${PYTHON:=python3.5${EXE}}
|
||||
fi
|
||||
|
||||
BASEDIR=$( cd "$(dirname $(dirname "${0}"))" > /dev/null; pwd -P )
|
||||
8
bin/distclean.sh
Executable file
8
bin/distclean.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURRDIR=$(dirname "${0}")
|
||||
source ${CURRDIR}/common.sh
|
||||
|
||||
rm -rf ${BUILDDIR}/${DIST} \
|
||||
${BUILDDIR}/${DIST_DOCKER}
|
||||
echo "Deleted distribution artifacts."
|
||||
13
bin/doc.sh
13
bin/doc.sh
@@ -1,9 +1,8 @@
|
||||
#!/bin/bash -e
|
||||
#!/bin/bash
|
||||
|
||||
BASEDIR=`dirname $0`/..
|
||||
CURRDIR=$(dirname "${0}")
|
||||
source ${CURRDIR}/common.sh
|
||||
|
||||
cd $BASEDIR
|
||||
source $BASEDIR/env/bin/activate
|
||||
echo "Virtualenv activated."
|
||||
|
||||
sphinx-build -W -b html pydoc pydoc/_build
|
||||
echo "Building documentation..."
|
||||
${BUILDDIR}/${VENV}/${BIN}/sphinx-build${EXE} -W -b html pydoc pydoc/_build
|
||||
echo "Documentation built."
|
||||
|
||||
22
bin/docker.sh
Executable file
22
bin/docker.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURRDIR=$(dirname "${0}")
|
||||
source ${CURRDIR}/common.sh
|
||||
|
||||
: ${DOCKER_RUN:="docker run \
|
||||
--rm \
|
||||
-v ${BASEDIR}:/dcos-cli \
|
||||
-v ${HOME}:/home/${USER} \
|
||||
-v /etc/passwd:/etc/passwd:ro \
|
||||
-v /etc/group:/etc/group:ro \
|
||||
-e HOME=/home/${USER} \
|
||||
-e VENV=${VENV_DOCKER} \
|
||||
-e DIST=${DIST_DOCKER} \
|
||||
-e TOX=${TOX_DOCKER} \
|
||||
-w /dcos-cli \
|
||||
-u $(id -u ${USER}):$(id -g ${USER}) \
|
||||
python:3.5"}
|
||||
|
||||
for target in "${@}"; do
|
||||
${DOCKER_RUN} make ${target}
|
||||
done
|
||||
67
bin/env.sh
67
bin/env.sh
@@ -1,35 +1,52 @@
|
||||
#!/bin/bash -e
|
||||
#!/bin/bash
|
||||
|
||||
BASEDIR=`dirname $0`/..
|
||||
CURRDIR=$(dirname "${0}")
|
||||
source ${CURRDIR}/common.sh
|
||||
|
||||
if [ ! -d "$BASEDIR/env" ]; then
|
||||
|
||||
if [ ! "$(command -v pyvenv-3.5)" ]; then
|
||||
echo "Cannot find supported python version 3.5. Exiting..."
|
||||
if [ ! -d "${BUILDDIR}/${VENV}" ]; then
|
||||
# Check for required prerequisites.
|
||||
echo "Checking prerequisites..."
|
||||
if [ ! "$(command -v ${PYTHON})" ]; then
|
||||
echo "Cannot find python. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pyvenv-3.5 $BASEDIR/env
|
||||
echo "Virtualenv created."
|
||||
PYTHON_MAJOR=$(${PYTHON} -c 'import sys; print(sys.version_info[0])')
|
||||
PYTHON_MINOR=$(${PYTHON} -c 'import sys; print(sys.version_info[1])')
|
||||
|
||||
if [ -f "$BASEDIR/env/bin/activate" ]; then
|
||||
source $BASEDIR/env/bin/activate
|
||||
else
|
||||
$BASEDIR/env/Scripts/activate
|
||||
if [ "${PYTHON_MAJOR}" != "3" ] || [ "${PYTHON_MINOR}" != "5" ]; then
|
||||
echo "Cannot find supported python version 3.5. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
echo "Virtualenv activated."
|
||||
if [ "$(uname)" = "Windows_NT" ]; then
|
||||
if [ ! "$(command -v ${VIRTUALENV})" ]; then
|
||||
echo "Cannot find virtualenv. Exiting..."
|
||||
fi
|
||||
fi
|
||||
echo "Prerequisite checks passed."
|
||||
|
||||
pip install -r $BASEDIR/requirements.txt
|
||||
pip install -e $BASEDIR
|
||||
echo "Requirements installed."
|
||||
|
||||
elif [ ! -f "$BASEDIR/env/bin/activate" -o "$BASEDIR/setup.py" -nt "$BASEDIR/env/bin/activate" ]; then
|
||||
|
||||
source $BASEDIR/env/bin/activate
|
||||
echo "Virtualenv activated."
|
||||
|
||||
pip install -r $BASEDIR/requirements.txt
|
||||
pip install -e $BASEDIR
|
||||
echo "Requirements installed."
|
||||
# Create the virtualenv.
|
||||
echo "Creating virtualenv..."
|
||||
if [ "$(uname)" = "Windows_NT" ]; then
|
||||
mkdir -p ${BUILDDIR}/${VENV}; cd ${BUILDDIR}/${VENV}
|
||||
${VIRTUALENV} --python=$(which ${PYTHON}) --prompt="${PROMPT}" --no-site-packages ${BUILDDIR}/${VENV}
|
||||
${VIRTUALENV} --relocatable ${BUILDDIR}/${VENV}
|
||||
cd -
|
||||
else
|
||||
${PYTHON} -m venv ${BUILDDIR}/${VENV}
|
||||
sed -i'' -e "s#(${VENV}) #${PROMPT}#g" ${BUILDDIR}/${VENV}/${BIN}/activate
|
||||
fi
|
||||
echo "Virtualenv created: ${BUILDDIR}/${VENV}"
|
||||
|
||||
# Install all requirements into the virtualenv.
|
||||
echo "Installing virtualenv requirements..."
|
||||
${BUILDDIR}/${VENV}/${BIN}/pip${EXE} install --upgrade pip
|
||||
${BUILDDIR}/${VENV}/${BIN}/pip${EXE} install -r ${BASEDIR}/requirements.txt
|
||||
${BUILDDIR}/${VENV}/${BIN}/pip${EXE} install -e ${BASEDIR}
|
||||
if [ "$(uname)" = "Windows_NT" ]; then
|
||||
${VIRTUALENV} --relocatable ${BUILDDIR}/${VENV}
|
||||
fi
|
||||
echo "Virtualenv requirements installed."
|
||||
else
|
||||
echo "Virtualenv already exists: '${BUILDDIR}/${VENV}'"
|
||||
fi
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
#!/bin/bash -e
|
||||
#!/bin/bash
|
||||
|
||||
BASEDIR=`dirname $0`/..
|
||||
if [ -f "$BASEDIR/env/bin/python" ]; then
|
||||
CURRDIR=$(dirname "${0}")
|
||||
source ${CURRDIR}/common.sh
|
||||
|
||||
PYTHON="$BASEDIR/env/bin/python"
|
||||
else
|
||||
PYTHON="$BASEDIR/env/Scripts/python.exe"
|
||||
fi
|
||||
cd ${BASEDIR}
|
||||
|
||||
mkdir -p ${BUILDDIR}/${DIST}/build
|
||||
rm -rf ${BUILDDIR}/${DIST}/build/packages
|
||||
|
||||
echo "Building wheel..."
|
||||
"$PYTHON" setup.py bdist_wheel
|
||||
${BUILDDIR}/${VENV}/${BIN}/python${EXE} setup.py bdist_wheel \
|
||||
--dist-dir=${BUILDDIR}/${DIST}
|
||||
|
||||
echo "Building egg..."
|
||||
"$PYTHON" setup.py sdist
|
||||
${BUILDDIR}/${VENV}/${BIN}/python${exe} setup.py sdist \
|
||||
--dist-dir=${BUILDDIR}/${DIST}
|
||||
|
||||
mv build ${BUILDDIR}/${DIST}/build/packages
|
||||
echo "Packages built."
|
||||
|
||||
17
bin/test.sh
17
bin/test.sh
@@ -1,13 +1,8 @@
|
||||
#!/bin/bash -e
|
||||
#!/bin/bash
|
||||
|
||||
BASEDIR=`dirname $0`/..
|
||||
CURRDIR=$(dirname "${0}")
|
||||
source ${CURRDIR}/common.sh
|
||||
|
||||
cd $BASEDIR
|
||||
if [ -f "$BASEDIR/env/bin/activate" ]; then
|
||||
source $BASEDIR/env/bin/activate
|
||||
else
|
||||
$BASEDIR/env/Scripts/activate
|
||||
fi
|
||||
echo "Virtualenv activated."
|
||||
|
||||
tox
|
||||
echo "Running tests..."
|
||||
TOXWORKDIR=${BUILDDIR}/${TOX} ${BUILDDIR}/${VENV}/${BIN}/tox${EXE}
|
||||
echo "Tests completed."
|
||||
|
||||
50
cli/Makefile
50
cli/Makefile
@@ -1,22 +1,40 @@
|
||||
all: env test packages
|
||||
all: env packages binary test
|
||||
all-docker: env-docker packages-docker binary-docker test-docker
|
||||
|
||||
clean:
|
||||
bin/clean.sh
|
||||
@bash bin/clean.sh
|
||||
|
||||
distclean: clean
|
||||
@bash bin/distclean.sh
|
||||
|
||||
env:
|
||||
bin/env.sh
|
||||
|
||||
test: env
|
||||
bin/test.sh
|
||||
|
||||
binary: clean env packages
|
||||
bin/create-binary.sh
|
||||
|
||||
test-binary: binary
|
||||
bin/test-binary.sh
|
||||
|
||||
doc: env
|
||||
bin/doc.sh
|
||||
@bash bin/env.sh
|
||||
|
||||
packages: env
|
||||
bin/packages.sh
|
||||
@bash bin/packages.sh
|
||||
|
||||
binary: env
|
||||
@bash bin/binary.sh
|
||||
|
||||
test: env
|
||||
@bash bin/test.sh
|
||||
|
||||
test-binary: binary
|
||||
@bash bin/test-binary.sh
|
||||
|
||||
env-docker:
|
||||
@bash bin/docker.sh env
|
||||
|
||||
packages-docker: env-docker
|
||||
@bash bin/docker.sh packages
|
||||
|
||||
binary-docker: env-docker
|
||||
@bash bin/docker.sh binary
|
||||
|
||||
test-docker: env-docker
|
||||
@bash bin/docker.sh test
|
||||
|
||||
test-binary-docker: binary-docker
|
||||
@bash bin/docker.sh test-binary
|
||||
|
||||
.PHONY: env env-docker
|
||||
|
||||
11
cli/bin/binary.sh
Executable file
11
cli/bin/binary.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURRDIR=$(dirname "${0}")
|
||||
source ${CURRDIR}/common.sh
|
||||
|
||||
echo "Building binary..."
|
||||
${BUILDDIR}/${VENV}/${BIN}/pyinstaller${EXE} \
|
||||
--workpath=${BUILDDIR}/${DIST}/build \
|
||||
--distpath=${BUILDDIR}/${DIST} \
|
||||
${BASEDIR}/binary.spec
|
||||
echo "Binary built."
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
set -o errexit -o nounset
|
||||
|
||||
BASEDIR=`dirname $0`/..
|
||||
|
||||
rm -rf $BASEDIR/.tox $BASEDIR/env $BASEDIR/dist $BASEDIR/build
|
||||
find $BASEDIR -name '*.pyc' -delete || true
|
||||
echo "Deleted virtualenv and test artifacts."
|
||||
|
||||
1
cli/bin/clean.sh
Symbolic link
1
cli/bin/clean.sh
Symbolic link
@@ -0,0 +1 @@
|
||||
../../bin/clean.sh
|
||||
5
cli/bin/common.sh
Normal file
5
cli/bin/common.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
CURRDIR=$(dirname "${0}")
|
||||
|
||||
: ${PROMPT:="(dcos-cli/cli) "}
|
||||
|
||||
source ${CURRDIR}/../../bin/common.sh
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
BASEDIR=`dirname $0`/..
|
||||
|
||||
cd $BASEDIR
|
||||
|
||||
if [ -f "$BASEDIR/env/bin/activate" ]; then
|
||||
source $BASEDIR/env/bin/activate
|
||||
else
|
||||
$BASEDIR/env/Scripts/activate
|
||||
fi
|
||||
|
||||
pip install pyinstaller==3.1.1
|
||||
pyinstaller $BASEDIR/binary/binary.spec
|
||||
|
||||
deactivate
|
||||
1
cli/bin/distclean.sh
Symbolic link
1
cli/bin/distclean.sh
Symbolic link
@@ -0,0 +1 @@
|
||||
../../bin/distclean.sh
|
||||
@@ -1,9 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
BASEDIR=`dirname $0`/..
|
||||
|
||||
cd $BASEDIR
|
||||
source $BASEDIR/env/bin/activate
|
||||
echo "Virtualenv activated."
|
||||
|
||||
sphinx-build -W -b html pydoc pydoc/_build
|
||||
20
cli/bin/docker.sh
Executable file
20
cli/bin/docker.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURRDIR=$(dirname "${0}")
|
||||
source ${CURRDIR}/common.sh
|
||||
|
||||
: ${DOCKER_RUN:="docker run \
|
||||
--rm \
|
||||
-v ${BASEDIR}/..:/dcos-cli \
|
||||
-v ${HOME}:/home/${USER} \
|
||||
-v /etc/passwd:/etc/passwd:ro \
|
||||
-v /etc/group:/etc/group:ro \
|
||||
-e HOME=/home/${USER} \
|
||||
-e VENV=${VENV_DOCKER} \
|
||||
-e DIST=${DIST_DOCKER} \
|
||||
-e TOX=${TOX_DOCKER} \
|
||||
-w /dcos-cli/cli \
|
||||
-u $(id -u ${USER}):$(id -g ${USER}) \
|
||||
python:3.5"}
|
||||
|
||||
source ${BASEDIR}/../bin/docker.sh
|
||||
@@ -1,35 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
BASEDIR=`dirname $0`/..
|
||||
|
||||
if [ ! -d "$BASEDIR/env" ]; then
|
||||
|
||||
if [ ! "$(command -v pyvenv-3.5)" ]; then
|
||||
echo "Cannot find supported python version 3.5. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pyvenv-3.5 $BASEDIR/env
|
||||
echo "Virtualenv created."
|
||||
|
||||
if [ -f "$BASEDIR/env/bin/activate" ]; then
|
||||
source $BASEDIR/env/bin/activate
|
||||
else
|
||||
$BASEDIR/env/Scripts/activate
|
||||
fi
|
||||
echo "Virtualenv activated."
|
||||
|
||||
pip install -r $BASEDIR/requirements.txt
|
||||
pip install -e $BASEDIR
|
||||
echo "Requirements installed."
|
||||
|
||||
elif [ ! -f "$BASEDIR/env/bin/activate" -o "$BASEDIR/setup.py" -nt "$BASEDIR/env/bin/activate" ]; then
|
||||
|
||||
source $BASEDIR/env/bin/activate
|
||||
echo "Virtualenv activated."
|
||||
|
||||
pip install -r $BASEDIR/requirements.txt
|
||||
pip install -e $BASEDIR
|
||||
echo "Requirements installed."
|
||||
|
||||
fi
|
||||
1
cli/bin/env.sh
Symbolic link
1
cli/bin/env.sh
Symbolic link
@@ -0,0 +1 @@
|
||||
../../bin/env.sh
|
||||
@@ -1,15 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
BASEDIR=`dirname $0`/..
|
||||
if [ -f "$BASEDIR/env/bin/python" ]; then
|
||||
|
||||
PYTHON="$BASEDIR/env/bin/python"
|
||||
else
|
||||
PYTHON="$BASEDIR/env/Scripts/python.exe"
|
||||
fi
|
||||
|
||||
echo "Building wheel..."
|
||||
"$PYTHON" setup.py bdist_wheel
|
||||
|
||||
echo "Building egg..."
|
||||
"$PYTHON" setup.py sdist
|
||||
1
cli/bin/packages.sh
Symbolic link
1
cli/bin/packages.sh
Symbolic link
@@ -0,0 +1 @@
|
||||
../../bin/packages.sh
|
||||
@@ -1,17 +1,7 @@
|
||||
#!/bin/bash -e
|
||||
#!/bin/bash
|
||||
|
||||
BASEDIR=`dirname $0`/..
|
||||
CURRDIR=$(dirname "${0}")
|
||||
source ${CURRDIR}/common.sh
|
||||
|
||||
cd $BASEDIR
|
||||
|
||||
if [ -f "$BASEDIR/env/bin/activate" ]; then
|
||||
cp tests/data/dcos.toml $DCOS_CONFIG
|
||||
source $BASEDIR/env/bin/activate
|
||||
else
|
||||
export DCOS_CONFIG=tests/data/dcos.toml
|
||||
$BASEDIR/env/Scripts/activate
|
||||
fi
|
||||
|
||||
export PATH=$BASEDIR/dist:$PATH
|
||||
py.test tests/integrations
|
||||
deactivate
|
||||
export PATH="${BUILDDIR}/${DIST}:${PATH}"
|
||||
source ${CURRDIR}/test.sh
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
BASEDIR=`dirname $0`/..
|
||||
|
||||
cd $BASEDIR
|
||||
if [ -f "$BASEDIR/env/bin/activate" ]; then
|
||||
source $BASEDIR/env/bin/activate
|
||||
else
|
||||
$BASEDIR/env/Scripts/activate
|
||||
fi
|
||||
echo "Virtualenv activated."
|
||||
|
||||
chmod 600 $BASEDIR/tests/data/dcos.toml
|
||||
|
||||
tox
|
||||
1
cli/bin/test.sh
Symbolic link
1
cli/bin/test.sh
Symbolic link
@@ -0,0 +1 @@
|
||||
../../bin/test.sh
|
||||
@@ -3,4 +3,5 @@ tox>=2.2, <3.0
|
||||
wheel>=0.24.0, <1.0
|
||||
pytest>=2.9.1
|
||||
teamcity-messages>=1.20
|
||||
PyInstaller==3.2.1
|
||||
-e .. # Install the DC/OS package
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[tox]
|
||||
envlist = py35-syntax, py35-unit, py35-integration
|
||||
toxworkdir={env:TOXWORKDIR:.tox}
|
||||
|
||||
[flake8]
|
||||
application-import-names=dcos,dcoscli
|
||||
|
||||
1
tox.ini
1
tox.ini
@@ -1,5 +1,6 @@
|
||||
[tox]
|
||||
envlist = py35-syntax, py35-unit
|
||||
toxworkdir={env:TOXWORKDIR:.tox}
|
||||
|
||||
[flake8]
|
||||
application-import-names=dcos
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[tox]
|
||||
envlist = py35-unit
|
||||
toxworkdir={env:TOXWORKDIR:.tox}
|
||||
|
||||
[testenv]
|
||||
setenv =
|
||||
|
||||
Reference in New Issue
Block a user