@@ -17,6 +17,7 @@ limitations under the License.
1717package cmd
1818
1919import (
20+ "fmt"
2021 "gatehill.io/imposter/engine"
2122 "gatehill.io/imposter/engine/docker"
2223 "github.com/sirupsen/logrus"
@@ -32,6 +33,8 @@ import (
3233 "syscall"
3334)
3435
36+ var flagPort int
37+
3538// mockCmd represents the mock command
3639var mockCmd = & cobra.Command {
3740 Use : "mock OPENDEPS_FILE" ,
@@ -58,11 +61,12 @@ by this tool.`,
5861 openapi .BundleSpecs (stagingDir , manifestPath , manifest , flagForceOverwrite )
5962
6063 mockEngine := docker .BuildEngine (stagingDir , engine.StartOptions {
61- Port : 8080 ,
64+ Port : flagPort ,
6265 Version : "latest" ,
6366 PullPolicy : engine .PullIfNotPresent ,
6467 LogLevel : "DEBUG" ,
6568 ReplaceRunning : true ,
69+ Deduplicate : genDeduplicationKey (manifestPath , flagPort ),
6670 })
6771 wg := & sync.WaitGroup {}
6872 mockEngine .Start (wg )
@@ -72,7 +76,14 @@ by this tool.`,
7276 },
7377}
7478
79+ // genDeduplicationKey overrides the default deduplication key to a
80+ // stable value, since the staging dir is dynamic
81+ func genDeduplicationKey (manifestPath string , port int ) string {
82+ return fmt .Sprintf ("%v:%d" , manifestPath , port )
83+ }
84+
7585func init () {
86+ mockCmd .Flags ().IntVarP (& flagPort , "port" , "p" , 8080 , "Port on which to listen" )
7687 rootCmd .AddCommand (mockCmd )
7788}
7889
0 commit comments