Add TCP/UDP port mapping support
- Add app_ports table for storing port mappings per app - Add Port model with CRUD operations - Add handlers for adding/deleting port mappings - Add ports section to app detail template - Update Docker client to configure port bindings when creating containers - Support both TCP and UDP protocols
This commit is contained in:
@@ -339,6 +339,11 @@ func (svc *Service) buildContainerOptions(
|
||||
return docker.CreateContainerOptions{}, fmt.Errorf("failed to get volumes: %w", err)
|
||||
}
|
||||
|
||||
ports, err := app.GetPorts(ctx)
|
||||
if err != nil {
|
||||
return docker.CreateContainerOptions{}, fmt.Errorf("failed to get ports: %w", err)
|
||||
}
|
||||
|
||||
envMap := make(map[string]string, len(envVars))
|
||||
for _, envVar := range envVars {
|
||||
envMap[envVar.Key] = envVar.Value
|
||||
@@ -355,6 +360,7 @@ func (svc *Service) buildContainerOptions(
|
||||
Env: envMap,
|
||||
Labels: buildLabelMap(app, labels),
|
||||
Volumes: buildVolumeMounts(volumes),
|
||||
Ports: buildPortMappings(ports),
|
||||
Network: network,
|
||||
}, nil
|
||||
}
|
||||
@@ -384,6 +390,19 @@ func buildVolumeMounts(volumes []*models.Volume) []docker.VolumeMount {
|
||||
return mounts
|
||||
}
|
||||
|
||||
func buildPortMappings(ports []*models.Port) []docker.PortMapping {
|
||||
mappings := make([]docker.PortMapping, 0, len(ports))
|
||||
for _, port := range ports {
|
||||
mappings = append(mappings, docker.PortMapping{
|
||||
HostPort: port.HostPort,
|
||||
ContainerPort: port.ContainerPort,
|
||||
Protocol: string(port.Protocol),
|
||||
})
|
||||
}
|
||||
|
||||
return mappings
|
||||
}
|
||||
|
||||
func (svc *Service) updateAppRunning(
|
||||
ctx context.Context,
|
||||
app *models.App,
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -100,6 +101,7 @@ func createTestApp(
|
||||
return app
|
||||
}
|
||||
|
||||
//nolint:funlen // table-driven test with comprehensive test cases
|
||||
func TestExtractBranch(testingT *testing.T) {
|
||||
testingT.Parallel()
|
||||
|
||||
@@ -156,6 +158,9 @@ func TestExtractBranch(testingT *testing.T) {
|
||||
err := svc.HandleWebhook(context.Background(), app, "push", payload)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Allow async deployment goroutine to complete before test cleanup
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
events, err := app.GetWebhookEvents(context.Background(), 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, events, 1)
|
||||
@@ -190,6 +195,9 @@ func TestHandleWebhookMatchingBranch(t *testing.T) {
|
||||
err := svc.HandleWebhook(context.Background(), app, "push", payload)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Allow async deployment goroutine to complete before test cleanup
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
events, err := app.GetWebhookEvents(context.Background(), 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, events, 1)
|
||||
|
||||
Reference in New Issue
Block a user