Hello people!
I'm learning Dagger by using it in a little project and my first case is to test my application on my computer before the next steps (remotly deploying it on development environment).
I use the GO SDK to develop a REST API and Dagger engine run on my computer.
I'm trying to build and run my Go application on port 8080 to query it from the host machine of the Dagger container (localhost). Currently I have this code blocks in main.go:
func (m *MyAPI) Run(ctx context.Context, source *dagger.Directory, user *dagger.Secret, password *dagger.Secret) *dagger.Service {
//var exposedPort = dagger.PortForward{Frontend: 8080, Backend: 8080}
return m.GetAPIService(ctx, source, user, password)
}
func (m *MyAPI) GetAPIService(ctx context.Context, source *dagger.Directory, user *dagger.Secret, password *dagger.Secret) *dagger.Service {
database := m.createDatabaseContainer(user, password)
m.Migrate(ctx, source, database.Service(), user, password)
return m.Build(ctx, source, "./cmd/summarizer", "summarizer").
WithServiceBinding("db", database.Service()).
WithSecretVariable("MYAPI_DATABASE_USERNAME", user).
WithSecretVariable("MYAPI_DATABASE_PASSWORD", password).
WithExposedPort(8080, dagger.ContainerWithExposedPortOpts{Protocol: dagger.NetworkProtocolTcp, Description: "API HTTP listener"}).
WithExec([]string{
"./myapi",
"serve",
"api",
"--dbname",
"myapi",
"--host",
"db",
"--port",
"5432",
}).AsService(dagger.ContainerAsServiceOpts{})
}
I run the Dagger function with the following parameters:
dagger call run --source=. --user=env://PG_USER --password=env://PG_PASSWORD up --ports 8080:8080
But the port 8080 is still closed from the localhost.