diff --git a/.travis.yml b/.travis.yml index e870c1e..17752ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,26 @@ language: python -python: - - "3.7" -install: - - pip install -r requirements.txt +services: + - docker -script: - - pytest -s tests/ \ No newline at end of file + +jobs: + include: + - stage: test + if: (type IN (pull_request)) + install: + - pip install -r requirements + script: + - pytest -s tests/ + + - stage: build docker + if: (branch = master) AND (NOT (type IN (pull_request))) + install: + - docker pull byjg/k8s-ci + script: + - docker run --privileged -v /tmp/z:/var/lib/containers -it --rm -v $PWD:/work -w /work -e DOCKER_USERNAME=$DOCKER_USERNAME -e DOCKER_PASSWORD=$DOCKER_PASSWORD -e DOCKER_REGISTRY=$DOCKER_REGISTRY byjg/k8s-ci /work/build-multiarch.sh + + - stage: documentation + if: (branch = master) AND (NOT (type IN (pull_request))) + install: skip + script: "curl https://opensource.byjg.com/add-doc.sh | bash /dev/stdin devops docker-easy-haproxy" diff --git a/Dockerfile b/Dockerfile index 6dcc7c0..86f11ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,10 @@ RUN pip3 install --upgrade pip \ COPY templates /scripts/templates/ COPY easymapping /scripts/easymapping/ +COPY tests/ /scripts/tests/ COPY assets / +RUN pytest -s tests/ + CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf" ] diff --git a/README.md b/README.md index 2af85c4..8f040f2 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Important: easyhaproxy needs to be in the same network of the containers or othe | com.byjg.easyhaproxy.host.[definition] | What is the host that the HAProxy will listen to. | somehost.com | | com.byjg.easyhaproxy.redirect.[definition] | (Optional) Host redirects from connections in the port defined above. | foo.com--https://bla.com,bar.com--https://bar.org | | com.byjg.easyhaproxy.sslcert.[definition] | (Optional) Cert PEM Base64 encoded. | | -| com.byjg.easyhaproxy.health-check.[definition] | (Optional) `ssl`, enable health check via SSL in `mode tcp` (Defaults to "empty") | | +| com.byjg.easyhaproxy.health-check.[definition] | (Optional) `ssl`, enable health check via SSL in `mode tcp` (Defaults to "empty") | | Note: if you are deploying a stack set labels at the `deploy` level: diff --git a/build-multiarch.sh b/build-multiarch.sh new file mode 100755 index 0000000..6a5ae0e --- /dev/null +++ b/build-multiarch.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -e + +# Start k8s-ci before run this command +# docker run --privileged -v /tmp/z:/var/lib/containers -it --rm -v $PWD:/work -w /work byjg/k8s-ci + +if [ -z "$DOCKER_USERNAME" ] || [ -z "$DOCKER_PASSWORD" ] || [ -z "$DOCKER_REGISTRY" ] +then + echo You need to setup \$DOCKER_USERNAME, \$DOCKER_PASSWORD and \$DOCKER_REGISTRY before run this command. + exit 1 +fi + +buildah login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD $DOCKER_REGISTRY + +podman run --rm --events-backend=file --cgroup-manager=cgroupfs --privileged docker://multiarch/qemu-user-static --reset -p yes + +VERSIONS="latest $TRAVIS_TAG" +for VERSION in $VERSIONS +do + DOCKERFILE=Dockerfile + + buildah manifest create byjg/easy-haproxy:$VERSION + + buildah bud --arch arm64 --os linux --iidfile /tmp/iid-arm64 -f $DOCKERFILE -t byjg/easy-haproxy:$VERSION-arm64 . + buildah bud --arch amd64 --os linux --iidfile /tmp/iid-amd64 -f $DOCKERFILE -t byjg/easy-haproxy:$VERSION-amd64 . + + buildah manifest add byjg/easy-haproxy:$VERSION --arch arm64 --os linux --variant v8 $(cat /tmp/iid-arm64) + buildah manifest add byjg/easy-haproxy:$VERSION --arch amd64 --os linux --os=linux $(cat /tmp/iid-amd64) + + buildah manifest push --all --format v2s2 byjg/easy-haproxy:$VERSION docker://byjg/easy-haproxy:$VERSION +done + diff --git a/requirements.txt b/requirements.txt index fa90f6f..364b4b7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ pyyaml docker -jinja2 \ No newline at end of file +jinja2 +pytest \ No newline at end of file diff --git a/templates/bind.j2 b/templates/bind.j2 index abbd254..6cad5ff 100644 --- a/templates/bind.j2 +++ b/templates/bind.j2 @@ -1,5 +1,5 @@ {% if "ssl_cert" in o %} - bind *:{{ o["port"] }} ssl crt {{ o["ssl_cert"] }} + bind *:{{ o["port"] }} ssl crt {{ o["ssl_cert"] }} {% elif "h2" in o and o["h2"] %} bind *:{{ o["port"] }} proto h2 option http-use-htx diff --git a/templates/haproxy.cfg.j2 b/templates/haproxy.cfg.j2 index 6214a4c..e04b1e5 100644 --- a/templates/haproxy.cfg.j2 +++ b/templates/haproxy.cfg.j2 @@ -60,8 +60,8 @@ backend srv_{{ host }} http-request add-header X-Forwarded-Proto https if { ssl_fc } {% elif mode == "tcp" %} option tcp-check - tcp-check connect{{ " ssl" if o["health-check"] == "ssl" }} + tcp-check connect{{ " ssl" if o["health-check"] == "ssl" }} {% endif %} - server srv {{ o["hosts"][k] }} check weight 1{{ " verify none" if o["health-check"] == "ssl" }} + server srv {{ o["hosts"][k] }} check weight 1{{ " verify none" if o["health-check"] == "ssl" }} {% endfor %} {% endfor %}