Skip to content

Commit

Permalink
start docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
leonitousconforti committed Nov 3, 2024
1 parent 2a47302 commit 3c2a826
Show file tree
Hide file tree
Showing 2 changed files with 1,080 additions and 7 deletions.
152 changes: 145 additions & 7 deletions src/engines/DockerCompose.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,151 @@
/**
* Docker compose engine
* Docker compose engine.
*
* @since 1.0.0
*/

// TODO: implement
export interface DockerComposeImpl {
up: () => void;
down: () => void;
pull: () => void;
build: () => void;
import * as FileSystem from "@effect/platform/FileSystem";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Stream from "effect/Stream";

import { Containers, ContainersError } from "../endpoints/Containers.js";
import { Images, ImagesError } from "../endpoints/Images.js";
import { Networks, NetworksError } from "../endpoints/Networks.js";
import { Volumes, VolumesError } from "../endpoints/Volumes.js";
import { JSONMessage } from "../generated/index.js";
import { DockerLayer } from "./Docker.js";

/**
* @since 1.0.0
* @category Type id
*/
export const TypeId: unique symbol = Symbol.for("@the-moby-effect/engines/DockerCompose") as TypeId;

/**
* @since 1.0.0
* @category Type id
*/
export type TypeId = typeof TypeId;

/**
* @since 1.0.0
* @category Models
*/
export interface DockerCompose {
readonly [TypeId]: TypeId;

readonly build: (
project: unknown,
options: {}
) => Effect.Effect<
Record<string, Stream.Stream<JSONMessage, ImagesError, never>>,
ImagesError,
FileSystem.FileSystem
>;

readonly pull: (
project: unknown,
options: {}
) => Effect.Effect<Record<string, Stream.Stream<JSONMessage, ImagesError, never>>, ImagesError, never>;

readonly up: (
project: unknown,
options: {}
) => Effect.Effect<Record<string, string>, ContainersError | VolumesError | NetworksError, never>;

readonly down: (project: unknown, options: {}) => Effect.Effect<Record<string, string>, ContainersError, never>;

readonly rm: (
project: unknown,
options: {}
) => Effect.Effect<Record<string, string>, ContainersError | VolumesError | NetworksError, never>;

readonly kill: (project: unknown, options: {}) => Effect.Effect<Record<string, string>, ContainersError, never>;

readonly forProject: (project: unknown) => DockerComposeProject;
}

/**
* @since 1.0.0
* @category Tags
*/
export const DockerCompose: Context.Tag<DockerCompose, DockerCompose> = Context.GenericTag<DockerCompose>(
"@the-moby-effect/engines/DockerCompose"
);

/**
* @since 1.0.0
* @category Layers
*/
export const layer: Layer.Layer<DockerCompose, never, Layer.Layer.Success<DockerLayer>> = Layer.effect(
DockerCompose,
Effect.gen(function* () {
const images = yield* Images;

Check failure on line 85 in src/engines/DockerCompose.ts

View workflow job for this annotation

GitHub Actions / typescript-build

'images' is declared but its value is never read.
const volumes = yield* Volumes;

Check failure on line 86 in src/engines/DockerCompose.ts

View workflow job for this annotation

GitHub Actions / typescript-build

'volumes' is declared but its value is never read.
const networks = yield* Networks;

Check failure on line 87 in src/engines/DockerCompose.ts

View workflow job for this annotation

GitHub Actions / typescript-build

'networks' is declared but its value is never read.
const containers = yield* Containers;

Check failure on line 88 in src/engines/DockerCompose.ts

View workflow job for this annotation

GitHub Actions / typescript-build

'containers' is declared but its value is never read.

return DockerCompose.of({});

Check failure on line 90 in src/engines/DockerCompose.ts

View workflow job for this annotation

GitHub Actions / typescript-build

Argument of type '{}' is not assignable to parameter of type 'DockerCompose'.
})
);

/**
* @since 1.0.0
* @category Type id
*/
export const DockerComposeProjectTypeId: unique symbol = Symbol.for(
"@the-moby-effect/engines/DockerComposeProject"
) as DockerComposeProjectTypeId;

/**
* @since 1.0.0
* @category Type id
*/
export type DockerComposeProjectTypeId = typeof DockerComposeProjectTypeId;

/**
* @since 1.0.0
* @category Models
*/
export interface DockerComposeProject {
readonly [DockerComposeProjectTypeId]: DockerComposeProjectTypeId;

readonly build: (options: {}) => Effect.Effect<
Record<string, Stream.Stream<JSONMessage, ImagesError, never>>,
ImagesError,
never
>;

readonly up: (options: {}) => Effect.Effect<
Record<string, string>,
ContainersError | VolumesError | NetworksError,
never
>;

readonly down: (options: {}) => Effect.Effect<Record<string, string>, ContainersError, never>;

readonly rm: (options: {}) => Effect.Effect<
Record<string, string>,
ContainersError | VolumesError | NetworksError,
void
>;
}

/**
* @since 1.0.0
* @category Layers
*/
export const layerProject: (
project: string,
tagIdentifier: string
) => {
readonly tag: Context.Tag<DockerComposeProject, DockerComposeProject>;
readonly layer: Layer.Layer<DockerComposeProject, never, DockerCompose>;
} = (project: unknown, tagIdentifier: string) => {
const tag = Context.GenericTag<DockerComposeProject>(tagIdentifier);
const effect = Effect.map(DockerCompose, ({ forProject }) => forProject(project));
const layer = Layer.effect(tag, effect);
return { tag, layer } as const;
};
Loading

0 comments on commit 3c2a826

Please sign in to comment.