Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1040 Add package node-multiple-ports #1700

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
build: add package node-multiple-ports
  • Loading branch information
leite08 committed Feb 27, 2024
commit 211f052b29faa828b8a7aa9f671e49da734159dd
25 changes: 25 additions & 0 deletions packages/node-multiple-ports/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#########################################
### Base Image ##
#########################################
FROM node:18 AS build
WORKDIR /app
COPY . /app
RUN npm ci --no-fund --no-audit

#########################################
### Prod Image ##
#########################################
FROM node:18-slim
COPY --from=build /app /app
WORKDIR /app
EXPOSE 8443
EXPOSE 8080
EXPOSE 8081
EXPOSE 8082
EXPOSE 8083
EXPOSE 8084
EXPOSE 8085
EXPOSE 8086
EXPOSE 9091
EXPOSE 9092
ENTRYPOINT npm start
42 changes: 42 additions & 0 deletions packages/node-multiple-ports/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Metriport Utils: Node listening to multiple ports

Metriport's util to build a docker container that listens to multiple ports and respond a simple 200 +
payload indicating the port being executed.

Upon execution it logs:

```shell
Listening on port 8080...
Listening on port 8443...
Listening on port 8081...
...
```

Upon request on port `8080` it logs:

```shell
Got a request on port 8080 - GET /
```

...and responds:

```json
{
"port": 8080,
"method": "GET",
"path": "/",
"status": "OK"
}
```

## Useful commands

- `npm start` runs the server as a Node process
- `docker compose -f docker-compose.yml up --build` build and run the server as a docker container
(remove `--build` to run it without building)
- `./deploy.sh` publishes the docker container on ECR and triggers a restart on a ECS service - required env vars:
- `AWS_REGION` the aws region
- `ECR_REPO_URI` the ECR repo URI
- `ECS_CLUSTER` the ECS cluster ARN
- `IHE_OUTBOUND_ECS_SERVICE` the ECS service ARN of the outbound instance
- `IHE_INBOUND_ECS_SERVICE` the ECS service ARN of the outbound instance
64 changes: 64 additions & 0 deletions packages/node-multiple-ports/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash

# Run from the root of the repository.

AWS_REGION="us-west-1"
ECR_REPO_URI="463519787594.dkr.ecr.us-west-1.amazonaws.com/metriport/ihe-gateway"
ECS_CLUSTER="IHEStack-IHEGatewayClusterA7D9B464-O0YKSVeILdSi"
IHE_OUTBOUND_ECS_SERVICE="IHEStack-IHEGatewayOutboundFargateService64CBCB18-s0a924Lki3Be"
IHE_INBOUND_ECS_SERVICE="IHEStack-IHEGatewayInboundFargateService4393BE41-ksKDv5k5owRh"

if [[ -z "${AWS_REGION}" ]]; then
echo "AWS_REGION is missing"
exit 1
fi
if [[ -z "${ECR_REPO_URI}" ]]; then
echo "ECR_REPO_URI is missing"
exit 1
fi
if [[ -z "${ECS_CLUSTER}" ]]; then
echo "ECS_CLUSTER is missing"
exit 1
fi
if [[ -z "${ECS_SERVICE}" ]]; then
echo "ECS_SERVICE is missing"
exit 1
fi

# Fail on error
set -e
# Echo commands
set -x

echo "Logging into ECR/Docker"
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_REPO_URI

GITHUB_SHA=$(git rev-parse --short HEAD)

echo "Building and pushing Docker image"
docker buildx build \
--platform linux/amd64 \
--tag "$ECR_REPO_URI:latest" \
--tag "$ECR_REPO_URI:$GITHUB_SHA" \
--push \
.

# TODO consider using the same approach from packages/ihe-gateway/scripts/push-to-cloud.sh to restart the services

echo "Restarting the IHE GW service $IHE_INBOUND_ECS_SERVICE"
# Update the fargate service
aws ecs update-service \
--no-cli-pager \
--region "$AWS_REGION" \
--cluster "$ECS_CLUSTER" \
--service "$IHE_INBOUND_ECS_SERVICE" \
--force-new-deployment

echo "Restarting the IHE GW service $IHE_OUTBOUND_ECS_SERVICE"
# Update the fargate service
aws ecs update-service \
--no-cli-pager \
--region "$AWS_REGION" \
--cluster "$ECS_CLUSTER" \
--service "$IHE_OUTBOUND_ECS_SERVICE" \
--force-new-deployment
21 changes: 21 additions & 0 deletions packages/node-multiple-ports/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3"
services:
ihe-gateway:
build:
context: .
dockerfile: Dockerfile
args:
# Update this if you're trying to run it on a different platform
PLATFORM: "linux/arm64"
restart: on-failure
ports:
- "8443:8443"
- "8080:8080"
- "8081:8081"
- "8082:8082"
- "8083:8083"
- "8084:8084"
- "8085:8085"
- "8086:8086"
- "9091:9091"
- "9092:9092"
Loading
Loading