Alex Mikhalev
7 years ago
23 changed files with 161 additions and 82 deletions
@ -1,13 +1,32 @@
@@ -1,13 +1,32 @@
|
||||
FROM node:alpine |
||||
FROM node:alpine as builder |
||||
|
||||
RUN apk add yarn \ |
||||
python \ |
||||
make \ |
||||
g++ |
||||
|
||||
WORKDIR /app/ |
||||
|
||||
COPY package.json yarn.lock /app/ |
||||
RUN yarn install --frozen-lockfile |
||||
|
||||
RUN npm install --global yarn |
||||
COPY tslint.json /app |
||||
COPY app/ /app/app |
||||
COPY common/ /app/common |
||||
COPY server/ /app/server |
||||
|
||||
RUN yarn build |
||||
|
||||
RUN yarn install --frozen-lockfile --production |
||||
|
||||
FROM node:alpine |
||||
|
||||
ADD package.json yarn.lock /app/ |
||||
WORKDIR /app/ |
||||
RUN yarn install --production |
||||
|
||||
ADD dist/ /app/dist |
||||
ADD public/ /app/public |
||||
COPY --from=builder /app/package.json /app/yarn.lock ./ |
||||
COPY --from=builder /app/node_modules ./node_modules |
||||
COPY --from=builder /app/dist ./dist |
||||
COPY --from=builder /app/public ./public |
||||
|
||||
EXPOSE 8080 |
||||
ENTRYPOINT [ "npm", "run", "start" ] |
||||
|
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash |
||||
|
||||
set -e |
||||
|
||||
IMAGE_NAME="amikhalev/sprinklers3" |
||||
BUILD_IMAGE="$IMAGE_NAME:build" |
||||
DIST_IMAGE="$IMAGE_NAME:dist" |
||||
EXTRACT_CONTAINER="extract-$RANDOM" |
||||
BUILD_DIR="." |
||||
|
||||
echo "Cleaning build files" |
||||
rm -rf ./build ./dist ./public |
||||
|
||||
echo "Building build image $BUILD_IMAGE" |
||||
docker build -t "$BUILD_IMAGE" --target builder . |
||||
|
||||
echo "Extracting build image using container $EXTRACT_CONTAINER" |
||||
mkdir -p ./build |
||||
cp package.json yarn.lock "$BUILD_DIR" |
||||
docker container create --name "$EXTRACT_CONTAINER" "$BUILD_IMAGE" |
||||
docker container cp "$EXTRACT_CONTAINER:/app/dist" "$BUILD_DIR/dist" |
||||
docker container cp "$EXTRACT_CONTAINER:/app/public" "$BUILD_DIR/public" |
||||
docker container rm -f "$EXTRACT_CONTAINER" |
||||
|
||||
echo "Building dist image $DIST_IMAGE" |
||||
docker build -t "$DIST_IMAGE" . |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
import { update } from "serializr"; |
||||
|
||||
import * as s from "@common/sprinklersRpc"; |
||||
import * as schema from "@common/sprinklersRpc/schema"; |
||||
|
||||
export class MqttProgram extends s.Program { |
||||
onMessage(payload: string, topic: string | undefined) { |
||||
if (topic === "running") { |
||||
this.running = (payload === "true"); |
||||
} else if (topic == null) { |
||||
this.updateFromJSON(JSON.parse(payload)); |
||||
} |
||||
} |
||||
|
||||
updateFromJSON(json: any) { |
||||
update(schema.program, this, json); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
import { update } from "serializr"; |
||||
|
||||
import * as s from "@common/sprinklersRpc"; |
||||
import * as schema from "@common/sprinklersRpc/schema"; |
||||
|
||||
export class MqttSection extends s.Section { |
||||
onMessage(payload: string, topic: string | undefined) { |
||||
if (topic === "state") { |
||||
this.state = (payload === "true"); |
||||
} else if (topic == null) { |
||||
this.updateFromJSON(JSON.parse(payload)); |
||||
} |
||||
} |
||||
|
||||
updateFromJSON(json: any) { |
||||
update(schema.section, this, json); |
||||
} |
||||
} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
import { update } from "serializr"; |
||||
|
||||
import * as s from "@common/sprinklersRpc"; |
||||
import * as schema from "@common/sprinklersRpc/schema"; |
||||
|
||||
export class MqttSectionRunner extends s.SectionRunner { |
||||
onMessage(payload: string) { |
||||
this.updateFromJSON(JSON.parse(payload)); |
||||
} |
||||
|
||||
updateFromJSON(json: any) { |
||||
update(schema.sectionRunner, this, json); |
||||
} |
||||
} |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
version: "3" |
||||
services: |
||||
web: |
||||
image: "amikhalev/sprinklers3" |
||||
build: . |
||||
ports: |
||||
- "8080:8080" |
||||
env_file: |
||||
- .env |
||||
environment: |
||||
- PORT=8080 |
||||
- TYPEORM_CONNECTION=postgres |
||||
- TYPEORM_HOST=database |
||||
- TYPEORM_DATABASE=postgres |
||||
- TYPEORM_USERNAME=postgres |
||||
- TYPEORM_PASSWORD=8JN4w0UsN5dbjMjNvPe452P2yYOqg5PV |
||||
# Must specify JWT_SECRET and MQTT_URL |
||||
|
||||
database: |
||||
image: "postgres:11-alpine" |
||||
environment: |
||||
- POSTGRES_PASSWORD=8JN4w0UsN5dbjMjNvPe452P2yYOqg5PV |
Loading…
Reference in new issue