diff --git a/.travis/docker-hub-helper.sh b/.ci/docker-hub-helper.sh similarity index 100% rename from .travis/docker-hub-helper.sh rename to .ci/docker-hub-helper.sh diff --git a/.ci/setup-tools.sh b/.ci/setup-tools.sh new file mode 100755 index 0000000..669fae1 --- /dev/null +++ b/.ci/setup-tools.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +set -euo pipefail +IFS=$'\n\t' + +HADOLINT_VERSION=1.17.1 +DOCKER_COMPOSE_VERSION=1.23.2 +TRIVY_VERSION=0.1.1 +GOSS_VERSION=0.3.7 +COMMANDER_VERSION=1.2.1 + +if ! command -v hadolint > /dev/null; then + sudo curl -L "https://github.com/hadolint/hadolint/releases/download/v$HADOLINT_VERSION/hadolint-$(uname -s)-$(uname -m)" -o /usr/local/bin/hadolint + sudo chmod +rx /usr/local/bin/hadolint +fi + +if ! command -v docker-compose > /dev/null; then + sudo curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +rx /usr/local/bin/docker-compose +fi + +if ! command -v trivy > /dev/null; then + wget https://github.com/knqyf263/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz + sudo tar zxvf trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz -C /usr/local/bin trivy +fi + +if ! command -v goss > /dev/null; then + sudo curl -L https://github.com/aelsabbahy/goss/releases/download/v$GOSS_VERSION/goss-linux-amd64 -o /usr/local/bin/goss + sudo chmod +rx /usr/local/bin/goss +fi + +if ! command -v dcgoss > /dev/null; then + sudo curl -L https://raw.githubusercontent.com/fbartels/goss/dcgoss-v2/extras/dcgoss/dcgoss -o /usr/local/bin/dcgoss + sudo chmod +rx /usr/local/bin/dcgoss +fi + +if ! command -v commander > /dev/null; then + sudo curl -L https://github.com/SimonBaeumer/commander/releases/download/v$COMMANDER_VERSION/commander-linux-amd64 -o /usr/local/bin/commander + sudo chmod +rx /usr/local/bin/commander +fi + +if ! command -v commander > /dev/null; then + sudo curl -L https://raw.githubusercontent.com/fbartels/dccommander/master/dccommander -o /usr/local/bin/dccommander + sudo chmod +rx /usr/local/bin/commander +fi + +if ! command -v expect > /dev/null; then + sudo apt update && sudo apt install -y expect +fi + +if ! command -v yamllint > /dev/null; then + sudo pip install --upgrade pip && sudo pip install yamllint +fi + +if ! command -v eclint > /dev/null; then + npm install -g eclint +fi diff --git a/.travis.yml b/.travis.yml index cd453cf..30ad573 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,33 +4,11 @@ language: node_js node_js: - stable - -env: - global: - - HADOLINT_VERSION=1.17.1 - - DOCKER_COMPOSE_VERSION=1.23.2 - - TRIVY_VERSION=0.1.1 - - GOSS_VERSION=0.3.7 - - COMMANDER_VERSION=1.2.1 services: - docker before_install: - - sudo curl -L https://github.com/hadolint/hadolint/releases/download/v$HADOLINT_VERSION/hadolint-$(uname -s)-$(uname -m) -o /usr/local/bin/hadolint - - sudo rm /usr/local/bin/docker-compose - - sudo curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose - - wget https://github.com/knqyf263/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz - - sudo tar zxvf trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz -C /usr/local/bin trivy - - sudo curl -L https://github.com/aelsabbahy/goss/releases/download/v$GOSS_VERSION/goss-linux-amd64 -o /usr/local/bin/goss - - sudo curl -L https://raw.githubusercontent.com/fbartels/goss/dcgoss-v2/extras/dcgoss/dcgoss -o /usr/local/bin/dcgoss - - sudo curl -L https://github.com/SimonBaeumer/commander/releases/download/v$COMMANDER_VERSION/commander-linux-amd64 -o /usr/local/bin/commander - - sudo chmod +rx /usr/local/bin/hadolint - - sudo chmod +rx /usr/local/bin/docker-compose - - sudo chmod +rx /usr/local/bin/goss - - sudo chmod +rx /usr/local/bin/dcgoss - - sudo chmod +rx /usr/local/bin/commander - - sudo apt update && sudo apt install -y expect - - sudo pip install --upgrade pip && sudo pip install yamllint - - npm install -g eclint + - sudo rm /usr/local/bin/docker-compose # remove pre-installed docker-compose (too old) + - bash .ci/setup-tools.sh install: - "./version.sh" - make lint diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9e5c315..40cd804 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,9 +1,18 @@ # Contributing -When contributing to this repository, please first discuss the change you wish to make via issue, -email, or any other method with the owners of this repository before making a change. +When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. -Please see https://github.com/zokradonh/kopano-docker/blob/master/README.md#when-building-my-own-containers-how-can-i-make-sure-my-build-works-as-expected for testing remakrs +## Testing + +This project includes a few automated tests that can be run to ensure that containers start up and are operational. Required tools for testing can be installed by executing `bash .ci/setup-tools.sh`. + +The startup test can be executed by calling `make test-startup`. It spins up all containers and checks if they listen on their expected interfaces afterwards as well as execute some commands that should succeed on a succesful deployment. + +A more detailed test can be executed by calling `make test-goss`. This uses [Goss](https://github.com/aelsabbahy/goss) and its helper [dcgoss](https://github.com/aelsabbahy/goss/tree/master/extras/dcgoss) to validate the container configuration at runtime. These tests have not been implemented for all containers yet, but as an upside the same validation is used as part of the container healtcheck. Contributions are welcome! + +Testing the startup scripts of the containers is still a work in progress. When running `make test-commander` [Commander](https://github.com/SimonBaeumer/commander) will be used to test output of the `version.sh` script and some of the container startup scripts. + +## Tricks To speed up testing rebuilds you can override the git hash that is passed as a build argument. diff --git a/Makefile b/Makefile index 93c8eeb..76066c8 100644 --- a/Makefile +++ b/Makefile @@ -276,7 +276,7 @@ publish-container: ## Helper target to push a given image to a registry. Default done docker push $(docker_repo)/kopano_$(component):latest ifdef DOCKERREADME - .travis/docker-hub-helper.sh $(component) + .ci/docker-hub-helper.sh $(component) endif publish-base: tag-base diff --git a/README.md b/README.md index 4cfea4a..d13f4cc 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Instead of using the internal scheduler one can also just use an existing schedu This project also makes it possible to build Docker images based on the official Kopano releases. For this the following section needs to be modified in `.env`: -``` +```bash # Docker Repository to push to/pull from docker_repo=zokradonh COMPOSE_PROJECT_NAME=kopano @@ -101,6 +101,7 @@ COMPOSE_PROJECT_NAME=kopano #RELEASE_KEY_DOWNLOAD=1 #DOWNLOAD_COMMUNITY_PACKAGES=0 ``` + Just uncomment the last four lines and insert your Kopano subscription key where it currently says `REPLACE-ME`. Once this is done a `make build-all` will rebuild the images based on the latest available Kopano release (don't forget to `make tag-core` and `make tag-webapp` your images after building them). If you are running a private Docker Registry then you may also change `docker_repo` to reference your internal registry. @@ -111,13 +112,7 @@ The built image includes your subscription key! Do not push this image to any pu ### When building my own containers, how can I make sure my build works as expected? -This project includes a few automated tests that can be run to ensure that containers start up and are operational. - -The startup test can be executed by calling `make test-startup`. It spins up all containers and checks if they listen on their expected interfaces afterwards and executes some commands that should succeed on a succesful deployment. - -A more detailed test can be executed by calling `make test-goss`. This uses [Goss](https://github.com/aelsabbahy/goss) and its helper [dcgoss](https://github.com/aelsabbahy/goss/tree/master/extras/dcgoss) to validate the container configuration at runtime. These tests have not been implemented for all containers yet, but as an upside the same validation is used as part of the container healtcheck. Contributions are welcome! - -Testing the startup scripts of the containers is still a work in progress. When running `make test-commander` [Commander](https://github.com/SimonBaeumer/commander) will be used to test output of the `version.sh` script and some of the container startup scripts. +Please check the [contributing information](CONTRIBUTING.md). ### What if I want to use a different front facing proxy than the one in docker-compose? Or just some part of the compose file?