fix dial errors (I fucking did it)
This commit is contained in:
@@ -371,7 +371,7 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("DELETE", config.DeamonURL+"/deploy/"+projectName, nil)
|
||||
req, err := http.NewRequest("DELETE", config.DeamonURL+"/deployments/"+projectName, nil)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to delete app: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -80,6 +80,7 @@ func CreateDockerContainer(ctx context.Context, imageName, projectPath string, p
|
||||
},
|
||||
},
|
||||
&container.HostConfig{
|
||||
RestartPolicy: container.RestartPolicy{Name: container.RestartPolicyUnlessStopped},
|
||||
NetworkMode: "bridge",
|
||||
Mounts: []mount.Mount{
|
||||
{
|
||||
|
||||
@@ -140,6 +140,22 @@ func (s *FluxServer) DeployHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var headContainer *Container
|
||||
for _, container := range deployment.Containers {
|
||||
if container.Head {
|
||||
headContainer = &container
|
||||
}
|
||||
}
|
||||
|
||||
deployment.Proxy, err = NewDeploymentProxy(&deployment, headContainer)
|
||||
if err != nil {
|
||||
log.Printf("Failed to create deployment proxy: %v\n", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
ReverseProxy.AddDeployment(&deployment)
|
||||
|
||||
Apps.AddApp(app.Name, app)
|
||||
} else {
|
||||
log.Printf("Upgrading deployment %s...\n", app.Name)
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/juls0730/fluxd/pkg"
|
||||
)
|
||||
@@ -114,12 +113,12 @@ func (am *AppManager) Init() {
|
||||
deployment.Containers = append(deployment.Containers, container)
|
||||
}
|
||||
|
||||
deployment.Proxy = &DeploymentProxy{
|
||||
deployment: &deployment,
|
||||
currentHead: headContainer,
|
||||
gracePeriod: time.Second * 30,
|
||||
activeRequests: 0,
|
||||
deployment.Proxy, err = NewDeploymentProxy(&deployment, headContainer)
|
||||
if err != nil {
|
||||
log.Printf("Failed to create deployment proxy: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
app.Deployment = deployment
|
||||
|
||||
Apps.AddApp(app.Name, &app)
|
||||
@@ -162,16 +161,8 @@ func CreateDeployment(containerID string, port uint16, appUrl string, db *sql.DB
|
||||
}
|
||||
copy(container.ContainerID[:], containerIDString)
|
||||
|
||||
deployment.Proxy = &DeploymentProxy{
|
||||
deployment: &deployment,
|
||||
currentHead: &container,
|
||||
gracePeriod: time.Second * 30,
|
||||
activeRequests: 0,
|
||||
}
|
||||
|
||||
container.Deployment = &deployment
|
||||
deployment.Containers = append(deployment.Containers, container)
|
||||
ReverseProxy.AddDeployment(&deployment)
|
||||
|
||||
return deployment, nil
|
||||
}
|
||||
@@ -252,11 +243,10 @@ func (deployment *Deployment) Upgrade(ctx context.Context, projectConfig pkg.Pro
|
||||
|
||||
// Create a new proxy that points to the new head, and replace the old one, but ensure that the old one is gracefully shutdown
|
||||
oldProxy := deployment.Proxy
|
||||
deployment.Proxy = &DeploymentProxy{
|
||||
deployment: deployment,
|
||||
currentHead: &container,
|
||||
gracePeriod: time.Second * 30,
|
||||
activeRequests: 0,
|
||||
deployment.Proxy, err = NewDeploymentProxy(deployment, &container)
|
||||
if err != nil {
|
||||
log.Printf("Failed to create deployment proxy: %v\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
var containers []Container
|
||||
|
||||
@@ -35,22 +35,30 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
atomic.AddInt64(&deployment.(*Deployment).Proxy.activeRequests, 1)
|
||||
|
||||
container := deployment.(*Deployment).Proxy.currentHead
|
||||
if container == nil {
|
||||
http.Error(w, "No active container found", http.StatusNotFound)
|
||||
return
|
||||
deployment.(*Deployment).Proxy.proxy.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
containerJSON, err := dockerClient.ContainerInspect(context.Background(), string(container.ContainerID[:]))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
type DeploymentProxy struct {
|
||||
deployment *Deployment
|
||||
currentHead *Container
|
||||
proxy *httputil.ReverseProxy
|
||||
gracePeriod time.Duration
|
||||
activeRequests int64
|
||||
}
|
||||
|
||||
containerUrl, err := url.Parse(fmt.Sprintf("http://%s:%d", containerJSON.NetworkSettings.IPAddress, container.Deployment.Port))
|
||||
func NewDeploymentProxy(deployment *Deployment, head *Container) (*DeploymentProxy, error) {
|
||||
containerJSON, err := dockerClient.ContainerInspect(context.Background(), string(head.ContainerID[:]))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if containerJSON.NetworkSettings.IPAddress == "" {
|
||||
return nil, fmt.Errorf("No IP address found for container %s", head.ContainerID[0:12])
|
||||
}
|
||||
|
||||
containerUrl, err := url.Parse(fmt.Sprintf("http://%s:%d", containerJSON.NetworkSettings.IPAddress, deployment.Port))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proxy := &httputil.ReverseProxy{
|
||||
@@ -58,20 +66,24 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
req.URL = containerUrl
|
||||
req.Host = containerUrl.Host
|
||||
},
|
||||
Transport: &http.Transport{
|
||||
MaxIdleConns: 100,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
MaxIdleConnsPerHost: 100,
|
||||
},
|
||||
ModifyResponse: func(resp *http.Response) error {
|
||||
atomic.AddInt64(&deployment.(*Deployment).Proxy.activeRequests, -1)
|
||||
atomic.AddInt64(&deployment.Proxy.activeRequests, -1)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
proxy.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
type DeploymentProxy struct {
|
||||
deployment *Deployment
|
||||
currentHead *Container
|
||||
gracePeriod time.Duration
|
||||
activeRequests int64
|
||||
return &DeploymentProxy{
|
||||
deployment: deployment,
|
||||
currentHead: head,
|
||||
proxy: proxy,
|
||||
gracePeriod: time.Second * 30,
|
||||
activeRequests: 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (dp *DeploymentProxy) GracefulShutdown(oldContainers []*Container) {
|
||||
|
||||
Reference in New Issue
Block a user