Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 6 additions & 10 deletions .github/workflows/binary-nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,18 @@ jobs:
mv "./$ARCHIVE_DIR/dune" "$HOME/.local/bin"
rm -rf "./$ARCHIVE_DIR"

- name: Update config on test
if: ${{ github.ref == 'refs/heads/staging' }}
run: |
sed -i 's#let bucket_dir = .*#let bucket_dir = "/dune/test"#g' ./bin/config.ml
sed -i 's#let url = .*#let url = "https://get.dune.build/test"#g' ./bin/config.ml
git add --ignore-errors ./bin/config.ml
cat ./bin/config.ml

- name: Install Sandworm deps && build
run: dune build

- name: Move artifacts to scope
run: mv "/home/runner/artifacts" "."

- name: Export executables and generate html
shell: bash
- name: 'TEST -- Export executables and generate HTML'
if: ${{ github.ref == 'refs/heads/staging' }}
Comment thread
shonfeder marked this conversation as resolved.
run: ./_build/install/default/bin/sandworm sync --commit "${{ needs.binary.outputs.git-commit }}" --testing

- name: Export executables and generate HTML
if: ${{ github.ref != 'refs/heads/staging' }}
Comment thread
shonfeder marked this conversation as resolved.
run: ./_build/install/default/bin/sandworm sync --commit "${{ needs.binary.outputs.git-commit }}"

- name: Commit changes to branch
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/binary-stable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,6 @@ jobs:
with:
path: /home/runner/artifacts

- name: Update config to point to test environment
if: ${{ github.ref == 'refs/heads/staging' || inputs.test }}
run: |
sed -i 's#let bucket_dir = .*#let bucket_dir = "/dune/test"#g' ./bin/config.ml
sed -i 's#let url = .*#let url = "https://get.dune.build/test"#g' ./bin/config.ml
cat ./bin/config.ml

- name: "Install Sandworm deps & build"
run: dune build

Expand All @@ -222,8 +215,12 @@ jobs:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_PUBLIC_KEY: ${{ secrets.SSH_PUBLIC_KEY }}

- name: Export executables and generate html
shell: bash
- name: 'TEST -- Export executables and generate HTML'
if: ${{ inputs.test }}
run: ./_build/install/default/bin/sandworm sync --commit "${{ needs.check_build.outputs.commit }}" --tag "${{ needs.check_build.outputs.release }}" --testing

- name: Export executables and generate HTML
if: ${{ !inputs.test }}
run: ./_build/install/default/bin/sandworm sync --commit "${{ needs.check_build.outputs.commit }}" --tag "${{ needs.check_build.outputs.release }}"

- name: Commit changes to branch
Expand Down
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ build`.

### Configure

The configuration is in [bin/config.ml](./bin/config.ml)
file. When running in the pipeline, the _sandworm_ binary is generated before
its execution. As a result, the path taken is the root of this repository. If
you want to run it locally, make sure the _files artifacts_ and `rclone.conf`
are available in the directory where _sandworm_ binary is executed.
The configuration for serving the redirects to the artifacts and the web site
is stored in [`bin/config.ml`](./bin/config.ml), it includes both production
and test configuration values.

When launching the _sandworm_ binary, it supports the `--testing` option to
switch between the configurations. It defaults to the production config.

The upload of created binaries uses RClone, its configuration is set in the
`rclone.conf` in the repository, where it specifies which host, username and
authentication method is used.

The export relies on an SSH key to the server. If you want to run your own
tests, you need to have a server available by _SSH_ with an _SSH key_. Then,
Expand All @@ -53,14 +58,10 @@ key_file = </path/to/your/ssh/private/key>
```

If you don't have a `/dune` directory on your server, you might want to change
the `s3_bucket_ref` variable. It could be:

```ocaml
let s3_bucket_ref = "dune-binary-distribution:/path/to/your/server/dir"
```
the `bucket_dir` variable in [`bin/config.ml`](./bin/config.ml).

> [!TIP]
> For our use case, the _RClone_ configuration works with SFTP but, it is
> For our use case, the _RClone_ configuration is set up to use SFTP but it is
> compatible with any _RClone_ provider.

## Running
Expand All @@ -69,8 +70,6 @@ Now your setup is ready, you can execute this list of commands to generate or
update the files:

```sh
$ ls
artifacts rclone.conf
$ dune exec -- sandworm sync --commit [commit hash]
```

Expand Down
49 changes: 40 additions & 9 deletions bin/config.ml
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
module Server = struct
let bucket_dir = "/dune/"
let rclone_bucket_ref = Format.sprintf "dune-binary-distribution:%s" bucket_dir
let url = "https://get.dune.build/"
module type Configuration = sig
module Server : sig
val rclone_bucket_ref : string
val url : string
end

module Path : sig
val artifacts_dir : string
val metadata : string
val rclone : string
val install : string
end
end

module Path = struct
let artifacts_dir = "./artifacts"
let metadata = "./metadata.json"
let rclone = "./rclone.conf"
let install = "./static/install"
module Production : Configuration = struct
module Server = struct
let bucket_dir = "/dune/"
let rclone_bucket_ref = Printf.sprintf "dune-binary-distribution:%s" bucket_dir
let url = "https://get.dune.build/"
end

module Path = struct
let artifacts_dir = "./artifacts"
let metadata = "./metadata.json"
let rclone = "./rclone.conf"
let install = "./static/install"
end
end

module Testing : Configuration = struct
module Server = struct
let bucket_dir = "/dune/test"
let rclone_bucket_ref = Printf.sprintf "dune-binary-distribution:%s" bucket_dir
let url = "https://get.dune.build/test"
end

module Path = struct
let artifacts_dir = "./artifacts"
let metadata = "./metadata.json"
let rclone = "./rclone.conf"
let install = "./static/install"
end
end
23 changes: 14 additions & 9 deletions bin/config.mli
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
module Server : sig
val rclone_bucket_ref : string
val url : string
end
module type Configuration = sig
module Server : sig
val rclone_bucket_ref : string
val url : string
end

module Path : sig
val artifacts_dir : string
val metadata : string
val rclone : string
val install : string
module Path : sig
val artifacts_dir : string
val metadata : string
val rclone : string
val install : string
end
end

module Production : Configuration
module Testing : Configuration
36 changes: 23 additions & 13 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ open Sandworm
open Cmdliner

module Common_args = struct
let metadata_file =
let doc = "The JSON file containing the metadata." in
Arg.(value & opt string Config.Path.metadata & info ~doc [ "metadata" ])
let testing =
let doc = "Run in test configuration." in
Arg.(value & opt bool false & info ~doc [ "testing" ])
;;

let commit =
Expand Down Expand Up @@ -34,9 +34,9 @@ module Common_args = struct
end

module Sync = struct
let synchronise metadata_file ~commit ~tag dry_run =
let synchronise (module Config : Config.Configuration) ~commit ~tag dry_run =
Format.printf "--> Start synchronisation\n";
let bundles = Metadata.import_from_json metadata_file in
let bundles = Metadata.import_from_json Config.Path.metadata in
let daily_bundle =
Metadata.Bundle.create_daily ~commit ~tag Metadata.Target.defaults
in
Expand Down Expand Up @@ -82,19 +82,24 @@ module Sync = struct
let bundles = Metadata.insert_unique daily_bundle bundles in
let () =
if dry_run
then Format.printf "- Export metadata to %s\n" metadata_file
else Metadata.export_to_json metadata_file bundles
then Format.printf "- Export metadata to %s\n" Config.Path.metadata
else Metadata.export_to_json Config.Path.metadata bundles
in
Format.printf "--> Completed ✓\n"
;;

let term =
let open Term.Syntax in
let+ metadata_file = Common_args.metadata_file
let+ testing = Common_args.testing
and+ commit = Common_args.commit
and+ tag = Common_args.tag
and+ dry_run = Common_args.dry_run in
synchronise metadata_file ~commit ~tag dry_run
let config =
match testing with
| false -> (module Config.Production : Config.Configuration)
| true -> (module Config.Testing)
in
synchronise config ~commit ~tag dry_run
;;

let info =
Expand Down Expand Up @@ -128,10 +133,10 @@ let find_latest_stable bundles =
;;

module Http = struct
let serve dev metadata_file port =
let serve dev (module Config : Config.Configuration) port =
let title = "Dune Nightly" in
let base_url = Config.Server.url in
let bundles = Metadata.import_from_json metadata_file in
let bundles = Metadata.import_from_json Config.Path.metadata in
let latest_release =
match find_latest_stable bundles with
| None -> "<RELEASE>"
Expand All @@ -151,9 +156,14 @@ module Http = struct
let term =
let open Term.Syntax in
let+ dev = Common_args.dev
and+ metadata_file = Common_args.metadata_file
and+ testing = Common_args.testing
and+ port = Common_args.port in
serve dev metadata_file port
let config =
match testing with
| false -> (module Config.Production : Config.Configuration)
| true -> (module Config.Testing)
in
serve dev config port
;;

let info =
Expand Down