Skip to content

Commit

Permalink
Merge pull request #9 from makeopensource/cli-publish
Browse files Browse the repository at this point in the history
Cli publish
  • Loading branch information
RA341 authored Oct 4, 2024
2 parents 27c9ba1 + 6d01211 commit 00bd3e1
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 35 deletions.
1 change: 1 addition & 0 deletions .example/hydra/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
29 changes: 29 additions & 0 deletions .example/hydra/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 3 additions & 1 deletion .example/hydra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
58 changes: 29 additions & 29 deletions .example/hydra/src/client.ts
Original file line number Diff line number Diff line change
@@ -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);
// }
// });
// }
19 changes: 16 additions & 3 deletions .example/hydra/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -82,6 +83,18 @@ async function main() {
}
}

program.action(main);
program
.option('-u, --url <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);
11 changes: 9 additions & 2 deletions .github/workflows/beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
dkbuild:
docker build . -t github.com/makeopensource/leviathan

dkrun:
docker run -p 9221:9221 github.com/makeopensource/leviathan

buildrun:
make dkbuild
make dkrun

pullrun:
docker run -p 9221:9221 ghcr.io/makeopensource/leviathan

0 comments on commit 00bd3e1

Please sign in to comment.