Skip to content

Commit

Permalink
Allow deploying services built with cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
talex5 committed Jul 6, 2020
1 parent 1fed9e5 commit 683cedb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion ocurrent
58 changes: 36 additions & 22 deletions src/pipeline.ml
Expand Up @@ -129,25 +129,28 @@ module Build_unikernel = Build.Make(Packet_unikernel)
module Cluster = struct
module Api = Build_scheduler_api

module Toxis_docker = Current_docker.Default

type build_info = {
sched : Build_cluster.t;
dockerfile : string;
archs : arch list;
}

type deploy_info = {
target : Api.Docker.Image_id.t;
hub_id : Api.Docker.Image_id.t;
services : ([`Toxis] * string) list;
}

(* Build [src/dockerfile] as a Docker service. *)
let build { sched; dockerfile; archs } src =
let build_arch arch = Build_cluster.build sched ~dockerfile ~pool:(pool_id arch) src in
Current.all (List.map build_arch archs)

let name info = Api.Docker.Image_id.repo info.target
let name info = Api.Docker.Image_id.repo info.hub_id

let deploy { sched; dockerfile; archs } { target } src =
let target_label = Api.Docker.Image_id.repo target |> String.map (function '/' | ':' -> '-' | c -> c) in
let deploy { sched; dockerfile; archs } { hub_id; services } src =
let target_label = Api.Docker.Image_id.repo hub_id |> String.map (function '/' | ':' -> '-' | c -> c) in
let build_arch arch =
let pool = pool_id arch in
let tag = Printf.sprintf "live-%s-%s" target_label pool in
Expand All @@ -156,8 +159,16 @@ module Cluster = struct
in
let images = List.map build_arch archs in
match auth with
| Some auth -> Current_docker.push_manifest ~auth images ~tag:(Api.Docker.Image_id.to_string target)
| None -> Current.fail "No auth configured; can't push final image"
| Some auth ->
let multi_hash = Current_docker.push_manifest ~auth images ~tag:(Api.Docker.Image_id.to_string hub_id) in
match services with
| [] -> Current.ignore_value multi_hash
| services ->
let image = Current.map Toxis_docker.Image.of_hash multi_hash in
services
|> List.map (function `Toxis, name -> Toxis_docker.service ~name ~image ())
|> Current.all
end
module Cluster_build = Build.Make(Cluster)

Expand All @@ -174,12 +185,15 @@ let docker dockerfile services =
|> List.map (fun (branch, tag, service) -> branch, { Toxis_service.tag; service }) in
(build_info, deploys)

let docker_hub ?(archs=[`Linux_x86_64]) ~sched dockerfile services =
let docker_hub ?(archs=[`Linux_x86_64]) ~sched dockerfile targets =
let build_info = { Cluster.sched; dockerfile; archs } in
let deploys =
services
|> List.map (fun (branch, target) ->
branch, { Cluster.target = Build_scheduler_api.Docker.Image_id.of_string target |> or_fail }
targets
|> List.map (fun (branch, target, services) ->
branch, { Cluster.
hub_id = Build_scheduler_api.Docker.Image_id.of_string target |> or_fail;
services
}
)
in
(build_info, deploys)
Expand All @@ -202,17 +216,6 @@ let v ~app ~notify:channel ~sched ~staging_auth () =
let build (org, name, builds) = Build_toxis.repo ~channel ~web_ui ~org ~name builds in
Current.all @@ List.map build [
(* OCurrent repositories *)
ocurrent, "ocaml-ci", [
docker "Dockerfile" ["live-engine", "ocaml-ci-service:latest", "ocaml-ci_ci"];
docker "Dockerfile.web" ["live-www", "ocaml-ci-web:latest", "ocaml-ci_web";
"staging-www", "ocaml-ci-web:staging", "test-www"];
];
ocurrent, "ocurrent-deployer", [
docker "Dockerfile" ["live", "ci.ocamllabs.io-deployer:latest", "infra_deployer"];
];
ocurrent, "docker-base-images", [
docker "Dockerfile" ["live", "base-images:latest", "base-images_builder"];
];
ocurrent, "opam-repo-ci", [
docker "Dockerfile" []; (* No deployments for now *)
docker "Dockerfile.web" [];
Expand All @@ -223,9 +226,20 @@ let v ~app ~notify:channel ~sched ~staging_auth () =
let sched = Build_cluster.v ~timeout ?push_auth:staging_auth sched in
let docker_hub = docker_hub ~sched in
Current.all @@ List.map build [
ocurrent, "ocaml-ci", [
docker_hub "Dockerfile" ["live-engine", "ocurrent/ocaml-ci-service:live", [`Toxis, "ocaml-ci_ci"]];
docker_hub "Dockerfile.web" ["live-www", "ocurrent/ocaml-ci-web:live", [`Toxis, "ocaml-ci_web"];
"staging-www", "ocurrent/ocaml-ci-web:staging", [`Toxis, "test-www"]];
];
ocurrent, "ocurrent-deployer", [
docker_hub "Dockerfile" ["live", "ocurrent/ci.ocamllabs.io-deployer:live", [`Toxis, "infra_deployer"]];
];
ocurrent, "docker-base-images", [
docker_hub "Dockerfile" ["live", "ocurrent/base-images:live", [`Toxis, "base-images_builder"]];
];
ocurrent, "build-scheduler", [
docker_hub "Dockerfile" ["live", "ocurrent/build-scheduler:live"];
docker_hub "Dockerfile.worker" ["live", "ocurrent/build-worker:live"] ~archs:[`Linux_x86_64; `Linux_arm64];
docker_hub "Dockerfile" ["live", "ocurrent/build-scheduler:live", []];
docker_hub "Dockerfile.worker" ["live", "ocurrent/build-worker:live", [`Toxis, "build-agent"]] ~archs:[`Linux_x86_64; `Linux_arm64];
];
]
and mirage_unikernels =
Expand Down

0 comments on commit 683cedb

Please sign in to comment.