From a48b96ae3c85b865ed39de9d89fb8ae7394a121f Mon Sep 17 00:00:00 2001 From: RA341 Date: Thu, 3 Oct 2024 23:23:51 -0400 Subject: [PATCH 1/3] added makefile cmds --- Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Makefile b/Makefile index e69de29..c3aae56 100644 --- a/Makefile +++ b/Makefile @@ -0,0 +1,12 @@ +dk: + docker build . -t github.com/makeopensource/leviathan + +dkrun: + docker run -p 9221:9221 github.com/makeopensource/leviathan + +buildrun: + make dk + make dkrun + +pullrun: + docker run -p 9221:9221 ghcr.io/makeopensource/leviathan \ No newline at end of file From 35a7ddb9189f8eccec972e1e398b9e7ff3d38505 Mon Sep 17 00:00:00 2001 From: RA341 Date: Thu, 3 Oct 2024 23:24:03 -0400 Subject: [PATCH 2/3] client is private for now --- .example/hydra/src/client.ts | 58 ++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/.example/hydra/src/client.ts b/.example/hydra/src/client.ts index dfe2d46..9961aa7 100644 --- a/.example/hydra/src/client.ts +++ b/.example/hydra/src/client.ts @@ -1,29 +1,29 @@ -// implementation for interacting with the leviathan GRPC API - -import grpc from '@grpc/grpc-js'; -import {DockerServiceClient} from "./gen/docker_grpc_pb"; -import {JobServiceClient} from "./gen/jobs_grpc_pb"; -import {CreateRequest} from "./gen/docker_pb"; -import {NewJobRequest} from "./gen/jobs_pb"; - - -export function client() { - const dockerClient = new DockerServiceClient('localhost:50051', grpc.credentials.createInsecure()); - const jobsClient = new JobServiceClient('localhost:50051', grpc.credentials.createInsecure()) - - dockerClient.createContainer(new CreateRequest(), (err, resp) => { - if (err) { - console.error(err); - } else { - console.log("Response :", resp); - } - }); - - jobsClient.newJob(new NewJobRequest(), (err, resp) => { - if (err) { - console.error(err); - } else { - console.log("Response :", resp); - } - }); -} +// // implementation for interacting with the leviathan GRPC API +// +// import grpc from '@grpc/grpc-js'; +// import {DockerServiceClient} from "leviathan-client/index"; +// import {JobServiceClient} from "./gen/jobs_grpc_pb"; +// import {CreateRequest} from "./gen/docker_pb"; +// import {NewJobRequest} from "./gen/jobs_pb"; +// +// +// export function client() { +// const dockerClient = new DockerServiceClient('localhost:50051', grpc.credentials.createInsecure()); +// const jobsClient = new JobServiceClient('localhost:50051', grpc.credentials.createInsecure()) +// +// dockerClient.createContainer(new CreateRequest(), (err, resp) => { +// if (err) { +// console.error(err); +// } else { +// console.log("Response :", resp); +// } +// }); +// +// jobsClient.newJob(new NewJobRequest(), (err, resp) => { +// if (err) { +// console.error(err); +// } else { +// console.log("Response :", resp); +// } +// }); +// } From 6d012113d55b5647fa5b7e79ea49de1ed993ee83 Mon Sep 17 00:00:00 2001 From: RA341 Date: Thu, 3 Oct 2024 23:49:34 -0400 Subject: [PATCH 3/3] added cli docker build --- .example/hydra/.dockerignore | 1 + .example/hydra/Dockerfile | 29 +++++++++++++++++++++++++++++ .example/hydra/package.json | 4 +++- .example/hydra/src/index.ts | 19 ++++++++++++++++--- .github/workflows/beta.yml | 11 +++++++++-- .github/workflows/release.yml | 15 +++++++++++++++ Makefile | 4 ++-- 7 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 .example/hydra/.dockerignore create mode 100644 .example/hydra/Dockerfile diff --git a/.example/hydra/.dockerignore b/.example/hydra/.dockerignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.example/hydra/.dockerignore @@ -0,0 +1 @@ +node_modules diff --git a/.example/hydra/Dockerfile b/.example/hydra/Dockerfile new file mode 100644 index 0000000..a5f7d4f --- /dev/null +++ b/.example/hydra/Dockerfile @@ -0,0 +1,29 @@ +# Build the docker cli for docker consumption + +# Build client library +FROM node:20 AS client-builder + +WORKDIR /client + +COPY .spec/client . + +RUN npm install + +# Use an official Node runtime as the parent image +FROM node:20 + +# Set the working directory in the container +WORKDIR /app/cli/hydra/ + +# Copy the application source code +COPY .example/hydra . + +COPY --from=client-builder client client + +# Install the application dependencies +RUN npm install + +RUN npm install ./client + +# Set the entrypoint to run the CLI +ENTRYPOINT ["npm", "run", "cli"] \ No newline at end of file diff --git a/.example/hydra/package.json b/.example/hydra/package.json index a03d31d..703a6ed 100644 --- a/.example/hydra/package.json +++ b/.example/hydra/package.json @@ -5,7 +5,9 @@ "main": "index.js", "scripts": { "cli": "ts-node src/index.ts", - "index": "npm src/index.ts" + "index": "npm src/index.ts", + "dk:bd": "docker build ../../ -f ./Dockerfile -t hydra", + "dk:rn": "docker run -it --network host hydra start" }, "type": "commonjs", "keywords": [], diff --git a/.example/hydra/src/index.ts b/.example/hydra/src/index.ts index 54cbfa0..e0505e6 100644 --- a/.example/hydra/src/index.ts +++ b/.example/hydra/src/index.ts @@ -10,10 +10,11 @@ program .version('1.0.0') .description('A CLI to interact with the Leviathan API'); -const baseUrl = "http://localhost:9221" +let baseUrl = "http://localhost:9221" // const coursesApi = new CoursesApi(undefined, "http://localhost:9221"); -const dockerApi = new DockerApi(undefined, baseUrl); +let dockerApi = new DockerApi(undefined, baseUrl); + const dockerEndpoints = { "Get Container info": async () => { const {containerId} = await inquirer.prompt([ @@ -82,6 +83,18 @@ async function main() { } } -program.action(main); +program + .option('-u, --url ', 'specify a custom base URL for the API') + .action((options) => { + if (options.url) { + dockerApi = new DockerApi(undefined, options.url); + console.log(`Using custom base URL: ${baseUrl}`); + } + }); + +program + .command('start') + .description('Start the calling the API') + .action(main) program.parse(process.argv); \ No newline at end of file diff --git a/.github/workflows/beta.yml b/.github/workflows/beta.yml index 5f1d8eb..f2decce 100644 --- a/.github/workflows/beta.yml +++ b/.github/workflows/beta.yml @@ -26,12 +26,19 @@ jobs: - name: Login to GHCR registry run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - - name: build image + - name: build leviathan image run: docker build . -t ghcr.io/${{ github.repository }}:beta - - name: push + - name: push leviathan run: docker push ghcr.io/${{ github.repository }}:beta + - name: build hydra image + working-directory: .example/hydra + run: docker build . -t ghcr.io/makeopensource/hydra:beta + + - name: push hydra + run: docker push ghcr.io/makeopensource/hydra:beta + # if the binary needs to built directly # - name: Set up Go # uses: actions/setup-go@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c9dd844..1980997 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -68,3 +68,18 @@ jobs: - name: push latest run: docker push ghcr.io/${{ github.repository }}:latest + + - name: build hydra image latest + working-directory: .example/hydra + run: docker build . -t ghcr.io/makeopensource/hydra:latest + + - name: push hydra latest + run: docker push ghcr.io/makeopensource/hydra:latest + + - name: build hydra image versioned + working-directory: .example/hydra + run: docker build . -t ghcr.io/makeopensource/hydra:${{ steps.tagName.outputs.tag }} + + - name: push hydra versioned + run: docker push ghcr.io/makeopensource/hydra:${{ steps.tagName.outputs.tag }} + diff --git a/Makefile b/Makefile index c3aae56..3a02bdf 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ -dk: +dkbuild: docker build . -t github.com/makeopensource/leviathan dkrun: docker run -p 9221:9221 github.com/makeopensource/leviathan buildrun: - make dk + make dkbuild make dkrun pullrun: