Skip to content

Commit 08a004e

Browse files
Project docker setup (#12)
Signed-off-by: Prudhvi Godithi <pgodithi@amazon.com>
1 parent bab72ee commit 08a004e

File tree

7 files changed

+90
-5
lines changed

7 files changed

+90
-5
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![](https://img.shields.io/codecov/c/gh/opensearch-project/automation-app)](https://app.codecov.io/gh/opensearch-project/automation-app)
2+
13
<img src="https://opensearch.org/assets/img/opensearch-logo-themed.svg" height="64px">
24

35
- [Welcome!](#welcome)
@@ -60,7 +62,6 @@ When you run the above command, the following takes place:
6062
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.
6163
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.
6264

63-
6465
#### List of Environment Variables (You can use them directly in the startup command, export them, or add them to the `.env` file):
6566
| Name | Type | Default | Description | Example |
6667
|-----------------------------|---------|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------|
@@ -70,6 +71,10 @@ When you run the above command, the following takes place:
7071
| 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 |
7172
| SERVICE_NAME | String | 'default' | Set Service Name | 'My Service' |'
7273

74+
#### Start the Service with Docker
75+
76+
For detailed instructions on starting the service with Docker, refer to the project's [Docker Setup](./docker/README.md).
77+
7378
## Code of Conduct
7479

7580
This project has adopted [the Open Source Code of Conduct](CODE_OF_CONDUCT.md).

docker/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM node:20
2+
WORKDIR /usr/share/app
3+
COPY ../ .
4+
RUN npm cache clean --force

docker/README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# GitHub Automation App Setup with Docker
2+
3+
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.
4+
5+
## Prerequisites
6+
7+
Make sure the following installed on the system:
8+
9+
- Docker: [Get Docker](https://docs.docker.com/get-docker/)
10+
- Docker Compose: [Get Docker Compose](https://docs.docker.com/compose/install/)
11+
12+
## Project Structure
13+
14+
```bash
15+
.
16+
├── configs/
17+
│ ├── operations/
18+
│ │ └── sample-operation.yml
19+
│ └── resources/
20+
│ └── sample-resource.yml
21+
├── docker/
22+
│ ├── Dockerfile
23+
│ └── docker-compose.yml
24+
```
25+
26+
## Docker Setup
27+
28+
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.
29+
30+
### Dockerfile
31+
32+
The [Dockerfile](Dockerfile) is used to create a Docker image for the app.
33+
34+
35+
### Docker Compose File
36+
37+
The [compose.yml](compose.yaml) file sets up a service (automation-app) to run the app:
38+
39+
40+
### Run multiple Services
41+
42+
This allows to run multiple instances of the service with different configurations and ports.
43+
44+
#### This will run the service on port 8080 with the sample-operation.yml configuration.
45+
46+
```bash
47+
PORT=8080 RESOURCE_CONFIG=configs/resources/sample-resource.yml OPERATION_CONFIG=configs/operations/sample-operation.yml docker-compose -p automation-app-1 up -d
48+
```
49+
50+
#### This will run the second service on port 8081 with the sample-operation-2.yml configuration.
51+
52+
```
53+
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
54+
55+
```

docker/compose.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
services:
2+
web:
3+
build:
4+
context: ../
5+
dockerfile: docker/Dockerfile
6+
command:
7+
- /bin/bash
8+
- -c
9+
- |
10+
npm install
11+
npm start
12+
environment:
13+
- RESOURCE_CONFIG=${RESOURCE_CONFIG}
14+
- OPERATION_CONFIG=${OPERATION_CONFIG}
15+
volumes:
16+
- ../:/usr/share/app
17+
- /usr/share/app/node_modules
18+
ports:
19+
- '${PORT}:3000'

src/app.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export default async (app: Probot) => {
1414
app.log.info('OpenSearch Automation App is starting now......');
1515

1616
// Env Vars
17-
const resourceConfig: string = process.env.RESOURCE_CONFIG || '';
18-
const processConfig: string = process.env.OPERATION_CONFIG || '';
17+
const resourceConfig: string = String(process.env.RESOURCE_CONFIG) || '';
18+
const processConfig: string = String(process.env.OPERATION_CONFIG) || '';
1919
const additionalResourceContext: boolean = Boolean(process.env.ADDITIONAL_RESOURCE_CONTEXT) || false;
2020
const serviceName: string = process.env.SERVICE_NAME || 'default';
2121

src/utility/opensearch/opensearch-client.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

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

1416
export class OpensearchClient {
1517
private readonly _roleArn = process.env.ROLE_ARN;

test/utility/opensearch/opensearch-client.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { OpensearchClient } from '../../../src/utility/opensearch/opensearch-cli
1313

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

0 commit comments

Comments
 (0)