Skip to content

Commit

Permalink
Merge pull request #121 from friday-ai/docker
Browse files Browse the repository at this point in the history
Big project update
  • Loading branch information
MathieuAndrade authored Mar 25, 2024
2 parents d4c02cb + 712fb2f commit 41a17e8
Show file tree
Hide file tree
Showing 198 changed files with 4,474 additions and 3,718 deletions.
34 changes: 34 additions & 0 deletions .docker/Dockerfile-development
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Base image node ----------------------------------------
FROM node:18-alpine as base

# System dependencies
RUN apk add --no-cache sqlite make python3 gcc g++ \
&& npm install -g pnpm@8 turbo

USER node
WORKDIR /src

RUN pnpm config set store-dir .pnpm-store && pnpm config set node-linker hoisted

# Friday builder image -----------------------------------
FROM base as builder

HEALTHCHECK --interval=1s --retries=3600 \
CMD test -f ./task_finished.txt || exit 1

# Start container
CMD pnpm install && turbo build && touch task_finished.txt && sleep 4s

# Friday server image -------------------------------------
FROM base as server

# Start container
EXPOSE 3001
CMD pnpm start:dev

# Friday front image -------------------------------------
FROM base as front

# Start container
EXPOSE 3001
CMD pnpm start:dev
62 changes: 62 additions & 0 deletions .docker/Dockerfile-production
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# base image node ----------------------------------------
FROM node:18-alpine as base

# System dependencies
RUN apk add --no-cache curl

WORKDIR /src

CMD npm run start:prod

# builder ------------------------------------------------
FROM base as builder

# System dependencies
RUN apk add --no-cache sqlite make

# Builder dependencies
RUN npm install -g pnpm@8 turbo

WORKDIR /usr/src

COPY ../pnpm-lock.yaml ./
COPY ../*.npmrc ./

COPY ../ ./

RUN pnpm fetch \
&& pnpm install -r \
&& turbo build

# Friday front -------------------------------------------
FROM base as front

# Front dependencies
RUN npm install -g http-server

# Add friday core
COPY --from=builder /usr/src/apps/front/dist ./dist

COPY ../apps/front/package.json ./

ENV NODE_ENV production

# Export listening port
EXPOSE 1444

# Friday back ------------------------------------------
FROM base as server

# Server dependencies
RUN npm install mqtt sqlite3 ssh2
RUN npm install -g cross-env

# Add friday core
COPY --from=builder /usr/src/apps/server/dist ./dist

COPY ../apps/server/package.json ./

ENV NODE_ENV production

# Export listening port
EXPOSE 1443
80 changes: 80 additions & 0 deletions .docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
version: "3.9"

services:
builder:
container_name: builder-dev
image: fridayai/friday-builder:dev
build:
context: ../
dockerfile: ./.docker/Dockerfile-development
target: builder
restart: on-failure
volumes:
- ../.pnpm-store:/src/.pnpm-store
- ../apps:/src/apps
- ../packages:/src/packages
- ../package.json:/src/package.json
- ../pnpm-lock.yaml:/src/pnpm-lock.yaml
- ../pnpm-workspace.yaml:/src/pnpm-workspace.yaml
- ../node_modules:/src/node_modules

server:
container_name: server-dev
image: fridayai/friday-server:dev
build:
context: ../
dockerfile: ./.docker/Dockerfile-development
target: server
depends_on:
builder:
condition: service_healthy
ports:
- "3000:3000"
environment:
- NODE_ENV=development
- MQTT_HOST=host.docker.internal
volumes:
- ../.pnpm-store:/src/.pnpm-store
- ../apps/server:/src/apps/server
- ../packages:/src/packages
- ../package.json:/src/package.json
- ../pnpm-lock.yaml:/src/pnpm-lock.yaml
- ../pnpm-workspace.yaml:/src/pnpm-workspace.yaml
- ../node_modules:/src/node_modules

front:
container_name: front-dev
image: fridayai/friday-front:dev
build:
context: ../
dockerfile: ./.docker/Dockerfile-development
target: front
depends_on:
builder:
condition: service_healthy
ports:
- "3001:3001"
environment:
- NODE_ENV=development
volumes:
- ../.pnpm-store:/src/.pnpm-store
- ../apps/front:/src/apps/front
- ../packages:/src/packages
- ../package.json:/src/package.json
- ../pnpm-lock.yaml:/src/pnpm-lock.yaml
- ../pnpm-workspace.yaml:/src/pnpm-workspace.yaml
- ../node_modules:/src/node_modules

broker:
container_name: broker-dev
image: eclipse-mosquitto:latest
restart: always
ports:
- "1883:1883"
- "9001:9001"
volumes:
- ../.docker/mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf
- ../.docker/mosquitto/data:/mosquitto/data
environment:
- TZ=Europe/Paris
user: 1000:1000
51 changes: 51 additions & 0 deletions .docker/docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: "3.9"

services:
server:
container_name: friday-server
image: fridayai/friday-server:latest
build:
context: ../
dockerfile: ./.docker/Dockerfile-production
target: server
ports:
- "1443:1443"
environment:
- NODE_ENV=production
- MQTT_HOST=host.docker.internal

front:
container_name: friday-front
image: fridayai/friday-front:latest
build:
context: ../
dockerfile: ./.docker/Dockerfile-production
target: front
depends_on:
- server
ports:
- "1444:1444"
environment:
- NODE_ENV=production

broker:
container_name: friday-broker
image: eclipse-mosquitto:latest
restart: always
ports:
- "1883:1883"
- "9001:9001"
volumes:
- ../.docker/mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf
- ../.docker/mosquitto/data:/mosquitto/data
environment:
- TZ=Europe/Paris
user: 1000:1000

watchtower:
container_name: friday-watchtower
image: containrrr/watchtower
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: --cleanup
File renamed without changes.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ node.d.ts
.git
docker
.github
.pnpm-store
node_modules
lib
dist
.turbo
1 change: 0 additions & 1 deletion .env

This file was deleted.

10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This configuration only applies to the package manager root.
/** @type {import("eslint").Linter.Config} */
module.exports = {
ignorePatterns: ["apps/**", "packages/**"],
extends: ["@friday-ai/tools/eslint/base.js"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
},
};
16 changes: 12 additions & 4 deletions .github/actions/prepare-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ author: "MathieuAndrade"
inputs:
node-version:
description: Version of Node to use
default: 18.x
default: 20.x

pnpm-version:
description: Version of pnpm to use
Expand All @@ -27,12 +27,12 @@ runs:
using: composite
steps:
- name: 📦 Setup pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v3
with:
version: ${{ inputs.pnpm-version }}

- name: 📦 Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: pnpm
Expand All @@ -41,12 +41,20 @@ runs:
run: pnpm install -r --frozen-lockfile --strict-peer-dependencies
shell: bash

- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: 📦 Build
if: ${{ inputs.build == 'true' }}
run: |
if echo ${{ inputs.build-only-packages }}
then
pnpm -r --filter "./packages/*" build
pnpm build:packages
else
${{ inputs.build-command }}
fi
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ jobs:
files: ./apps/server/test-results.xml

- name: ⬆️ Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
if: always()
with:
directory: ./apps/server/
token: ${{ secrets.CODECOV_TOKEN }}
Loading

0 comments on commit 41a17e8

Please sign in to comment.