Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Options:

Commands:
generate Converts a source markdown folder or file to an output folder
serve Continuously serve a documentation folder at http://localhost:5000.
serve Continuously serve a documentation folder at http://localhost:3000.
File systems changes will be reflected without having to restart the server.
```

Expand Down
10 changes: 5 additions & 5 deletions docs/source/contribute/locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Follow these steps to contribute to Elastic docs.
```

3. **Run the Binary:**
Use the `serve` command to start serving the documentation at http://localhost:5000. The path to the docset.yml file that you want to build can be specified with `-p`:
Use the `serve` command to start serving the documentation at http://localhost:3000. The path to the docset.yml file that you want to build can be specified with `-p`:
```sh
./docs-builder serve -p ./path/to/docs
```
Expand All @@ -53,7 +53,7 @@ Follow these steps to contribute to Elastic docs.
```

3. **Run the Binary:**
Use the `serve` command to start serving the documentation at http://localhost:5000. The path to the docset.yml file that you want to build can be specified with `-p`:
Use the `serve` command to start serving the documentation at http://localhost:3000. The path to the docset.yml file that you want to build can be specified with `-p`:
```sh
.\docs-builder serve -p ./path/to/docs
```
Expand All @@ -77,7 +77,7 @@ Follow these steps to contribute to Elastic docs.
```

3. **Run the Binary:**
Use the `serve` command to start serving the documentation at http://localhost:5000. The path to the docset.yml file that you want to build can be specified with `-p`:
Use the `serve` command to start serving the documentation at http://localhost:3000. The path to the docset.yml file that you want to build can be specified with `-p`:
```sh
./docs-builder serve -p ./path/to/docs
```
Expand All @@ -101,7 +101,7 @@ git clone https://github.com/elastic/docs-content.git
```

2. **Run the Binary:**
Use the `serve` command to start serving the documentation at http://localhost:5000. The path to the `docset.yml` file that you want to build can be specified with `-p`:
Use the `serve` command to start serving the documentation at http://localhost:3000. The path to the `docset.yml` file that you want to build can be specified with `-p`:
```sh
# macOS/Linux
./docs-builder serve -p ./migration-test
Expand All @@ -110,7 +110,7 @@ git clone https://github.com/elastic/docs-content.git
.\docs-builder serve -p .\migration-test
```

Now you should be able to view the documentation locally by navigating to http://localhost:5000.
Now you should be able to view the documentation locally by navigating to http://localhost:3000.

## Step 4: Open a PR [#step-four]

Expand Down
8 changes: 4 additions & 4 deletions src/docs-builder/Cli/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ namespace Documentation.Builder.Cli;
internal class Commands(ILoggerFactory logger, ICoreService githubActionsService)
{
/// <summary>
/// Continuously serve a documentation folder at http://localhost:5000.
/// Continuously serve a documentation folder at http://localhost:3000.
/// File systems changes will be reflected without having to restart the server.
/// </summary>
/// <param name="path">-p, Path to serve the documentation.
/// Defaults to the`{pwd}/docs` folder
/// </param>
/// <param name="port">Port to serve the documentation.</param>
/// <param name="ctx"></param>
[Command("serve")]
public async Task Serve(string? path = null, Cancel ctx = default)
public async Task Serve(string? path = null, int port = 3000, Cancel ctx = default)
{
var host = new DocumentationWebHost(path, logger, new FileSystem());
var host = new DocumentationWebHost(path, port, logger, new FileSystem());
await host.RunAsync(ctx);
await host.StopAsync(ctx);

}

/// <summary>
Expand Down
9 changes: 8 additions & 1 deletion src/docs-builder/Http/DocumentationWebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Elastic.Markdown.Diagnostics;
using Elastic.Markdown.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
Expand All @@ -28,7 +29,7 @@ public class DocumentationWebHost

private readonly BuildContext _context;

public DocumentationWebHost(string? path, ILoggerFactory logger, IFileSystem fileSystem)
public DocumentationWebHost(string? path, int port, ILoggerFactory logger, IFileSystem fileSystem)
{
var builder = WebApplication.CreateSlimBuilder();

Expand All @@ -54,6 +55,12 @@ public DocumentationWebHost(string? path, ILoggerFactory logger, IFileSystem fil

//builder.Services.AddSingleton(logger);

// See https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#dotnet_running_in_container-and-dotnet_running_in_containers
// This way use the default port when running in a container
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER")) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking one will suffice 😸 both will be set (don't ask my why!).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay 😅

c9b04bb

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm starting to wonder.

IIUC, the main reason for the differing ports for the native binary and the docker image are dotnet defaults.

Would it be a better UX if both use the same port?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://learn.microsoft.com/en-us/dotnet/core/compatibility/containers/8.0/aspnet-port has some background as to why its 8080.

In .net the default changes based on environments: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-9.0

Which is not something we leverage. Docker is a prod environments hence the different port as the rest of the run environments which are dev by default..

It makes sense to normalize this to one non privileged port and forego the docker env check to keep it simple.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand correctly? We skip the environment check and always do UseUrls?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes thats the less long winded conclusion 😸

We'll have to update https://github.com/elastic/docs-builder-example or maybe we should archive that repository now that we have the migration repositories.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINERS")))
builder.WebHost.UseUrls($"http://localhost:{port}");

_webApplication = builder.Build();
SetUpRoutes();
}
Expand Down
Loading