Example: REST
Let's expand on the Basic example with a REST service. The code below describes a minimal implementation of the domain logic and infrastructure as code to implement a REST service.
Domain Logic (Source Code)
You should consider using a private NPM registry or implementing more creative solutions such as extending base Docker images with
ADD
|COPY
statements for source code or npm link
for your domain logic.Infrastructure
Dockerfile
FROM fnalabs/hive-base-js:latest
RUN npm install hive-io-rest-exampledocker-compose.yml
version: '3.5'
services:
hive-base-js:
build: .
image: hive-base-js:production
container_name: hive-base-js
environment:
ACTOR: ContentActor
ACTOR_LIB: hive-io-rest-example
ACTOR_URLS: "/contents,/contents/:id"
CLUSTER_SIZE: 1
HTTP_VERSION: 1
SECURE: "false"
TELEMETRY: "true"
TELEMETRY_URL_METRICS: "http://collector:55681/v1/metrics"
TELEMETRY_URL_TRACES: "http://collector:55681/v1/trace"
MONGO_URL: 'mongodb://mongo:27017/content'
depends_on:
- collector
- mongo
ports:
- 80:3000
networks:
- hive-io
mongo:
image: mongo:4.4.2
container_name: mongo
networks:
- hive-io
restart: on-failure
# telemetry
# NOTE: you will need to provide a configuration for the collector
# see https://github.com/fnalabs/hive-io/blob/master/dev/collector/collector-config.yml
collector:
image: otel/opentelemetry-collector:0.16.0
container_name: collector
command: ["--config=/conf/collector-config.yml", "--log-level=ERROR"]
depends_on:
- zipkin
networks:
- hive-io
restart: on-failure
zipkin:
image: openzipkin/zipkin:2.23.1
container_name: zipkin
ports:
- 9411:9411
networks:
- hive-io
restart: on-failure
# networking
networks:
hive-io:
driver: bridge