Skip to content

Commit

Permalink
Build bdcs-cli and run tests inside Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Sep 18, 2017
1 parent d9c4916 commit 55be922
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 22 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.sql
*.tix
*.db
*.repo/
cabal.sandbox.config
.cabal-sandbox/
.git/
dist/
import
export
bdcs-cli
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dist
export
import
*.tar
*.repo
32 changes: 16 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@ cache:

before_install:
- sudo docker pull welder/bdcs-api-rs:latest
- sudo pip install s3cmd toml parameterized
- sudo docker pull welder/bdcs-cli:latest
- sudo pip install s3cmd
- wget --progress=dot:giga https://haskell.org/platform/download/8.0.2/haskell-platform-8.0.2-unknown-posix--minimal-x86_64.tar.gz
- tar -xzvf ./haskell-platform-8.0.2-unknown-posix--minimal-x86_64.tar.gz
- sudo ./install-haskell-platform.sh
- travis_retry cabal update && cabal install hlint hpc-coveralls
- travis_retry cabal update && cabal install hpc-coveralls

script:
- |
if [ "$TRAVIS_EVENT_TYPE" == "cron" ]; then
./tests/test_images.sh
else
~/.cabal/bin/hlint .
cabal install --dependencies-only --enable-tests --force-reinstalls
cabal configure --enable-tests --enable-coverage --ghc-option=-DTEST
cabal build
cabal test --show-details=always
# tests for bdcs-cli binary
./tests/test_binary.sh
# depsolve integration tests
./tests/test_depsolve.sh
# collect binary coverage
mkdir ./dist/hpc/vanilla/tix/bdcs-cli/
mv bdcs-cli.tix ./dist/hpc/vanilla/tix/bdcs-cli/
make test-in-docker
# copy the newly built files and coverage data out of
# the container
sudo docker create --name test-cont welder/bdcs-cli-integration-test:latest
sudo docker cp test-cont:/bdcs-cli/dist ./dist
sudo docker rm test-cont
fi
after_success:
- |
if [ "$TRAVIS_EVENT_TYPE" != "cron" ]; then
sudo chown travis:travis -R ./dist
~/.cabal/bin/hpc-coveralls --display-report spec bdcs-cli
if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
sudo docker tag welder/bdcs-cli:latest welder/bdcs-cli:$TRAVIS_BUILD_NUMBER
docker login -u atodorov -p $DOCKER_PASSWORD
docker push welder/bdcs-cli
s3cmd sync --access_key="$ARTIFACTS_KEY" --secret_key="$ARTIFACTS_SECRET" \
-v -P ./dist/build/bdcs-cli/bdcs-cli s3://weldr/bdcs-cli
fi
Expand Down
27 changes: 27 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM fedora:26

COPY bdcs-deps.dnf /etc/yum.repos.d/bdcs-deps.repo
RUN dnf -y install sudo cabal-install python-toml python-nose-parameterized \
gobject-introspection-devel ghc-*weldr* \
ghc-haskell-gi{,-devel}-0.20.3-1.fc26.weldr.1 \
libgit2-glib{,-devel}-0.26.0-2.fc26.weldr.1 hlint

RUN mkdir /bdcs-cli
WORKDIR /bdcs-cli

# install the build dependencies first so we can cache this layer
COPY BDCSCli.cabal .
RUN cabal update
RUN for i in `cabal install --dependencies-only --enable-tests --enable-coverage --dry-run | \
grep - | grep -v "In order" | grep -v basement | grep -v overloading | \
sed -r 's|-[0-9]+(\.[0-9]+)*||'`; do \
echo ghc-$i ghc-$i-devel; done | xargs dnf -y install && dnf clean all

# copy the rest of the code
COPY . /bdcs-cli

# build the application
RUN hlint .
RUN cabal configure --enable-tests --enable-coverage --ghc-option=-DTEST && \
cabal build && \
cabal test --show-details=always
11 changes: 11 additions & 0 deletions Dockerfile.integration-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM welder/bdcs-cli:latest

# tests for bdcs-cli binary
RUN ./tests/test_binary.sh

# depsolve integration tests
ENV START_API_EXTERNALLY 1
RUN ./tests/test_depsolve.sh

# collect binary coverage
RUN mkdir ./dist/hpc/vanilla/tix/bdcs-cli/ && mv bdcs-cli.tix ./dist/hpc/vanilla/tix/bdcs-cli/
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ORG_NAME=welder

default: all

all: bdcs-cli
Expand Down Expand Up @@ -26,4 +28,15 @@ tests: sandbox
cabal test
./tests/test_binary.sh

test-in-docker: Dockerfile.build
sudo docker network create welder
# download metadata and run the API backend which provides depsolving
[ -f "metadata.db" ] || curl https://s3.amazonaws.com/weldr/metadata.db > metadata.db
sudo docker ps | grep api || sudo docker run -d --rm --name api -p 4000:4000 -v `pwd`:/mddb --security-opt label=disable --network welder welder/bdcs-api-rs:latest

sudo docker build -t $(ORG_NAME)/bdcs-cli:latest -f $< --cache-from $(ORG_NAME)/bdcs-cli:latest .
sudo docker build -t $(ORG_NAME)/bdcs-cli-integration-test:latest -f Dockerfile.integration-test --network welder .
sudo docker stop api
sudo docker network remove welder

.PHONY: sandbox bdcs-cli clean test hlint
5 changes: 5 additions & 0 deletions bdcs-deps.dnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[bdcs-deps]
name = BDCS Deps
baseurl = https://s3.amazonaws.com/weldr/bdcs-deps/
enabled = 1
gpgcheck = 0
5 changes: 4 additions & 1 deletion tests/test_depsolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
_RECIPE_DIR = os.path.abspath(_RECIPE_DIR)

_DEPSOLVE = os.path.join(_TEST_DIR, '..', 'dist', 'build', 'bdcs-cli', 'bdcs-cli')
_DEPSOLVE = [os.path.abspath(_DEPSOLVE), 'recipes', 'depsolve']
_DEPSOLVE = [os.path.abspath(_DEPSOLVE)]
if os.environ.get('START_API_EXTERNALLY'):
_DEPSOLVE.extend(['--url', 'http://api:4000/'])
_DEPSOLVE.extend(['recipes', 'depsolve'])

_RECIPES = []
for _dirpath, _dirnames, filenames in os.walk(_RECIPE_DIR):
Expand Down
20 changes: 15 additions & 5 deletions tests/test_depsolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ set -x
BDCS_CLI="./dist/build/bdcs-cli/bdcs-cli"

METADATA_DB="metadata.db"
[ -f "$METADATA_DB" ] || curl https://s3.amazonaws.com/weldr/metadata.db > "$METADATA_DB"

# start the backend API which provides depsolving
# later this will be replaces with the depsolver from bdcs library
sudo docker run -d --rm --name api -p 4000:4000 -v `pwd`:/mddb --security-opt label=disable welder/bdcs-api-rs:latest
# start the backend API which provides depsolving only if not running already
# later this will be replaced with the depsolver from bdcs library
if [ -z "$START_API_EXTERNALLY" ]; then
sudo docker ps | grep api
if [ $? -ne 0 ]; then
[ -f "$METADATA_DB" ] || curl https://s3.amazonaws.com/weldr/metadata.db > "$METADATA_DB"
sudo docker run -d --rm --name api -p 4000:4000 -v `pwd`:/mddb --security-opt label=disable welder/bdcs-api-rs:latest
fi
fi

python ./tests/test_depsolve.py -v
RUNNER="python"
rpm -q python-nose-parameterized >/dev/null
if [ $? -eq 0 ]; then
RUNNER="nosetests"
fi
$RUNNER ./tests/test_depsolve.py -v

0 comments on commit 55be922

Please sign in to comment.