Sample build viewer application built with .NET Core, F#, Fable, WebSocket.
This template can be used to generate a full-stack web application using the SAFE Stack. It was created using the dotnet SAFE Template. If you want to learn more about the template why not start with the quick start guide?
You'll need to install the following pre-requisites in order to build SAFE applications
- The .NET Core SDK 3.1 or higher.
- npm package manager.
- Node LTS.
Start the server:
cd src\Server\
dotnet run
Start the client:
npm install
npm run start
Open a browser to http://localhost:8080
to view the site.
If you want to know more about the full Azure Stack and all of its components (including Azure) visit the official SAFE documentation.
You will find more documentation about the used F# components at the following places:
In our CI/CD, some builds run asynchronously because of various infrastructure constraints. That's why we need a viewer app to see what's going on:
- How many build requests are running?
- How many are queued?
- Are there any errors already in running builds?
You can look at commit history to identify the changes related to all steps below.
I used minimal SAFE template:
dotnet new SAFE -m
I prefer Feliz
over Fable.React
for the same reasons as in The Elmish book.
That's why I have migrated the client code to Feliz
.
Then I start populating my model with various types:
BuildStatus
: list ofBuildRequest
BuildRequest
: a request in the queue with various info like platform, configuration, sha1, user, etc.
I update client model to render a first dummy request.
I need to extend current API to include build progress info.
I add the type BuildProgress
for this matter:
Server
: host currently processing this request.Start
: time when this request was removed from queue.ExpectedMin
: expected duration in minutes.Errors
: list of errors found in log.
In BuildStatus
(list of build requests), I now use a tuple where the second parameter is a BuildProgress
option.
This allows me to use the same list for the requests still in queue and the ones currently running.
I need a cool progress with inverted colors bar to render build progress. I found a cool one in codepen, but unfortunately, it depends on compass.
So I refactored the code to suit my needs with vanilla CSS. I would have preferred a pure F# solution, but I could not manage to remove all raw css (cf. changes in index.html)
I update client code to render two sections:
- Queued build requests.
- Running build requests with progress info.
I also do the necessary to use some FontAwesome
icons.
In previous commit, I display a red list icon when a running build has errors.
To properly display the list of errors, I want to:
- Show errors when user click on list icon.
- Show errors for only one build at a time.
- Hide errors when clicking again on the same build.
Impacts in client code:
- I update client model to add a
Guid option
for the build with errors displayed. - I add two client messages to hide or show errors for a specific build.
- The list icon is promoted to a button. When clicked:
- If build id matches current id, I dispatch a Hide message.
- Otherwise, this is a Show id message to display errors of this build (and this will automatically hide errors of previous build if needed)
In many other SAFE applications, most messages are triggered by client events. Here, the server will continuously analyze the build queue and the builds running in the pool of servers. So I need to be able to trigger messages on client side from the server.
I found out I can use WebSocket for this matter.
I adapted the code from two other SAFE samples:
Before sending BuildStatus
updates from the server, in a first step I just update hello message with server uptime.
In this last step, I remove everything related to hello message. Client model now starts with an empty list of builds.
On server side:
- I extend
BuildStatus
API with all members needed to:- Add a new queued request
- Start progress of an existing request
- Add an error to a running request
- Remove a (finished) request
- I remove the router (not used anymore)
- I update the loop to continuously send
BuildStatus
updates with all operations listed above.
- The Elmish Book
- Feliz documentation
- Redux dev tools to fix browser errors