Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,28 @@ A simple way to generate and manage local certificates is using `mkcert`, as it

To generate a certificate pair for use with HAProxy, you typically use the default domain `*.docker.amazee.io`, but you can substitute any domain as needed for your local development environment:

1. **Install mkcert**
Follow instructions at [mkcert GitHub](https://github.com/FiloSottile/mkcert).
Example for macOS:
### 1. Install mkcert and nss

**Linux**:

Follow instructions at [mkcert GitHub](https://github.com/FiloSottile/mkcert) and [nss GitHub](https://github.com/nss-dev/nss).

**macOS**:
```shell
brew install mkcert
brew install mkcert nss
mkcert -install # generates and installs the local CA
```

2. **Generate a wildcard certificate and key**
Run:
### 2. Generate a wildcard certificate and key

Run:
```shell
mkcert "*.docker.amazee.io"
```
This creates `_wildcard.docker.amazee.io.pem` (certificate) and `_wildcard.docker.amazee.io-key.pem` (private key).

3. **Combine certificate and key for HAProxy**
### 3. Combine certificate and key for HAProxy

Run:
```shell
mkdir -p ~/pygmy/
Expand All @@ -175,7 +181,7 @@ To generate a certificate pair for use with HAProxy, you typically use the defau
```
pygmy up --tls-cert=/location_to/haproxy.pem
```
or can be stored in the default location of `~/pygmy/server.pem`.
or can be stored in the default location of `~/pygmy/server.pem` - which will attempt to load every time pygmy is started.


**Notes:**
Expand Down
4 changes: 2 additions & 2 deletions external/docker/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func Setup(ctx context.Context, cli *client.Client, c *Config) {
ImportDefaults(ctx, cli, c, "amazeeio-ssh-agent", agent.New())
ImportDefaults(ctx, cli, c, "amazeeio-ssh-agent-add-key", key.NewAdder())
ImportDefaults(ctx, cli, c, "amazeeio-dnsmasq", dnsmasq.New(&dockerruntime.Params{Domain: c.Domain}))
ImportDefaults(ctx, cli, c, "amazeeio-haproxy", haproxy.New(&dockerruntime.Params{Domain: c.Domain}, c.TLSCertPath))
ImportDefaults(ctx, cli, c, "amazeeio-mailhog", mailhog.New(&dockerruntime.Params{Domain: c.Domain}))
ImportDefaults(ctx, cli, c, "amazeeio-haproxy", haproxy.New(&dockerruntime.Params{Domain: c.Domain, TLSCertPath: c.TLSCertPath}))
ImportDefaults(ctx, cli, c, "amazeeio-mailhog", mailhog.New(&dockerruntime.Params{Domain: c.Domain, TLSCertPath: c.TLSCertPath}))

// Disable Resolvers if needed.
if c.ResolversDisabled {
Expand Down
2 changes: 2 additions & 0 deletions internal/runtime/docker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ type Service struct {
type Params struct {
// Domain is the target domain for Pygmy to use.
Domain string
// TLSCertPath is the TLS Certificate Path.
TLSCertPath string
}
9 changes: 5 additions & 4 deletions internal/service/docker/haproxy/haproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
)

// New will provide the standard object for the haproxy container.
func New(c *docker.Params, tlsCertPath string) docker.Service {
func New(c *docker.Params) docker.Service {
binds := []string{"/var/run/docker.sock:/tmp/docker.sock"}
if tlsCertPath != "" {
binds = append(binds, fmt.Sprintf("%s:/app/server.pem:ro", tlsCertPath))
if c.TLSCertPath != "" {
binds = append(binds, fmt.Sprintf("%s:/app/server.pem:ro", c.TLSCertPath))
}
return docker.Service{
Config: container.Config{
Expand All @@ -28,7 +28,8 @@ func New(c *docker.Params, tlsCertPath string) docker.Service {
"pygmy.weight": "14",
},
Env: []string{
fmt.Sprintf("AMAZEEIO_URL=%s", c.Domain),
"LAGOON_ROUTE=http://docker.amazee.io/stats",
fmt.Sprintf("AMAZEEIO_URL=http://%s", c.Domain),
},
},
HostConfig: container.HostConfig{
Expand Down
4 changes: 2 additions & 2 deletions internal/service/docker/haproxy/haproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
)

func Example() {
haproxy.New(&docker.Params{}, "")
haproxy.New(&docker.Params{})
haproxy.NewDefaultPorts()
}

func Test(t *testing.T) {
Convey("HAProxy: Field equality tests...", t, func() {
obj := haproxy.New(&docker.Params{Domain: "docker.amazee.io"}, "/path/to/ssl/cert.pem")
obj := haproxy.New(&docker.Params{Domain: "docker.amazee.io", TLSCertPath: "/path/to/ssl/cert.pem"})
objPorts := haproxy.NewDefaultPorts()
So(obj.Config.Image, ShouldContainSubstring, "pygmystack/haproxy")
So(obj.Config.Labels["pygmy.defaults"], ShouldEqual, "true")
Expand Down
12 changes: 10 additions & 2 deletions internal/service/docker/mailhog/mailhog.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// New will provide the standard object for the mailhog container.
func New(c *docker.Params) docker.Service {
return docker.Service{
serviceSpec := docker.Service{
Config: container.Config{
User: "0",
ExposedPorts: nat.PortSet{
Expand All @@ -34,7 +34,6 @@ func New(c *docker.Params) docker.Service {
"pygmy.enable": "true",
"pygmy.name": "amazeeio-mailhog",
"pygmy.network": "amazeeio-network",
"pygmy.url": fmt.Sprintf("http://mailhog.%s", c.Domain),
"pygmy.weight": "15",
},
},
Expand All @@ -48,6 +47,15 @@ func New(c *docker.Params) docker.Service {
NetworkConfig: network.NetworkingConfig{},
}

if c.TLSCertPath != "" {
serviceSpec.Config.Env = append(serviceSpec.Config.Env, "LAGOON_ROUTE=https://mailhog.docker.amazee.io")
serviceSpec.Config.Labels["pygmy.url"] = fmt.Sprintf("https://mailhog.%s", c.Domain)
} else {
serviceSpec.Config.Env = append(serviceSpec.Config.Env, "LAGOON_ROUTE=http://mailhog.docker.amazee.io")
serviceSpec.Config.Labels["pygmy.url"] = fmt.Sprintf("http://mailhog.%s", c.Domain)
}

return serviceSpec
}

// NewDefaultPorts will provide the standard ports used for merging into the
Expand Down
4 changes: 2 additions & 2 deletions internal/service/docker/mailhog/mailhog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func Example() {

func Test(t *testing.T) {
Convey("MailHog: Field equality tests...", t, func() {
obj := mailhog.New(&docker.Params{Domain: "docker.amazee.io"})
obj := mailhog.New(&docker.Params{Domain: "docker.amazee.io", TLSCertPath: ""})
objPorts := mailhog.NewDefaultPorts()
So(obj.Config.User, ShouldEqual, "0")
So(obj.Config.Image, ShouldContainSubstring, "pygmystack/mailhog")
So(fmt.Sprint(obj.Config.ExposedPorts), ShouldEqual, fmt.Sprint(nat.PortSet{"80/tcp": struct{}{}, "1025/tcp": struct{}{}, "8025/tcp": struct{}{}}))
So(fmt.Sprint(obj.Config.Env), ShouldEqual, fmt.Sprint([]string{"MH_UI_BIND_ADDR=0.0.0.0:80", "MH_API_BIND_ADDR=0.0.0.0:80", "AMAZEEIO=AMAZEEIO", "AMAZEEIO_URL=mailhog.docker.amazee.io"}))
So(fmt.Sprint(obj.Config.Env), ShouldEqual, fmt.Sprint([]string{"MH_UI_BIND_ADDR=0.0.0.0:80", "MH_API_BIND_ADDR=0.0.0.0:80", "AMAZEEIO=AMAZEEIO", "AMAZEEIO_URL=mailhog.docker.amazee.io", "LAGOON_ROUTE=http://mailhog.docker.amazee.io"}))
So(obj.Config.Labels["pygmy.defaults"], ShouldEqual, "true")
So(obj.Config.Labels["pygmy.enable"], ShouldEqual, "true")
So(obj.Config.Labels["pygmy.name"], ShouldEqual, "amazeeio-mailhog")
Expand Down
10 changes: 9 additions & 1 deletion internal/utils/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"crypto/tls"
"net/http"
"strings"
"time"
)

Expand All @@ -19,13 +20,20 @@ func Validate(url string) bool {
defer cancel()

client := &http.Client{
Timeout: 5 * time.Second,
Timeout: 2 * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DisableKeepAlives: true,
},
}

if strings.HasPrefix(url, "https://") {
client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: false},
DisableKeepAlives: true,
}
}

// Create a web request using HEAD for faster response
req, err := http.NewRequestWithContext(ctx, "HEAD", url, nil)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main_test

import (
"fmt"
"github.com/pygmystack/pygmy/internal/runtime/docker/internals"
"os"
"testing"
"time"
Expand All @@ -11,6 +10,7 @@ import (
"github.com/docker/docker/api/types/network"
. "github.com/smartystreets/goconvey/convey"

"github.com/pygmystack/pygmy/internal/runtime/docker/internals"
"github.com/pygmystack/pygmy/internal/runtime/docker/internals/containers"
"github.com/pygmystack/pygmy/internal/runtime/docker/internals/images"
)
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestDefault(t *testing.T) {
configuration := &config{
name: "default",
configpath: "/examples/pygmy.basic.yml",
endpoints: []string{"http://docker.amazee.io/stats", "http://mailhog.docker.amazee.io"},
endpoints: []string{"docker.amazee.io/stats", "mailhog.docker.amazee.io"},
images: []string{"pygmystack/haproxy", "pygmystack/dnsmasq", "pygmystack/mailhog"},
services: []string{"amazeeio-haproxy", "amazeeio-dnsmasq", "amazeeio-mailhog"},
servicewithports: []string{"amazeeio-haproxy", "amazeeio-mailhog"},
Expand All @@ -208,7 +208,7 @@ func TestCustom(t *testing.T) {
configuration := &config{
name: "custom",
configpath: "/examples/pygmy.complex.yml",
endpoints: []string{"http://traefik.docker.amazee.io", "http://mailhog.docker.amazee.io", "http://phpmyadmin.docker.amazee.io"},
endpoints: []string{"traefik.docker.amazee.io", "mailhog.docker.amazee.io", "http://phpmyadmin.docker.amazee.io"},
images: []string{"pygmystack/ssh-agent", "pygmystack/mailhog", "phpmyadmin/phpmyadmin", "library/traefik:v2.1.3"},
services: []string{"unofficial-traefik-2", "unofficial-phpmyadmin", "amazeeio-mailhog"},
servicewithports: []string{"amazeeio-mailhog", "unofficial-phpmyadmin", "unofficial-traefik-2"},
Expand Down
Loading