Skip to content

Commit

Permalink
Consul sunset (#294)
Browse files Browse the repository at this point in the history
* Consul sunset

* Consul sunset

* Consul sunset

* Consul sunset

* Disabled integration tests until Docker for AWS is fixed
  • Loading branch information
vfarcic authored Jul 22, 2017
1 parent 6d185e1 commit 0c9f190
Show file tree
Hide file tree
Showing 27 changed files with 162 additions and 2,103 deletions.
8 changes: 0 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ RUN go build -v -o docker-flow-proxy
FROM haproxy:1.7-alpine
MAINTAINER Viktor Farcic <viktor@farcic.com>

RUN apk add --no-cache --virtual .build-deps curl unzip && \
curl -SL https://releases.hashicorp.com/consul-template/0.13.0/consul-template_0.13.0_linux_amd64.zip -o /usr/local/bin/consul-template.zip && \
unzip /usr/local/bin/consul-template.zip -d /usr/local/bin/ && \
rm -f /usr/local/bin/consul-template.zip && \
chmod +x /usr/local/bin/consul-template && \
apk del .build-deps

RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
RUN mkdir -p /cfg/tmpl /consul_templates /templates /certs /logs

Expand All @@ -25,7 +18,6 @@ ENV CERTS="" \
CFG_TEMPLATE_PATH="/cfg/tmpl/haproxy.tmpl" \
CHECK_RESOLVERS=false \
CONNECTION_MODE="http-keep-alive" \
CONSUL_ADDRESS="" \
DEBUG="false" \
DEFAULT_PORTS="80,443:ssl" \
EXTRA_FRONTEND="" \
Expand Down
24 changes: 12 additions & 12 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ pipeline {
sh "docker image build -t vfarcic/docker-flow-proxy-docs -f Dockerfile.docs ."
}
}
stage("test") {
environment {
HOST_IP = "build.dockerflow.com"
DOCKER_HUB_USER = "vfarcic"
}
steps {
sh "docker-compose -f docker-compose-test.yml run --rm staging-swarm"
}
}
// stage("test") {
// environment {
// HOST_IP = "build.dockerflow.com"
// DOCKER_HUB_USER = "vfarcic"
// }
// steps {
// sh "docker-compose -f docker-compose-test.yml run --rm staging-swarm"
// }
// }
stage("release") {
when {
branch "master"
Expand Down Expand Up @@ -67,9 +67,9 @@ pipeline {
}
}
post {
always {
sh "docker system prune -f"
}
// always {
// sh "docker system prune -f"
// }
failure {
slackSend(
color: "danger",
Expand Down
66 changes: 0 additions & 66 deletions Vagrantfile

This file was deleted.

103 changes: 5 additions & 98 deletions actions/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,33 @@ package actions

import (
"../proxy"
"../registry"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
)

// Fetchable defines interface that fetches information from other sources
type Fetchable interface {
// TODO: It's deprecated (Consul). Remove it.
ReloadServicesFromRegistry(addresses []string, instanceName, mode string) error
// Sends request to swarm-listener to request reconfiguration of all proxy instances in Swarm.
ReloadClusterConfig(listenerAddr string) error
// Reconfigures this instance of proxy based on configuration taken from swarm-listener.
// This is synchronous.
// If listenerAddr is nil, unreachable or any other problem error is returned.
ReloadConfig(baseData BaseReconfigure, mode string, listenerAddr string) error
ReloadConfig(baseData BaseReconfigure, listenerAddr string) error
}
type fetch struct {
BaseReconfigure
Mode string `short:"m" long:"mode" env:"MODE" description:"If set to 'swarm', proxy will operate assuming that Docker service from v1.12+ is used."`
}

// NewFetch returns instance of the Fetchable object
var NewFetch = func(baseData BaseReconfigure, mode string) Fetchable {
var NewFetch = func(baseData BaseReconfigure) Fetchable {
return &fetch{
BaseReconfigure: baseData,
Mode: mode,
}
}

// TODO: It's deprecated (Consul). Remove it.
func (m *fetch) ReloadServicesFromRegistry(addresses []string, instanceName, mode string) error {
if len(addresses) > 0 {
return m.reloadFromRegistry(addresses, instanceName, mode)
}
return nil
}

// ReloadConfig recreates proxy configuration with data fetches from Swarm Listener
func (m *fetch) ReloadConfig(baseData BaseReconfigure, mode string, listenerAddr string) error {
func (m *fetch) ReloadConfig(baseData BaseReconfigure, listenerAddr string) error {
if len(listenerAddr) == 0 {
return fmt.Errorf("Swarm Listener address is missing %s", listenerAddr)
}
Expand All @@ -64,7 +49,7 @@ func (m *fetch) ReloadConfig(baseData BaseReconfigure, mode string, listenerAddr
for _, s := range services {
proxyService := proxy.GetServiceFromMap(&s)
if statusCode, _ := proxy.IsValidReconf(proxyService); statusCode == http.StatusOK {
reconfigure := NewReconfigure(baseData, *proxyService, mode)
reconfigure := NewReconfigure(baseData, *proxyService)
reconfigure.Execute(false)
needsReload = true
}
Expand All @@ -91,88 +76,10 @@ func (m *fetch) ReloadClusterConfig(listenerAddr string) error {
}

func (m *fetch) getReconfigure(service *proxy.Service) Reconfigurable {
return NewReconfigure(m.BaseReconfigure, *service, m.Mode)
return NewReconfigure(m.BaseReconfigure, *service)
}

func (m *fetch) getReload() Reloader {
return NewReload()
}

// TODO: It's deprecated (Consul). Remove it.
func (m *fetch) reloadFromRegistry(addresses []string, instanceName, mode string) error {
var resp *http.Response
var err error
logPrintf("Configuring existing services")
found := false
for _, address := range addresses {
address = strings.ToLower(address)
if !strings.HasPrefix(address, "http") {
address = fmt.Sprintf("http://%s", address)
}
servicesUrl := fmt.Sprintf("%s/v1/catalog/services", address)
resp, err = http.Get(servicesUrl)
if err == nil {
found = true
break
}
}
if !found {
return fmt.Errorf("Could not retrieve the list of services from Consul")
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
c := make(chan proxy.Service)
count := 0
var data map[string]interface{}
json.Unmarshal(body, &data)
count = len(data)
for key := range data {
go m.getService(addresses, key, instanceName, c)
}
logPrintf("\tFound %d services", count)
for i := 0; i < count; i++ {
s := <-c
if len(s.ServiceDest) > 0 && len(s.ServiceDest[0].ServicePath) > 0 {
reconfigure := m.getReconfigure(&s)
reconfigure.Execute(false)
}
}
reload := m.getReload()
return reload.Execute(true)
}

// TODO: It's deprecated (Consul). Remove it.
func (m *fetch) getService(addresses []string, serviceName, instanceName string, c chan proxy.Service) {
sr := proxy.Service{ServiceName: serviceName}

path, err := registryInstance.GetServiceAttribute(addresses, serviceName, registry.PATH_KEY, instanceName)
port, _ := m.getServiceAttribute(addresses, serviceName, registry.PORT, instanceName)
sd := proxy.ServiceDest{
ServicePath: strings.Split(path, ","),
Port: port,
}
if err == nil {
sr.ServiceDest = []proxy.ServiceDest{sd}
sr.ServiceColor, _ = m.getServiceAttribute(addresses, serviceName, registry.COLOR_KEY, instanceName)
sr.ServiceCert, _ = m.getServiceAttribute(addresses, serviceName, registry.CERT_KEY, instanceName)
sr.OutboundHostname, _ = m.getServiceAttribute(addresses, serviceName, registry.HOSTNAME_KEY, instanceName)
sr.PathType, _ = m.getServiceAttribute(addresses, serviceName, registry.PATH_TYPE_KEY, instanceName)
sr.ConsulTemplateFePath, _ = m.getServiceAttribute(addresses, serviceName, registry.CONSUL_TEMPLATE_FE_PATH_KEY, instanceName)
sr.ConsulTemplateBePath, _ = m.getServiceAttribute(addresses, serviceName, registry.CONSUL_TEMPLATE_BE_PATH_KEY, instanceName)
}
c <- sr
}

// TODO: It's deprecated (Consul). Remove it.
func (m *fetch) getServiceAttribute(addresses []string, serviceName, key, instanceName string) (string, bool) {
for _, address := range addresses {
url := fmt.Sprintf("%s/v1/kv/%s/%s/%s?raw", address, instanceName, serviceName, key)
resp, err := http.Get(url)
if err == nil && resp.StatusCode == http.StatusOK {
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
return string(body), true
}
}
return "", false
}
Loading

0 comments on commit 0c9f190

Please sign in to comment.