diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8ca3cc0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM registry.fedoraproject.org/fedora:26 + +ENV NAME=haproxy ARCH=x86_64 +LABEL MAINTAINER "Petr Hracek" +LABEL summary="HAProxy reverse proxy for high availability environments." \ + name="$FGC/$NAME" \ + version="0" \ + release="1.$DISTTAG" \ + architecture="$ARCH" \ + com.redhat.component=$NAME \ + usage="docker run -p 80:80 docker.io/modularityimages/haproxy" \ + help="Runs haproxy, which listens on port 80. No dependencies. See Help File below for more details." \ + description="HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments." \ + io.k8s.description="HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments." \ + io.k8s.diplay-name="HAProxy 1.6 " \ + io.openshift.expose-services="80:haproxy" \ + io.openshift.tags="haproxy" + +RUN dnf install -y --setopt=tsflags=nodocs haproxy which bash && \ + dnf -y clean all + +EXPOSE 80 + +ADD files /files +ADD help.md README.md / + +ENTRYPOINT ["/files/docker-entrypoint.sh"] +CMD ["/usr/sbin/haproxy", "-p", "/run/haproxy.pid", "-f", "/etc/haproxy/haproxy.cfg", "-D", "s"] + diff --git a/README.md b/README.md new file mode 100644 index 0000000..a88a8e7 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# haproxy + +HAProxy reverse proxy for high availability environments. + +## Summary + +- Dockerfile - build container image with haproxy. +- openshift-template.yml - Template for OpenShift to haproxy. + +## How to use the container + +* Copy ```./examples/haproxy.cfg``` to ```/etc/haproxy/haproxy.cfg``` +* Run two HTTPD servers on ```IP1```:```port1``` and ```IP2```:```port2``` +* Modify ```/etc/haproxy/haproxy.cfg``` so it uses relevant addresses and ports. + +Command for running haproxy docker container: + +```bash +docker run -it n +``` + +## How to run haproxy as standalone container + +Copy haproxy-container.service to ```/usr/lib/systemd/system/``` directory +```bash +sudo cp haproxy-container.service /usr/lib/systemd/system/ +systemctl daemon-reload +``` + +Command for running memcached as standalone container: +```bash +systemctl start haproxy-container +``` + +## How to stop memcached as standalone container +Command for stopping haproxy as standalone container: +```bash +systemctl stop haproxy-container +``` +## How to test the haproxy + +Statistic can be seen on haproxy url `http:///haproxy?stats`. + diff --git a/haproxy-container.service b/haproxy-container.service new file mode 100644 index 0000000..ce8b57f --- /dev/null +++ b/haproxy-container.service @@ -0,0 +1,10 @@ +[Unit] +Description="HAProxy reverse proxy for high availability environments." + +[Service] +ExecStart=/usr/bin/docker run -t -i -v /etc/sysconfig/haproxy:/etc/sysconfig/haproxy:ro -v /etc/haproxy/haproxy.cfg:/etc/haproxy/haproxy.cfg:ro -p 80:80 --name haproxy-container haproxy +ExecStop=/usr/bin/docker stop -t 2 haproxy-container +ExecStopPost=/usr/bin/docker rm -f haproxy-container + +[Install] +WantedBy=multi-user.target diff --git a/help.md b/help.md new file mode 100644 index 0000000..99a4a84 --- /dev/null +++ b/help.md @@ -0,0 +1,31 @@ +% HAPROXY(1) Container Image Pages +% Petr Hracek +% March 2, 2017 + +# NAME +haproxy - HAProxy reverse proxy for high availability environments. + +# DESCRIPTION +HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments. + +The container itself consists of: + - fedora/26 base image + - haproxy RPM package + +Files added to the container during docker build include: /files/haproxy.sh + +# USAGE +To get the memcached container image on your local system, run the following: + + docker pull hub.docker.io/phracek/haproxy + +# SECURITY IMPLICATIONS +Lists of security-related attributes that are opened to the host. + +-p 80:80 + Opens container port 80 and maps it to the same port on the host. + +# SEE ALSO +HAProxy page + + diff --git a/openshift-template.yml b/openshift-template.yml new file mode 100644 index 0000000..9b87c18 --- /dev/null +++ b/openshift-template.yml @@ -0,0 +1,44 @@ +apiVersion: v1 +kind: Template +metadata: + annotation: + description: HAProxy reverse proxy for high availability environments. + tags: haproxy + template: docker.io/phracek/haproxy + name: haproxy +objects: +- apiVersion: v1 + kind: ImageStream + metadata: + name: haproxy + spec: + dockerImageRepository: docker.io/phracek/haproxy + tags: + - name: latest +- apiVersion: v1 + kind: DeploymentConfig + metadata: + name: haproxy + spec: + dockerImageRepository: docker.io/phracek/haproxy + replicas: 1 + strategy: + type: Rolling + template: + metadata: + labels: + name: haproxy + spec: + containers: + - env: + image: docker.io/phracek/haproxy + name: haproxy + triggers: + - imageChangeParams: + automatic: true + containerNames: + - docker.io/phracek/haproxy + from: + kind: ImageStreamTag + name: haproxy:latest + type: ImageChange diff --git a/tests/config.yaml b/tests/config.yaml new file mode 100644 index 0000000..5750d08 --- /dev/null +++ b/tests/config.yaml @@ -0,0 +1,28 @@ +document: modularity-testing +version: 1 +name: haproxy +modulemd-url: http://raw.githubusercontent.com/container-images/haproxy/master/haproxy.yaml +service: + port: 80 +packages: + rpms: + - haproxy +module: + docker: + start: "docker run -it -p 80:80" + labels: + description: "HAProxy reverse proxy for high availability environments" + io.k8s.description: "HAProxy reverse proxy for high availability environments" + source: https://github.com/container-images/haproxy.git + container: docker.io/phracek/haproxy + rpm: + start: systemctl start haproxy + stop: systemctl stop haproxy + status: systemctl status haproxy + repos: + - http://download.englab.brq.redhat.com/pub/fedora/releases/25/Everything/x86_64/os/ + - https://phracek.fedorapeople.org/haproxy-module-repo/ +test: + processrunning: + - 'ls /proc/*/exe -alh | grep haproxy' + diff --git a/tests/generated.py b/tests/generated.py new file mode 100644 index 0000000..c2ec809 --- /dev/null +++ b/tests/generated.py @@ -0,0 +1,17 @@ +#!/usr/bin/python + +import socket +from avocado import main +import moduleframework + +if __name__ == '__main__': + main() + +class GeneratedTestsConfig(moduleframework.AvocadoTest): + """ + :avocado: enable + """ + + def test_processrunning(self): + self.start() + self.run("ls /proc/*/exe -alh | grep haproxy")