Skip to content

Commit

Permalink
feat: add Docker healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
mKeRix committed May 2, 2020
1 parent 8025011 commit a8cffec
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Expand Up @@ -8,7 +8,7 @@ FROM node:12-alpine

WORKDIR /room-assistant

RUN apk add --no-cache bluez bluez-deprecated libusb avahi-dev bind-tools dmidecode tini \
RUN apk add --no-cache bluez bluez-deprecated libusb avahi-dev bind-tools dmidecode tini curl \
&& setcap cap_net_raw+eip $(eval readlink -f `which node`) \
&& setcap cap_net_raw+eip $(eval readlink -f `which hcitool`) \
&& setcap cap_net_admin+eip $(eval readlink -f `which hciconfig`) \
Expand All @@ -17,3 +17,4 @@ COPY --from=build /usr/local/lib/node_modules/room-assistant /usr/local/lib/node

ENTRYPOINT ["tini", "--", "room-assistant"]
CMD ["--digResolver"]
HEALTHCHECK --start-period=15s CMD curl --fail http://localhost:6415/status/ || exit 1
5 changes: 3 additions & 2 deletions dev.Dockerfile
Expand Up @@ -9,12 +9,13 @@ FROM node:12-alpine

WORKDIR /room-assistant

RUN apk add --no-cache bluez bluez-deprecated libusb avahi-dev bind-tools dmidecode \
RUN apk add --no-cache bluez bluez-deprecated libusb avahi-dev bind-tools dmidecode tini curl \
&& setcap cap_net_raw+eip $(eval readlink -f `which node`) \
&& setcap cap_net_raw+eip $(eval readlink -f `which hcitool`) \
&& setcap cap_net_admin+eip $(eval readlink -f `which hciconfig`) \
&& ln -s /usr/local/lib/node_modules/room-assistant/bin/room-assistant.js /usr/local/bin/room-assistant
COPY --from=build /usr/local/lib/node_modules/room-assistant /usr/local/lib/node_modules/room-assistant

ENTRYPOINT ["room-assistant"]
ENTRYPOINT ["tini", "--", "room-assistant"]
CMD ["--digResolver"]
HEALTHCHECK --start-period=15s CMD curl --fail http://localhost:6415/status/ || exit 1
4 changes: 3 additions & 1 deletion docker-compose.yml
@@ -1,7 +1,9 @@
version: '3'
services:
room-assistant:
build: .
build:
context: .
dockerfile: dev.Dockerfile
network_mode: host
environment:
NODE_CONFIG: >
Expand Down
18 changes: 18 additions & 0 deletions src/status/status.controller.spec.ts
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { StatusController } from './status.controller';

describe('Status Controller', () => {
let controller: StatusController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [StatusController]
}).compile();

controller = module.get<StatusController>(StatusController);
});

it('should return healthy', () => {
expect(controller.health()).toEqual('healthy');
});
});
9 changes: 9 additions & 0 deletions src/status/status.controller.ts
@@ -0,0 +1,9 @@
import { Controller, Get } from '@nestjs/common';

@Controller('status')
export class StatusController {
@Get()
health(): string {
return 'healthy';
}
}
4 changes: 3 additions & 1 deletion src/status/status.module.ts
Expand Up @@ -3,9 +3,11 @@ import { StatusService } from './status.service';
import { ClusterModule } from '../cluster/cluster.module';
import { EntitiesModule } from '../entities/entities.module';
import { ConfigModule } from '../config/config.module';
import { StatusController } from './status.controller';

@Module({
imports: [ClusterModule, EntitiesModule, ConfigModule],
providers: [StatusService]
providers: [StatusService],
controllers: [StatusController]
})
export class StatusModule {}

0 comments on commit a8cffec

Please sign in to comment.