Skip to content

Commit

Permalink
Project docker setup
Browse files Browse the repository at this point in the history
Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi committed Sep 28, 2024
1 parent f194866 commit 883201f
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:20.17.0
WORKDIR /usr/app
COPY ../package*.json ./
RUN npm cache clean --force
COPY ../ .
88 changes: 88 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# GitHub Automation App Setup with Docker

This GitHub Automation App uses Docker and Docker Compose to build and run a Node.js code with configurable resource and operation settings. Multiple services can be run simultaneously using different configurations.

## Prerequisites

Make sure the following installed on the system:

- Docker: [Get Docker](https://docs.docker.com/get-docker/)
- Docker Compose: [Get Docker Compose](https://docs.docker.com/compose/install/)

## Project Structure

```bash
.
├── configs/
│ ├── operations/
│ │ ├── github-merged-pulls-monitor.yml
│ │ └── github-workflow-runs-monitor.yml
│ └── resources/
│ └── sample-resource.yml
├── docker/
│ ├── Dockerfile
│ └── docker-compose.yml
├── package.json
└── src/
└── app.js
```

## Docker Setup

The `docker-compose.yml` is configured to use a Node.js image and to run the app. This mounts the project directory to the container for live reloading.

### Dockerfile

The `Dockerfile` is used to create a Docker image for the app:

```
FROM node:20.17.0
WORKDIR /usr/app
COPY ../package*.json ./
RUN npm cache clean --force
COPY ../ .
```

### Docker Compose File

The `docker-compose.yml` file sets up a service (automation-app) to run the app:

```
services:
automation-app:
build:
context: ../
dockerfile: docker/Dockerfile
command:
- /bin/bash
- -c
- |
npm install
npm start
environment:
- RESOURCE_CONFIG=configs/resources/sample-resource.yml
- OPERATION_CONFIG=${OPERATION_CONFIG}
volumes:
- ../:/usr/app/
- /usr/app/node_modules
ports:
- "${PORT}:3000"
```

### Running the Services

This allows to run multiple instances of the service with different configurations and ports.

#### This will run the service on port 8080 with the github-merged-pulls-monitor.yml configuration.

```bash
PORT=8080 OPERATION_CONFIG=configs/operations/github-merged-pulls-monitor.yml docker-compose -p automation-app-1 up -d
```

#### This will run the second service on port 8081 with the github-workflow-runs-monitor.yml configuration.

```
PORT=8081 OPERATION_CONFIG=configs/operations/github-workflow-runs-monitor.yml docker-compose -p automation-app-2 up -d
```
19 changes: 19 additions & 0 deletions docker/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
web:
build:
context: ../
dockerfile: docker/Dockerfile
command:
- /bin/bash
- -c
- |
npm install
npm start
environment:
- RESOURCE_CONFIG=configs/resources/sample-resource.yml
- OPERATION_CONFIG=${OPERATION_CONFIG}
volumes:
- ../:/usr/app/
- /usr/app/node_modules
ports:
- '${PORT}:3000'
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default async (app: Probot) => {
app.log.info('OpenSearch Automation App is starting now......');

const srvObj = new Service('Hello World Service');
const resourceConfig: string = process.env.RESOURCE_CONFIG || 'configs/resources/sample-resource.yml';
const processConfig: string = process.env.OPERATION_CONFIG || 'configs/operations/sample-operation.yml';
const resourceConfig: string = String(process.env.RESOURCE_CONFIG);
const processConfig: string = String(process.env.OPERATION_CONFIG);

if (resourceConfig === '' || processConfig === '') {
throw new Error(`Invalid config path: RESOURCE_CONFIG=${resourceConfig} or OPERATION_CONFIG=${processConfig}`);
Expand Down
4 changes: 3 additions & 1 deletion src/utility/opensearch/opensearch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

import { STSClient, AssumeRoleCommand } from '@aws-sdk/client-sts';
import { ApiResponse, Client as OpenSearchClient } from '@opensearch-project/opensearch';
import { AwsSigv4Signer } from '@opensearch-project/opensearch/lib/aws/index';
// coming from https://github.com/opensearch-project/opensearch-js/issues/410#issuecomment-2378736883
// eslint-disable-next-line import/no-unresolved
import { AwsSigv4Signer } from '@opensearch-project/opensearch/aws-v3';

export class OpensearchClient {
private readonly roleArn = process.env.ROLE_ARN;
Expand Down
2 changes: 1 addition & 1 deletion test/utility/opensearch/opensearch-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { OpensearchClient } from '../../../src/utility/opensearch/opensearch-cli

jest.mock('@aws-sdk/client-sts');
jest.mock('@opensearch-project/opensearch');
jest.mock('@opensearch-project/opensearch/lib/aws/index', () => ({
jest.mock('@opensearch-project/opensearch/aws-v3', () => ({
AwsSigv4Signer: jest.fn().mockReturnValue({}),
}));

Expand Down

0 comments on commit 883201f

Please sign in to comment.