build, docs: Improve macOS building

- New docker command for quickly running tasks in a Linux environment.
- Updated docs with macOS specific details.
- Fixed some test issues.
- Add (fallible) macOS test target for Travis.
This commit is contained in:
Johan Bloemberg
2018-02-09 13:10:59 +01:00
committed by James Shubin
parent e37bb3ac8a
commit ba21554c5f
17 changed files with 104 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
## Tips:
* please read the style guide before submitting your patch:
[docs/style-guide.md](docs/style-guide.md)
[docs/style-guide.md](../docs/style-guide.md)
* commit message titles must be in the form:
```topic: Capitalized message with no trailing period```

View File

@@ -1,4 +1,7 @@
language: go
os:
- linux
- osx
go:
- 1.8.x
- 1.9.x
@@ -7,7 +10,7 @@ go_import_path: github.com/purpleidea/mgmt
sudo: true
dist: trusty
before_install:
- sudo apt update
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then sudo apt update; fi
- git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
- git fetch --unshallow
install: 'make deps'
@@ -17,6 +20,7 @@ matrix:
allow_failures:
- go: tip
- go: 1.9.x
- os: osx
notifications:
irc:
channels:

View File

@@ -35,4 +35,4 @@ bindata.go: ../COPYING
clean:
# remove generated bindata/*.go
@ROOT=$$(dirname "$${BASH_SOURCE}")/.. && rm *.go
@ROOT=$$(dirname "$${BASH_SOURCE}")/.. && rm -f *.go

18
docker/scripts/exec-development Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/bash
# runs command provided as argument inside a development (Linux) Docker container
# Stop on any error
set -e
script_directory="$( cd "$( dirname "$0" )" && pwd )"
project_directory=$script_directory/../..
# Specify the Docker image name
image_name='purpleidea/mgmt:development'
# Run container in development mode
docker run --rm --name=mgm_development --user=mgmt \
-v "$project_directory:/go/src/github.com/purpleidea/mgmt/" \
-w /go/src/github.com/purpleidea/mgmt/ \
-it "$image_name" /bin/bash -c "$*"

View File

@@ -14,6 +14,7 @@ Once you're familiar with the general idea, please start hacking...
* You need golang version 1.8 or greater installed.
** To install on rpm style systems: `sudo dnf install golang`
** To install on apt style systems: `sudo apt install golang`
** To install on macOS systems install [Homebrew](https://brew.sh) and run: `brew install go`
* You can run `go version` to check the golang version.
* If your distro is tool old, you may need to [download](https://golang.org/dl/) a newer golang version.
@@ -97,3 +98,43 @@ At the moment we have:
* [Arch](https://aur.archlinux.org/packages/mgmt/)
Please contribute more! We'd especially like to see a Debian package!
## OSX/macOS/Darwin development
Developing and running `mgmt` on macOS is currently not supported (but not discouraged either). Meaning it might work but in the case it doesn't you would have to provide your own patches to fix problems (the project maintainer and community are glad to assist where needed).
There are currently some issues that make `mgmt` less suitable to run for provisioning macOS (eg: https://github.com/purpleidea/mgmt/issues/33). But as a client to provision remote servers it should run fine.
Since the primary supported systems are Linux and these are the environments tested for it is wise to run these suites during macOS development as well. To ease this Docker can be levaraged ((Docker for Mac)[https://docs.docker.com/docker-for-mac/]).
Before running any of the commands below create the development Docker image:
```
docker/scripts/build-development
```
This image requires updating every time dependencies (`make-deps.sh`) change.
Then to run the test suite:
```
docker run --rm -ti \
-v $PWD:/go/src/github.com/purpleidea/mgmt/ \
-w /go/src/github.com/purpleidea/mgmt/ \
purpleidea/mgmt:development \
make test
```
For convenience this command is wrapped in `docker/scripts/exec-development`.
Basically any command can be executed this way. Because the repository source is mounted into the Docker container invocation will be quick and allow rapid testing, example:
```
docker/scripts/exec-development test/test-shell.sh load0.sh
```
Other examples:
```
docker/scripts/exec-development make build
docker/scripts/exec-development ./mgmt run --tmp-prefix --lang examples/lang/load0.mcl
```

View File

@@ -39,7 +39,8 @@ if [ ! -z "$APT" ]; then
fi
if [ ! -z "$BREW" ]; then
$BREW install libvirt || true
# coreutils contains gtimeout
$BREW install libvirt augeas coreutils || true
fi
if [ ! -z "$PACMAN" ]; then

View File

@@ -10,7 +10,7 @@ mkdir -p "${MGMT_TMPDIR}"
> "${MGMT_TMPDIR}"sshd_config
# run empty graph, with prometheus support
timeout --kill-after=40s 35s ./mgmt run --tmp-prefix --yaml=augeas-1.yaml &
$timeout --kill-after=40s 35s ./mgmt run --tmp-prefix --yaml=augeas-1.yaml &
pid=$!
sleep 5s # let it converge

View File

@@ -1,9 +1,15 @@
#!/bin/bash -e
if [[ $(uname) == "Darwin" ]] ; then
# https://github.com/purpleidea/mgmt/issues/33
echo "This test is broken on macOS, skipping!"
exit
fi
set -x
# run till completion
timeout --kill-after=40s 35s ./mgmt run --yaml file-mode.yaml --converged-timeout=5 --no-watch --tmp-prefix &
$timeout --kill-after=40s 35s ./mgmt run --yaml file-mode.yaml --converged-timeout=5 --no-watch --tmp-prefix &
pid=$!
wait $pid # get exit status
e=$?

View File

@@ -1,10 +1,16 @@
#!/bin/bash -e
if [[ $(uname) == "Darwin" ]] ; then
# https://github.com/purpleidea/mgmt/issues/33
echo "This test is broken on macOS, skipping!"
exit
fi
mkdir -p /tmp/mgmt/
rm /tmp/mgmt/f1 || true
# run empty graph, with prometheus support
timeout --kill-after=40s 35s ./mgmt run --tmp-prefix --yaml=file-move.yaml 2>&1 | tee /tmp/mgmt/file-move.log &
$timeout --kill-after=40s 35s ./mgmt run --tmp-prefix --yaml=file-move.yaml 2>&1 | tee /tmp/mgmt/file-move.log &
pid=$!
sleep 5s # let it converge

View File

@@ -9,7 +9,7 @@ if ! timeout 1s sudo -A true; then
fi
# run till completion
timeout --kill-after=30s 25s sudo -A ./mgmt run --yaml file-owner.yaml --converged-timeout=5 --no-watch --tmp-prefix &
$timeout --kill-after=30s 25s sudo -A ./mgmt run --yaml file-owner.yaml --converged-timeout=5 --no-watch --tmp-prefix &
pid=$!
wait $pid # get exit status
e=$?

View File

@@ -1,7 +1,13 @@
#!/bin/bash -e
if [[ $(uname) == "Darwin" ]] ; then
# https://github.com/purpleidea/mgmt/issues/33
echo "This test is broken on macOS, skipping!"
exit
fi
# run a graph, with prometheus support
timeout --kill-after=40s 35s ./mgmt run --tmp-prefix --no-pgp --prometheus --yaml prometheus-3.yaml &
$timeout --kill-after=40s 35s ./mgmt run --tmp-prefix --no-pgp --prometheus --yaml prometheus-3.yaml &
pid=$!
sleep 10s # let it converge

View File

@@ -1,7 +1,13 @@
#!/bin/bash -xe
if [[ $(uname) == "Darwin" ]] ; then
# https://github.com/purpleidea/mgmt/issues/33
echo "This test is broken on macOS, skipping!"
exit
fi
# run a graph, with prometheus support
timeout --kill-after=30s 25s ./mgmt run --tmp-prefix --no-pgp --prometheus --yaml prometheus-4.yaml &
$timeout --kill-after=30s 25s ./mgmt run --tmp-prefix --no-pgp --prometheus --yaml prometheus-4.yaml &
pid=$!
sleep 10s # let it converge

View File

@@ -19,7 +19,7 @@ make build
buildout='test-examples.out'
# make symlink to outside of package
linkto="`pwd`/examples/lib/"
tmpdir="`mktemp --tmpdir -d tmp.XXX`" # get a dir outside of the main package
tmpdir="`$mktemp --tmpdir -d tmp.XXX`" # get a dir outside of the main package
cd "$tmpdir"
ln -s "$linkto" # symlink outside of dir
cd `basename "$linkto"`

View File

@@ -31,7 +31,7 @@ COUNT=`echo -e "$LINT" | wc -l` # number of golint problems in current branch
[ "$LINT" = "" ] && echo PASS && exit # everything is "perfect"
echo "$LINT" # display the issues
T=`mktemp --tmpdir -d tmp.X'X'X` # add quotes to avoid matching three X's
T=`$mktemp --tmpdir -d tmp.X'X'X` # add quotes to avoid matching three X's
[ "$T" = "" ] && fail_test "Could not create tmpdir"
cd $T || fail_test "Could not change into tmpdir $T"
git clone --recursive "${ROOT}" 2>/dev/null # make a copy

View File

@@ -25,7 +25,7 @@ function simplify-gocase() {
function token-coloncheck() {
# add quotes to avoid matching three X's
if grep -Ei "[\/]+[\/]+[ ]*+(FIXME[^:]|TODO[^:]|X"'X'"X[^:])" "$1"; then
if grep -Ei "[\/]+[\/]+[ ]*(FIXME[^:]|TODO[^:]|X"'X'"X[^:])" "$1"; then
return 1 # tokens must end with a colon
fi
return 0

View File

@@ -7,7 +7,7 @@ set -o pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir!
cd "$DIR" >/dev/null # work from main mgmt directory
make build
T=`mktemp --tmpdir -d tmp.X'X'X` # add quotes to avoid matching three X's
T=`$mktemp --tmpdir -d tmp.X'X'X` # add quotes to avoid matching three X's
cp -a ./mgmt "$T"/mgmt.1
make clean
make build

View File

@@ -2,8 +2,10 @@
if [[ $(uname) == "Darwin" ]] ; then
export timeout="gtimeout"
export mktemp="gmktemp"
else
export timeout="timeout"
export mktemp="mktemp"
fi
fail_test()