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

chore: Use yarn workspaces & add Turborepo #1369

Merged
merged 1 commit into from
Dec 5, 2024
Merged
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
8 changes: 6 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
node_modules
.yarn
**/node_modules/
.git
data/
server/dist
ui/.next
Dockerfile
**/*.md
35 changes: 35 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Code quality checks

on:
pull_request:
branches: [main]

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
formatting:
name: Formatting
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Activate corepack
run: |
corepack install
corepack enable
- name: Install dependencies
run: yarn --immutable
- name: Check formatting
run: yarn turbo format:check
2 changes: 1 addition & 1 deletion .github/workflows/run_jest_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
run: yarn --immutable

- name: Run tests
run: yarn test
run: yarn turbo test
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
data/
docs-output/
node_modules
.yarn
.idea
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
.idea
.turbo
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.preferences.importModuleSpecifier": "relative",
"files.associations": {
"globals.css": "tailwindcss"
},
}
}
}
934 changes: 934 additions & 0 deletions .yarn/releases/yarn-4.5.1.cjs

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
nodeLinker: node-modules
# yarnPath: .yarn/releases/yarn-4.0.2.cjs
enableGlobalCache: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.5.1.cjs
29 changes: 14 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ All help is welcome and greatly appreciated! If you would like to contribute to
### Tools Required

- HTML/Typescript/Javascript editor
- [VSCode](https://code.visualstudio.com/) is recommended. Upon opening the project, a few extensions will be automatically recommended for install.
- [VSCode](https://code.visualstudio.com/) is recommended. Upon opening the project, a few extensions will be automatically recommended for install.
- [NodeJS](https://nodejs.org/en/download/) (Node 20.x or higher)
- [Git](https://git-scm.com/downloads)

Expand Down Expand Up @@ -43,35 +43,34 @@ All help is welcome and greatly appreciated! If you would like to contribute to
- `docs`
- `feature`
- `fix`
- `patch`
- `patch`

4. Activate the correct Yarn version. (*Note: In order to run `corepack enable`, you will need to be running cmd or Powershell as an Administrator.*)
4. Activate the correct Yarn version. (_Note: In order to run `corepack enable`, you will need to be running cmd or PowerShell as an Administrator._)

```bash
```bash
corepack install
corepack enable
```

5. Install dependencies

```bash
yarn
```bash
yarn
```

6. As of Maintainerr v2.0, the project looks to ensure you have read/write permissions on the `data` directory. This `data` directory does not exist when you first clone your fork. Before running the below commands, create a folder inside of your main Maintainerr directory named `data`, and ensure it has full permissions to the `Everyone` user.

```bash
example -> C:\Users\You\Documents\GitRepos\Maintainerr\data
```
```bash
example -> C:\Users\You\Documents\GitRepos\Maintainerr\data
```

7. Run the development commands (you will need two different cmd/Powershell terminals. One for each command.)
7. Run the development command

```bash
yarn dev:server
yarn dev:ui
yarn dev
```

- If the build fails with Powershell, try to use cmd instead.
- If the build fails with PowerShell, try to use cmd instead.

8. Make your code changes/improvements and test that they work as intended.

Expand All @@ -94,8 +93,8 @@ All help is welcome and greatly appreciated! If you would like to contribute to
- Always rebase your commit to the latest `main` branch. Do **not** merge `main` into your branch.
- It is your responsibility to keep your branch up-to-date. Your work will **not** be merged unless it is rebased off the latest `main` branch.
- You can create a "draft" pull request early to get feedback on your work.
- Your code **must** be formatted correctly, or the tests will fail.
- We use Prettier to format our code base. It should automatically run with a Git hook, but it is recommended to have the Prettier extension installed in your editor and format on save.
- Your code **must** be formatted correctly.
- We use Prettier to format our code base. It is recommended to have the Prettier extension installed in your editor and format on save.
- If you have questions or need help, you can reach out via [Discussions](https://github.com/jorenn92/Maintainerr/discussions) or our [Discord server](https://discord.gg/WP4ZW2QYwk).

### UI Text Style
Expand Down
108 changes: 33 additions & 75 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,70 +1,54 @@
FROM node:20-alpine3.19 AS builder
FROM node:20-alpine3.19 AS base
LABEL Description="Contains the Maintainerr Docker image"

WORKDIR /opt/app/
FROM base AS builder

ARG TARGETPLATFORM
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}
WORKDIR /app

COPY server/ ./server/
COPY ui/ ./ui/
COPY package.json ./package.json
COPY yarn.lock ./yarn.lock
COPY .yarnrc.yml ./.yarnrc.yml

# Enable correct yarn version
RUN corepack install && \
corepack enable

RUN apk --update --no-cache add python3 make g++ curl

RUN yarn --immutable --network-timeout 99999999

RUN \
case "${TARGETPLATFORM}" in ('linux/arm64' | 'linux/amd64') \
yarn add sharp \
;; \
esac

RUN yarn build:server
RUN yarn global add turbo@^2
COPY . .

RUN yarn install --network-timeout 99999999
RUN yarn cache clean

RUN <<EOF cat >> ./ui/.env
NEXT_PUBLIC_BASE_PATH=/__PATH_PREFIX__
EOF

RUN sed -i "s,basePath: '',basePath: '/__PATH_PREFIX__',g" ./ui/next.config.js

RUN yarn build:ui
RUN yarn turbo build

# copy standalone UI
RUN mv ./ui/.next/standalone/ui/ ./standalone-ui/ && \
mv ./ui/.next/standalone/ ./standalone-ui/ && \
mv ./ui/.next/static ./standalone-ui/.next/static && \
mv ./ui/public ./standalone-ui/public && \
rm -rf ./ui && \
mv ./standalone-ui ./ui
FROM base AS runner

# Copy standalone server
RUN mv ./server/dist ./standalone-server && \
rm -rf ./server && \
mv ./standalone-server ./server
WORKDIR /opt/app

RUN rm -rf node_modules .yarn
# copy standalone UI
COPY --from=builder --chmod=777 --chown=node:node /app/ui/.next/standalone/ui ./ui
COPY --from=builder --chmod=777 --chown=node:node /app/ui/.next/static ./ui/.next/static
COPY --from=builder --chmod=777 --chown=node:node /app/ui/public ./ui/public

RUN yarn workspaces focus --production
# Copy standalone server
COPY --from=builder --chmod=777 --chown=node:node /app/server/dist ./server
COPY --from=builder --chmod=777 --chown=node:node /app/server/node_modules ./server/node_modules

RUN rm -rf .yarn && \
rm -rf /opt/yarn-* && \
chown -R node:node /opt/ && \
chmod -R 755 /opt/ && \
# Data dir
mkdir -m 777 /opt/data && \
COPY docker/supervisord.conf /etc/supervisord.conf
COPY --chmod=777 --chown=node:node docker/start.sh /opt/app/start.sh

# Create required directories
RUN mkdir -m 777 /opt/data && \
mkdir -m 777 /opt/data/logs && \
chown -R node:node /opt/data

# Final build
FROM node:20-alpine3.19
# This is required for docker user directive to work
RUN chmod 777 /opt/app/start.sh && \
chmod 777 /opt/app/ui && \
chmod 777 /opt/app/ui/public && \
chmod 777 /opt/app/ui/.next/static && \
mkdir -m 777 /opt/app/ui/.next/cache && \
chown -R node:node /opt/app/ui/.next/cache

RUN apk --update --no-cache add curl supervisor

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
Expand All @@ -85,46 +69,20 @@ ENV UI_HOSTNAME=${UI_HOSTNAME}
ARG GIT_SHA
ENV GIT_SHA=$GIT_SHA

ENV DATA_DIR=/opt/data

# container version type. develop, stable, edge,.. a release=stable
ARG VERSION_TAG=develop
ENV VERSION_TAG=$VERSION_TAG

ARG BASE_PATH
ENV BASE_PATH=${BASE_PATH}

# Set global yarn vars to a folder read/write able for all users
ENV YARN_INSTALL_STATE_PATH=/tmp/.yarn/install-state.gz
ENV YARN_GLOBAL_FOLDER=/tmp/.yarn/global
ENV YARN_CACHE_FOLDER=/tmp/.yarn/cache

# Temporary workaround for https://github.com/libuv/libuv/pull/4141
ENV UV_USE_IO_URING=0

COPY --from=builder --chown=node:node /opt /opt

WORKDIR /opt/app

COPY docker/supervisord.conf /etc/supervisord.conf
COPY docker/start.sh /opt/app/start.sh

# Enable correct yarn version, add supervisor & chown root /opt dir
RUN corepack install && \
corepack enable && \
apk add supervisor curl && \
chown node:node /opt && \
# This is required for docker user directive to work
chmod 777 /opt && \
chmod 777 /opt/app/start.sh && \
chmod 777 -R /opt/app/ui && \
mkdir -m 777 /.cache && \
mkdir -pm 777 /opt/app/ui/.next/cache && \
chown -R node:node /opt/app/ui/.next/cache

USER node

# Picked up for Node's .cache directory.
ENV HOME=/

EXPOSE 6246

VOLUME [ "/opt/data" ]
Expand Down
4 changes: 2 additions & 2 deletions docker/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile=/dev/null
pidfile=/dev/null

[program:server]
command=yarn node /opt/app/server/main.js
command=node /opt/app/server/main.js
autorestart=true
startretries=100
stdout_logfile=/dev/fd/1
Expand All @@ -13,7 +13,7 @@ redirect_stderr=true

[program:ui]
environment=PORT=%(ENV_UI_PORT)s,HOSTNAME=%(ENV_UI_HOSTNAME)s
command=yarn node /opt/app/ui/server.js
command=node /opt/app/ui/server.js
autorestart=true
startretries=100
stdout_logfile=/dev/fd/1
Expand Down
Loading
Loading