Skip to content

Commit

Permalink
Project docker setup (#12)
Browse files Browse the repository at this point in the history
Signed-off-by: Prudhvi Godithi <pgodithi@amazon.com>
  • Loading branch information
prudhvigodithi authored Sep 30, 2024
1 parent bab72ee commit 08a004e
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 5 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![](https://img.shields.io/codecov/c/gh/opensearch-project/automation-app)](https://app.codecov.io/gh/opensearch-project/automation-app)

<img src="https://opensearch.org/assets/img/opensearch-logo-themed.svg" height="64px">

- [Welcome!](#welcome)
Expand Down Expand Up @@ -60,7 +62,6 @@ When you run the above command, the following takes place:
1. Retrieves the [GitHub Context](https://probot.github.io/api/latest/classes/context.Context.html) (or any other defined context) for all the resources listed in the resource config file.
1. Registers and listens for events, executes the `Tasks` defined in the operation config. These tasks will be executed sequentially when the corresponding events occur.


#### List of Environment Variables (You can use them directly in the startup command, export them, or add them to the `.env` file):
| Name | Type | Default | Description | Example |
|-----------------------------|---------|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------|
Expand All @@ -70,6 +71,10 @@ When you run the above command, the following takes place:
| ADDITIONAL_RESOURCE_CONTEXT | Boolean | false | Setting true will let each resource defined in RESOURCE_CONFIG to call GitHub Rest API and GraphQL for more detailed context (ex: node_id). Increase startup time. | true / false |
| SERVICE_NAME | String | 'default' | Set Service Name | 'My Service' |'

#### Start the Service with Docker

For detailed instructions on starting the service with Docker, refer to the project's [Docker Setup](./docker/README.md).

## Code of Conduct

This project has adopted [the Open Source Code of Conduct](CODE_OF_CONDUCT.md).
Expand Down
4 changes: 4 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM node:20
WORKDIR /usr/share/app
COPY ../ .
RUN npm cache clean --force
55 changes: 55 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# GitHub Automation App Setup with Docker

The GitHub Automation App can be deployed using Docker and Docker Compose to run as a service 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/
│ │ └── sample-operation.yml
│ └── resources/
│ └── sample-resource.yml
├── docker/
│ ├── Dockerfile
│ └── docker-compose.yml
```

## 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](Dockerfile) is used to create a Docker image for the app.


### Docker Compose File

The [compose.yml](compose.yaml) file sets up a service (automation-app) to run the app:


### Run multiple 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 sample-operation.yml configuration.

```bash
PORT=8080 RESOURCE_CONFIG=configs/resources/sample-resource.yml OPERATION_CONFIG=configs/operations/sample-operation.yml docker-compose -p automation-app-1 up -d
```

#### This will run the second service on port 8081 with the sample-operation-2.yml configuration.

```
PORT=8081 RESOURCE_CONFIG=configs/resources/sample-resource.yml OPERATION_CONFIG=configs/operations/sample-operation-2.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=${RESOURCE_CONFIG}
- OPERATION_CONFIG=${OPERATION_CONFIG}
volumes:
- ../:/usr/share/app
- /usr/share/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 @@ -14,8 +14,8 @@ export default async (app: Probot) => {
app.log.info('OpenSearch Automation App is starting now......');

// Env Vars
const resourceConfig: string = process.env.RESOURCE_CONFIG || '';
const processConfig: string = process.env.OPERATION_CONFIG || '';
const resourceConfig: string = String(process.env.RESOURCE_CONFIG) || '';
const processConfig: string = String(process.env.OPERATION_CONFIG) || '';
const additionalResourceContext: boolean = Boolean(process.env.ADDITIONAL_RESOURCE_CONTEXT) || false;
const serviceName: string = process.env.SERVICE_NAME || 'default';

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 08a004e

Please sign in to comment.