diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..64159e2 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,75 @@ +workflows: + version: 2 + build_test_deploy: + jobs: + - test + - publish_latest: + context: docker-hub + requires: + - test + filters: + branches: + only: + - master + - build_children: + context: circle-api + requires: + - publish_latest + +version: 2 +jobs: + test: + docker: + - image: circleci/python:2-jessie + steps: + - checkout + + - setup_remote_docker: # (2) + docker_layer_caching: true # (3) + - run: + name: Install goss + command: | + # rather than give internet scripts SU rights, we install to local user bin and add to path + mkdir ~/bin + export GOSS_DST=~/bin + export PATH=$PATH:~/bin + curl -fsSL https://goss.rocks/install | sh + goss -version + - run: + name: Test + command: | + # Don't forget path! + export PATH=$PATH:~/bin + # Important, change from mount to work on remote docker, see https://github.com/aelsabbahy/goss/pull/271 + # If using machine image you do not need this. + export GOSS_FILES_STRATEGY=cp + ./run-tests.sh circleci keepimage + - run: + name: Save docker image + command: | + mkdir -p workspace + docker save -o workspace/steamcache-monolithic.tar steamcache/monolithic:goss-test + - persist_to_workspace: + root: workspace + paths: + steamcache-monolithic.tar + - store_test_results: + path: reports + - store_artifacts: + path: reports + destination: reports + publish_latest: + docker: + - image: circleci/python:2-jessie + steps: + - setup_remote_docker: # (2) + docker_layer_caching: true # (3) + - attach_workspace: + at: /tmp/workspace + - run: + name: "Deploy latest to docker hub" + command: | + docker login -u $DOCKER_USER -p $DOCKER_PASS + docker load -i /tmp/workspace/steamcache-monolithic.tar + docker tag steamcache/monolithic:goss-test steamcache/monolithic:latest + docker push steamcache/monolithic:latest diff --git a/goss.yaml b/goss.yaml new file mode 100644 index 0000000..32eb20e --- /dev/null +++ b/goss.yaml @@ -0,0 +1,28 @@ +file: + /data/logs/access.log: + exists: true + contains: [] + /data/logs/error.log: + exists: true + contains: [] +port: + tcp:80: + listening: true +command: + /scripts/cache_test.sh: + exit-status: 0 + stdout: + - Succesfully Cached + timeout: 10000 +process: + nginx: + running: true + supervisord: + running: true +http: + http://127.0.0.1/steamcache-heartbeat: + status: 204 + allow-insecure: false + no-follow-redirects: false + timeout: 0 + body: [] diff --git a/goss_wait.yaml b/goss_wait.yaml new file mode 100644 index 0000000..aa919f9 --- /dev/null +++ b/goss_wait.yaml @@ -0,0 +1,8 @@ +process: + supervisord: + running: true + nginx: + running: true +port: + tcp:80: + listening: true diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 0000000..0dfdb29 --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,40 @@ +#!/bin/bash +which goss + +if [ $? -ne 0 ]; then + echo "Please install goss from https://goss.rocks/install" + echo "For a quick auto install run the following" + echo "curl -fsSL https://goss.rocks/install | sh" + exit $? +fi + +docker build --tag steamcache/monolithic:goss-test . +case $1 in + circleci) + shift; + mkdir -p ./reports/goss + if [[ "$1" == "keepimage" ]]; then + KEEPIMAGE=true + shift + fi + export GOSS_OPTS="$GOSS_OPTS --format junit" + dgoss run $@ steamcache/monolithic:goss-test > reports/goss/report.xml + #store result for exit code + RESULT=$? + #delete the junk that goss currently outputs :( + sed -i '0,/^.*<\/system-err>/d' reports/goss/report.xml + ;; + *) + if [[ "$1" == "keepimage" ]]; then + KEEPIMAGE=true + shift + fi + dgoss run $@ steamcache/monolithic:goss-test + RESULT=$? + ;; +esac +[[ "$KEEPIMAGE" == "true" ]] || docker rmi steamcache/monolithic:goss-test + +exit $RESULT