Skip to content

Commit b50f23d

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents bb263bb + b302a66 commit b50f23d

69 files changed

Lines changed: 2484 additions & 883 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM golang:1.9 AS build
1+
FROM golang:1.9.6 AS build
22
ADD . /src
33
WORKDIR /src
44
RUN go get -d -v -t
55
RUN go test --cover ./... --run UnitTest
66
RUN go build -v -o docker-flow-proxy
77

88

9-
FROM haproxy:1.8-alpine
9+
FROM haproxy:1.8.8-alpine
1010
MAINTAINER Viktor Farcic <viktor@farcic.com>
1111

1212
RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
@@ -15,19 +15,22 @@ RUN mkdir -p /cfg/tmpl /templates /certs /logs
1515
ENV CERTS="" \
1616
CAPTURE_REQUEST_HEADER="" \
1717
CFG_TEMPLATE_PATH="/cfg/tmpl/haproxy.tmpl" \
18-
CHECK_RESOLVERS=false \
18+
CHECK_RESOLVERS=false RESOLVERS="nameserver dns 127.0.0.11:53" \
1919
CONNECTION_MODE="http-keep-alive" \
20+
CRT_LIST_PATH="" \
2021
DEBUG="false" \
2122
DEFAULT_PORTS="80,443:ssl" \
2223
DEFAULT_REQ_MODE="http" \
2324
DO_NOT_RESOLVE_ADDR="false" \
2425
ENABLE_H2="true" \
26+
FILTER_PROXY_INSTANCE_NAME="false" \
2527
HEALTHCHECK="true" \
2628
HTTPS_ONLY="false" \
2729
EXTRA_FRONTEND="" \
2830
LISTENER_ADDRESS="" \
2931
MODE="default" \
3032
PROXY_INSTANCE_NAME="docker-flow" \
33+
RELOAD_ATTEMPTS="5" \
3134
RELOAD_INTERVAL="5000" REPEAT_RELOAD=false \
3235
RECONFIGURE_ATTEMPTS="20" \
3336
SEPARATOR="," \
@@ -43,9 +46,9 @@ EXPOSE 443
4346
EXPOSE 8080
4447

4548
RUN apk --no-cache add tini
46-
ENTRYPOINT ["/sbin/tini","--"]
49+
ENTRYPOINT ["/sbin/tini", "-g", "--"]
4750
CMD ["docker-flow-proxy", "server"]
48-
HEALTHCHECK --interval=5s --start-period=3s --timeout=5s CMD check.sh
51+
HEALTHCHECK --interval=5s --start-period=3s --timeout=10s CMD check.sh
4952

5053
COPY scripts/check.sh /usr/local/bin/check.sh
5154
RUN chmod +x /usr/local/bin/check.sh

Dockerfile.linux-arm

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
FROM arm32v7/haproxy
2+
COPY tmp/qemu-arm-static /usr/bin/qemu-arm-static
3+
4+
MAINTAINER Raymond Mouthaan <raymondmmouthaan@gmail.com>
5+
6+
ENV CERTS="" \
7+
CAPTURE_REQUEST_HEADER="" \
8+
CFG_TEMPLATE_PATH="/cfg/tmpl/haproxy.tmpl" \
9+
CHECK_RESOLVERS=false \
10+
CONNECTION_MODE="http-keep-alive" \
11+
CRT_LIST_PATH="" \
12+
DEBUG="false" \
13+
DEFAULT_PORTS="80,443:ssl" \
14+
DEFAULT_REQ_MODE="http" \
15+
DO_NOT_RESOLVE_ADDR="false" \
16+
ENABLE_H2="true" \
17+
FILTER_PROXY_INSTANCE_NAME="false" \
18+
HEALTHCHECK="true" \
19+
HTTPS_ONLY="false" \
20+
EXTRA_FRONTEND="" \
21+
LISTENER_ADDRESS="" \
22+
MODE="default" \
23+
PROXY_INSTANCE_NAME="docker-flow" \
24+
RELOAD_ATTEMPTS="5" \
25+
RELOAD_INTERVAL="5000" REPEAT_RELOAD=false \
26+
RECONFIGURE_ATTEMPTS="20" \
27+
SEPARATOR="," \
28+
SERVICE_NAME="proxy" SERVICE_DOMAIN_ALGO="hdr_beg(host)" \
29+
STATS_USER="" STATS_USER_ENV="STATS_USER" STATS_PASS="" STATS_PASS_ENV="STATS_PASS" STATS_URI="" STATS_URI_ENV="STATS_URI" STATS_PORT="" \
30+
TIMEOUT_HTTP_REQUEST="5" TIMEOUT_HTTP_KEEP_ALIVE="15" TIMEOUT_CLIENT="20" TIMEOUT_CONNECT="5" TIMEOUT_QUEUE="30" TIMEOUT_SERVER="20" TIMEOUT_TUNNEL="3600" \
31+
USERS="" \
32+
SKIP_ADDRESS_VALIDATION="true" \
33+
SSL_BIND_OPTIONS="no-sslv3" SSL_BIND_CIPHERS="ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS"
34+
35+
COPY scripts/check.sh /usr/local/bin/check.sh
36+
RUN chmod +x /usr/local/bin/check.sh
37+
38+
COPY errorfiles /errorfiles
39+
COPY haproxy.cfg /cfg/haproxy.cfg
40+
RUN mkdir -p /cfg/tmpl /templates /certs /logs
41+
COPY haproxy.tmpl /cfg/tmpl/haproxy.tmpl
42+
43+
COPY docker-flow-proxy_linux_arm /usr/local/bin/docker-flow-proxy
44+
RUN chmod +x /usr/local/bin/docker-flow-proxy
45+
46+
HEALTHCHECK --interval=5s --start-period=3s --timeout=5s CMD check.sh
47+
48+
EXPOSE 80
49+
EXPOSE 443
50+
EXPOSE 8080
51+
52+
CMD ["docker-flow-proxy", "server"]

Dockerfile.packetbeat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM vfarcic/docker-flow-proxy
1+
FROM dockerflow/docker-flow-proxy
22

33
ENV PACKETBEAT_CONFIG /packetbeat/packetbeat.yml
44

Dockerfile.test

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
FROM golang:1.8
2-
3-
MAINTAINER Viktor Farcic <viktor@farcic.com>
4-
5-
RUN apt-get update && \
6-
apt-get install -y apt-transport-https ca-certificates curl software-properties-common expect && \
7-
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \
8-
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" && \
9-
apt-get update && \
10-
apt-get -y install docker-ce
1+
FROM dockerflow/docker-flow-proxy-test-base
112

123
COPY . /src
134
WORKDIR /src

Dockerfile.test-base

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM golang:1.8
2+
3+
MAINTAINER Viktor Farcic <viktor@farcic.com>
4+
5+
RUN apt-get update && \
6+
apt-get install -y apt-transport-https ca-certificates curl software-properties-common expect && \
7+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \
8+
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" && \
9+
apt-get update && \
10+
apt-get -y install docker-ce

Jenkinsfile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ pipeline {
1515
def dateFormat = new SimpleDateFormat("yy.MM.dd")
1616
currentBuild.displayName = dateFormat.format(new Date()) + "-" + env.BUILD_NUMBER
1717
}
18-
dfBuild("docker-flow-proxy")
19-
sh "docker image build -t vfarcic/docker-flow-proxy:latest-packet-beat -f Dockerfile.packetbeat ."
20-
sh "docker image tag vfarcic/docker-flow-proxy:latest-packet-beat vfarcic/docker-flow-proxy:${currentBuild.displayName}-packet-beat"
18+
dfBuild2("docker-flow-proxy")
19+
sh "docker image build -t dockerflow/docker-flow-proxy:latest-packet-beat -f Dockerfile.packetbeat ."
20+
sh "docker image tag dockerflow/docker-flow-proxy:latest-packet-beat dockerflow/docker-flow-proxy:${currentBuild.displayName}-packet-beat"
2121
}
2222
}
2323
stage("staging") {
2424
environment {
25-
DOCKER_HUB_USER = "vfarcic"
25+
DOCKER_HUB_USER = "dockerflow"
2626
}
2727
steps {
2828
script {
@@ -37,12 +37,12 @@ pipeline {
3737
branch "master"
3838
}
3939
steps {
40-
dockerLogin()
41-
sh "docker image push vfarcic/docker-flow-proxy:latest-packet-beat"
42-
sh "docker image push vfarcic/docker-flow-proxy:${currentBuild.displayName}-packet-beat"
40+
dfLogin()
41+
sh "docker image push dockerflow/docker-flow-proxy:latest-packet-beat"
42+
sh "docker image push dockerflow/docker-flow-proxy:${currentBuild.displayName}-packet-beat"
4343
dockerLogout()
44-
dfRelease("docker-flow-proxy")
45-
dfReleaseGithub("docker-flow-proxy")
44+
dfRelease2("docker-flow-proxy")
45+
dfReleaseGithub2("docker-flow-proxy")
4646
}
4747
}
4848
stage("deploy") {
@@ -53,7 +53,7 @@ pipeline {
5353
label "prod"
5454
}
5555
steps {
56-
dfDeploy("docker-flow-proxy", "proxy_proxy", "proxy_docs")
56+
dfDeploy2("docker-flow-proxy", "proxy_proxy", "proxy_docs")
5757
}
5858
}
5959
}

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# Docker Flow Proxy
22

3-
[![GitHub release](https://img.shields.io/github/release/vfarcic/docker-flow-proxy.svg)]()
4-
[![license](https://img.shields.io/github/license/vfarcic/docker-flow-proxy.svg)]()
3+
[![GitHub release](https://img.shields.io/github/release/docker-flow/docker-flow-proxy.svg)]()
4+
[![license](https://img.shields.io/github/license/docker-flow/docker-flow-proxy.svg)]()
55
[![Docker Pulls](https://img.shields.io/docker/pulls/vfarcic/docker-flow-proxy.svg)]()
6-
[![Go Report Card](https://goreportcard.com/badge/github.com/vfarcic/docker-flow-proxy)](https://goreportcard.com/report/github.com/vfarcic/docker-flow-proxy)
6+
[![Go Report Card](https://goreportcard.com/badge/github.com/docker-flow/docker-flow-proxy)](https://goreportcard.com/report/github.com/docker-flow/docker-flow-proxy)
77

88
The goal of the *Docker Flow Proxy* project is to provide an easy way to reconfigure proxy every time a new service is deployed, or when a service is scaled. It does not try to "reinvent the wheel", but to leverage the existing leaders and combine them through an easy to use integration. It uses [HAProxy](http://www.haproxy.org/) as a proxy and adds custom logic that allows on-demand reconfiguration.
99

10+
Supported archetectures are:
11+
12+
- linux-amd64
13+
- linux-arm
14+
1015
Please visit the **[project documentation](http://proxy.dockerflow.com)** for more info or join the #df-proxy Slack channel in [DevOps20](http://slack.devops20toolkit.com/) if you have any questions, suggestions, or problems.
1116

1217
<a href='https://ko-fi.com/A655LRB' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://az743702.vo.msecnd.net/cdn/kofi2.png?v=0' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>

actions/fetch.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package actions
22

33
import (
4-
"../proxy"
54
"encoding/json"
65
"fmt"
76
"net/http"
87
"strings"
8+
9+
"../proxy"
910
)
1011

1112
// Fetchable defines interface that fetches information from other sources
@@ -46,6 +47,7 @@ func (m *fetch) ReloadConfig(baseData BaseReconfigure, listenerAddr string) erro
4647
if err = json.NewDecoder(resp.Body).Decode(&services); err != nil {
4748
return err
4849
}
50+
4951
needsReload := false
5052
for _, s := range services {
5153
proxyService := proxy.GetServiceFromMap(&s)

actions/reconfigure.go

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@ import (
77
"os"
88
"strconv"
99
"strings"
10-
"sync"
1110

1211
"../proxy"
1312
)
1413

1514
const serviceTemplateFeFilename = "service-formatted-fe.ctmpl"
1615
const serviceTemplateBeFilename = "service-formatted-be.ctmpl"
1716

18-
var mu = &sync.Mutex{}
19-
2017
// Reconfigurable defines mandatory interface
2118
type Reconfigurable interface {
2219
Execute(reloadAfter bool) error
@@ -47,8 +44,11 @@ var NewReconfigure = func(baseData BaseReconfigure, serviceData proxy.Service) R
4744

4845
// Execute creates a new configuration and reloads the proxy
4946
func (m *Reconfigure) Execute(reloadAfter bool) error {
50-
mu.Lock()
51-
defer mu.Unlock()
47+
if strings.EqualFold(os.Getenv("FILTER_PROXY_INSTANCE_NAME"), "true") &&
48+
!strings.EqualFold(m.InstanceName, m.Service.ProxyInstanceName) {
49+
logPrintf("Filtering %s configuration, with proxyInstanceName: %s", m.ServiceName, m.Service.ProxyInstanceName)
50+
return nil
51+
}
5252
if strings.EqualFold(os.Getenv("SKIP_ADDRESS_VALIDATION"), "false") {
5353
host := m.ServiceName
5454
if len(m.ServiceDest) > 0 && len(m.ServiceDest[0].OutboundHostname) > 0 {
@@ -59,12 +59,9 @@ func (m *Reconfigure) Execute(reloadAfter bool) error {
5959
return err
6060
}
6161
}
62-
if err := m.createConfigs(); err != nil {
62+
if err := m.createConfigsAddService(); err != nil {
6363
return err
6464
}
65-
if !m.hasTemplate() {
66-
proxy.Instance.AddService(m.Service)
67-
}
6865
if reloadAfter {
6966
reload := reload{}
7067
if err := reload.Execute(true); err != nil {
@@ -83,6 +80,19 @@ func (m *Reconfigure) Execute(reloadAfter bool) error {
8380
return nil
8481
}
8582

83+
func (m *Reconfigure) createConfigsAddService() error {
84+
configProxyMu.Lock()
85+
defer configProxyMu.Unlock()
86+
87+
if err := m.createConfigs(); err != nil {
88+
return err
89+
}
90+
if !m.hasTemplate() {
91+
proxy.Instance.AddService(m.Service)
92+
}
93+
return nil
94+
}
95+
8696
// GetData returns structure with reconfiguration data and the service
8797
func (m *Reconfigure) GetData() (BaseReconfigure, proxy.Service) {
8898
return m.BaseReconfigure, m.Service
@@ -94,12 +104,7 @@ func (m *Reconfigure) GetTemplates() (front, back string, err error) {
94104
if value, err := strconv.ParseBool(os.Getenv("CHECK_RESOLVERS")); err == nil {
95105
sr.CheckResolvers = value
96106
}
97-
for i := range sr.ServiceDest {
98-
if len(sr.ServiceDest[i].ReqMode) == 0 {
99-
sr.ServiceDest[i].ReqMode = "http"
100-
}
101-
}
102-
m.formatData(sr)
107+
proxy.FormatServiceForTemplates(sr)
103108
if len(sr.TemplateFePath) > 0 {
104109
feTmpl, err := readTemplateFile(sr.TemplateFePath)
105110
if err != nil {
@@ -137,24 +142,6 @@ func (m *Reconfigure) createConfigs() error {
137142
return nil
138143
}
139144

140-
// TODO: Move to ha_proxy.go
141-
func (m *Reconfigure) formatData(sr *proxy.Service) {
142-
sr.AclCondition = ""
143-
if len(sr.AclName) == 0 {
144-
sr.AclName = sr.ServiceName
145-
}
146-
if len(sr.PathType) == 0 {
147-
sr.PathType = "path_beg"
148-
}
149-
for i, sd := range sr.ServiceDest {
150-
if sd.SrcPort > 0 {
151-
sr.ServiceDest[i].SrcPortAclName = fmt.Sprintf(" srcPort_%s%d", sr.ServiceName, sd.SrcPort)
152-
sr.ServiceDest[i].SrcPortAcl = fmt.Sprintf(`
153-
acl srcPort_%s%d dst_port %d`, sr.ServiceName, sd.SrcPort, sd.SrcPort)
154-
}
155-
}
156-
}
157-
158145
func (m *Reconfigure) getUsersList(sr *proxy.Service) string {
159146
if len(sr.Users) > 0 {
160147
return `userlist {{.ServiceName}}Users{{range .Users}}

0 commit comments

Comments
 (0)