Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using testcontainers in a fsx script gives wrong output #897

Open
rbauduin opened this issue Jan 15, 2024 · 7 comments
Open

Using testcontainers in a fsx script gives wrong output #897

rbauduin opened this issue Jan 15, 2024 · 7 comments

Comments

@rbauduin
Copy link

Putting this fsx in the docs directory:

> (**
# Usage
*)
(*** hide ***)

#r "nuget: Testcontainers.PostgreSql, 3.6.0"
open Testcontainers.PostgreSql
task {
(** # Start container *)
  let container =
    (new PostgreSqlBuilder())
          .WithImage("postgres:16")
          .Build();
  do! container.StartAsync()
  printfn "%s" (container.GetConnectionString())
(** But let's not forget to stop it with *)
  do! container.DisposeAsync().AsTask()
(*** hide ***)
}
|> Async.AwaitTask |> Async.RunSynchronously

and then running fsdocs build gives a page with content about test containers:
image

It can be reproduced on linux with these commands:

:/tmp$ dotnet new console --language "F#" -n fsdocdemo
:/tmp$ cd fsdocdemo/
:/tmp/fsdocdemo$ mkdir docs
:/tmp/fsdocdemo$ cat >docs/minimal.fsx <<EOF
> (**
# Usage
*)
(*** hide ***)

#r "nuget: Testcontainers.PostgreSql, 3.6.0"
open Testcontainers.PostgreSql
task {
(** # Start container *)
  let container =
    (new PostgreSqlBuilder())
          .WithImage("postgres:16")
          .Build();
  do! container.StartAsync()
  printfn "%s" (container.GetConnectionString())
(** But let's not forget to stop it with *)
  do! container.DisposeAsync().AsTask()
(*** hide ***)
}
|> Async.AwaitTask |> Async.RunSynchronously
EOF
:/tmp/fsdocdemo$ fsdocs build
:/tmp/fsdocdemo$ cd output
:/tmp/fsdocdemo$ python -m http.server

and access http://localhost:8000/minimal.html

Some more information:

$ dotnet --version
6.0.418
$ fsdocs --version
fsdocs 19.1.1
$ uname -r
6.2.0-37-generic
@rbauduin rbauduin changed the title Using testcontainers in a fsx script gives wrong result Using testcontainers in a fsx script gives wrong output Jan 17, 2024
@nojaf
Copy link
Collaborator

nojaf commented Feb 12, 2024

Hello,

This worked for me:
image

Are you using a custom _template.html maybe?

@rbauduin
Copy link
Author

Thanks for having a look.
I have the same behaviour when running in a docker container.
There's some content that shouldn't be there. And it's no due to test containers, just running a simple task has the problem.
Here's a Dockerfile reproducing the problem:

FROM mcr.microsoft.com/dotnet/sdk

RUN apt-get update && apt-get install -y python3
RUN dotnet tool install --global fsdocs-tool --version 19.1.1
RUN dotnet new console --language "F#" -n fsdocdemo
RUN cd fsdocdemo/
RUN mkdir docs
RUN cat >docs/minimal.fsx <<EOF
(**
# Usage
*)
(*** hide ***)
task {
 return ()
}
|> Async.AwaitTask |> Async.RunSynchronously
EOF

RUN ~/.dotnet/tools/fsdocs build
WORKDIR output
CMD python3 -m http.server

Building the image and running it with this command:

image=$(docker build -q .) ; docker run --rm -it -p8000:8000 $image

I can access the result on http://localhost:8000/minimal.html and get this:

image

@nojaf
Copy link
Collaborator

nojaf commented Feb 12, 2024

Could you try --version 20.0.0-beta-002?

@rbauduin
Copy link
Author

I tried with --version 20.0.0-beta-002 but also get additional content :-(
Some CSS seemed to be missing as layout was wrong.

@nojaf
Copy link
Collaborator

nojaf commented Feb 12, 2024

Oh, I see what you are doing now.
You will need to provide a root for your scenario I believe.
The main problem is that it will not generate the proper links to the .js and .css files.
Try adding --parameters root ./ (Or maybe --parameters root / even)

@rbauduin
Copy link
Author

Adding the value for the root parameter fixes it, thanks @nojaf !

After experimenting a bit, I see what I was doing 'wrong'. However, I don't understand the default value of the root parameter, which leads to paths like /$projectName/content/*.css while it is actually generated at /$projectName/output/content/*.css.

Not a big deal as it's working for me, just curious ;-)

Just for future readers, here's the fixed Dockerfile (including fixing the change of work directory). But note that in the end I went for a root parameter / and running the http server inside the output directory. Using / as root parameter allows content generated in nested directories to also be styled correctly.

FROM mcr.microsoft.com/dotnet/sdk

RUN apt-get update && apt-get install -y python3
RUN dotnet tool install --global fsdocs-tool --version 20.0.0-beta-002
RUN dotnet new console --language "F#" -n fsdocsdemo
WORKDIR fsdocsdemo
RUN mkdir docs
RUN cat >docs/minimal.fsx <<EOF
(**
# Usage
*)
(*** hide ***)
#r "nuget: Testcontainers.PostgreSql, 3.6.0"
open Testcontainers.PostgreSql
task {
(** # Start container *)
  let container =
    (new PostgreSqlBuilder())
          .WithImage("postgres:16")
          .Build();
  do! container.StartAsync()
  printfn "%s" (container.GetConnectionString())
(** But let's not forget to stop it with *)
  do! container.DisposeAsync().AsTask()
(*** hide ***)

}
|> Async.AwaitTask |> Async.RunSynchronously
EOF
RUN ~/.dotnet/tools/fsdocs build --parameters root ./
CMD python3 -m http.server

@nojaf
Copy link
Collaborator

nojaf commented Feb 12, 2024

I agree that the default value is a bit weird here. We should document the root parameter workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants