Skip to content

Commit fd3b1fb

Browse files
authored
Feat/local-plugin (#1125)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit • New Features  - Enhanced the login experience with improved session management and two-factor authentication.  - Introduced a comprehensive README for the Unraid Plugin Builder, detailing development workflows and commands. • Chores  - Streamlined build, packaging, and deployment processes with updated dependency and environment configurations.  - Updated Docker configurations to support pnpm as the package manager.  - Added new environment variables for better configuration management.  - Introduced new scripts for improved build and packaging processes. • Tests  - Removed outdated test cases and simplified test setups. • Refactor  - Modernized internal code structure and asynchronous handling for improved overall performance.  - Transitioned imports from lodash to lodash-es for better module handling.  - Updated environment variable management and configuration settings.  - Enhanced the build script for improved deployment processes.  - Updated the notification handling structure to improve efficiency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent c154b4e commit fd3b1fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+13719
-19276
lines changed

.github/workflows/main.yml

Lines changed: 113 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -34,66 +34,106 @@ jobs:
3434
- name: Validate branch and tag
3535
run: exit 0
3636

37-
build-test-api:
37+
test-api:
38+
defaults:
39+
run:
40+
working-directory: api
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout repo
44+
uses: actions/checkout@v4
45+
- name: Install Node
46+
uses: actions/setup-node@v4
47+
with:
48+
node-version-file: "api/.nvmrc"
49+
- name: Install pnpm
50+
uses: pnpm/action-setup@v4
51+
with:
52+
version: 8
53+
run_install: false
54+
- name: Get pnpm store directory
55+
id: pnpm-cache
56+
shell: bash
57+
run: |
58+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
59+
- uses: actions/cache@v4
60+
name: Setup pnpm cache
61+
with:
62+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
63+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('api/pnpm-lock.yaml') }}
64+
restore-keys: |
65+
${{ runner.os }}-pnpm-store-
66+
67+
- name: PNPM Install
68+
run: pnpm install
69+
70+
- name: Lint
71+
run: pnpm run lint
72+
73+
- name: Test
74+
run: pnpm run coverage
75+
76+
build-api:
3877
name: Build and Test API
3978
runs-on: ubuntu-latest
4079
defaults:
4180
run:
4281
working-directory: api
43-
outputs:
44-
API_VERSION: ${{ steps.vars.outputs.API_VERSION }}
45-
API_MD5: ${{ steps.set-hashes.outputs.API_MD5 }}
46-
API_SHA256: ${{ steps.set-hashes.outputs.API_SHA256 }}
4782
steps:
4883
- name: Checkout repo
4984
uses: actions/checkout@v4
50-
- name: Build with Buildx
51-
uses: docker/setup-buildx-action@v3
85+
86+
- name: Install Node
87+
uses: actions/setup-node@v4
5288
with:
53-
install: true
54-
platforms: linux/amd64
55-
- name: Build Builder
56-
uses: docker/build-push-action@v6
89+
node-version-file: "api/.nvmrc"
90+
91+
- uses: pnpm/action-setup@v4
92+
name: Install pnpm
5793
with:
58-
context: ./api
59-
push: false
60-
tags: builder:latest
61-
cache-from: type=gha,ref=builder:latest
62-
cache-to: type=gha,mode=max,ref=builder:latest
63-
load: true
64-
- name: Lint inside of the docker container
65-
continue-on-error: false
66-
run: |
67-
docker run --rm builder npm run lint
94+
version: 8
95+
run_install: false
6896

69-
- name: Test inside of the docker container
97+
- name: Get pnpm store directory
98+
id: pnpm-cache
99+
shell: bash
70100
run: |
71-
git fetch --depth=2 origin main
72-
if git diff --name-only --relative=api origin/main HEAD | grep -q '.'; then
73-
docker run --rm builder npm run coverage
74-
else
75-
echo "No changes in /api folder, skipping coverage."
76-
fi
101+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
102+
103+
- uses: actions/cache@v4
104+
name: Setup pnpm cache
105+
with:
106+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
107+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('api/pnpm-lock.yaml') }}
108+
restore-keys: |
109+
${{ runner.os }}-pnpm-store-
110+
111+
- name: Cache APT Packages
112+
uses: awalsh128/cache-apt-pkgs-action@v1.4.3
113+
with:
114+
packages: bash procps python3 libvirt-dev jq zstd git build-essential
115+
version: 1.0
116+
117+
- name: PNPM Install
118+
run: pnpm install
119+
120+
- name: Lint
121+
run: pnpm run lint
122+
123+
- name: Build
124+
run: pnpm run build
125+
77126
- name: Get Git Short Sha and API version
78127
id: vars
79128
run: |
80129
GIT_SHA=$(git rev-parse --short HEAD)
81130
IS_TAGGED=$(git describe --tags --abbrev=0 --exact-match || echo '')
82-
PACKAGE_LOCK_VERSION=$(jq -r '.version' package-lock.json)
83-
echo "GIT_SHA=$GIT_SHA" >> $GITHUB_OUTPUT
84-
echo "IS_TAGGED=$IS_TAGGED" >> $GITHUB_OUTPUT
85-
echo "PACKAGE_LOCK_VERSION=$PACKAGE_LOCK_VERSION" >> $GITHUB_OUTPUT
86-
echo "API_VERSION=$([[ -n "$IS_TAGGED" ]] && echo "$PACKAGE_LOCK_VERSION" || echo "${PACKAGE_LOCK_VERSION}+${GIT_SHA}")" >> $GITHUB_OUTPUT
87-
- name: Build inside of the docker container
88-
id: build-pack-binary
89-
run: |
90-
docker run --rm -v ${{ github.workspace }}/api/deploy/release:/app/deploy/release -e API_VERSION=${{ steps.vars.outputs.API_VERSION }} builder npm run build-and-pack
91-
92-
- name: Set Hashes
93-
id: set-hashes
94-
run: |
95-
echo "API_MD5=$(md5sum ${{ github.workspace }}/api/deploy/release/*.tgz | awk '{ print $1 }')" >> $GITHUB_OUTPUT
96-
echo "API_SHA256=$(sha256sum ${{ github.workspace }}/api/deploy/release/*.tgz | awk '{ print $1 }')" >> $GITHUB_OUTPUT
131+
PACKAGE_LOCK_VERSION=$(jq -r '.version' package.json)
132+
API_VERSION=$([[ -n "$IS_TAGGED" ]] && echo "$PACKAGE_LOCK_VERSION" || echo "${PACKAGE_LOCK_VERSION}+${GIT_SHA}")
133+
export API_VERSION
134+
135+
- name: Build
136+
run: pnpm run build-and-pack
97137

98138
- name: Upload tgz to Github artifacts
99139
uses: actions/upload-artifact@v4
@@ -187,7 +227,7 @@ jobs:
187227
path: web/.nuxt/nuxt-custom-elements/dist/unraid-components
188228

189229
build-plugin:
190-
needs: [build-test-api, build-web, build-unraid-ui-webcomponents]
230+
needs: [build-api, build-web, build-unraid-ui-webcomponents]
191231
defaults:
192232
run:
193233
working-directory: plugin
@@ -201,38 +241,42 @@ jobs:
201241
uses: actions/checkout@v4
202242
with:
203243
fetch-depth: 0
204-
- name: Build with Buildx
205-
uses: docker/setup-buildx-action@v3
206-
with:
207-
install: true
208-
platforms: linux/amd64
209-
- name: Build Builder
210-
uses: docker/build-push-action@v6
244+
- name: Install node
245+
uses: actions/setup-node@v4
211246
with:
212-
context: ./plugin
213-
push: false
214-
tags: plugin-builder:latest
215-
cache-from: type=gha,ref=plugin-builder:latest
216-
cache-to: type=gha,mode=max,ref=plugin-builder:latest
217-
load: true
247+
cache: "npm"
248+
cache-dependency-path: |
249+
plugin/package-lock.json
250+
node-version-file: ".nvmrc"
251+
- name: Install dependencies
252+
run: npm ci
218253
- name: Download Unraid Web Components
219254
uses: actions/download-artifact@v4
220255
with:
221256
pattern: unraid-wc-*
222257
path: ./plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components
223258
merge-multiple: true
224-
- name: Build Plugin
259+
- name: Download Unraid API
260+
uses: actions/download-artifact@v4
261+
with:
262+
name: unraid-api
263+
path: /tmp/unraid-api/
264+
- name: Extract Unraid API and Build Plugin
225265
run: |
226-
echo "API_VERSION=${{needs.build-test-api.outputs.API_VERSION}}" > .env
227-
echo "API_SHA256=${{needs.build-test-api.outputs.API_SHA256}}" >> .env
228-
echo "PR=${{ github.event.pull_request.number }}" >> .env
229-
npm run start
266+
tar -xzf /tmp/unraid-api/unraid-api.tgz -C ${{ github.workspace }}/plugin/source/dynamix.unraid.net/usr/local/unraid-api
267+
cd ${{ github.workspace }}/plugin
268+
269+
if [ -n "${{ github.event.pull_request.number }}" ]; then
270+
export TAG=PR${{ github.event.pull_request.number }}
271+
fi
272+
273+
npm run build
230274
- name: Upload binary txz and plg to Github artifacts
231275
uses: actions/upload-artifact@v4
232276
with:
233277
name: connect-files
234278
path: |
235-
plugin/deploy/release/plugins/*.plg
279+
plugin/deploy/release/plugins/
236280
plugin/deploy/release/archive/*.txz
237281
retention-days: 5
238282
if-no-files-found: error
@@ -241,20 +285,14 @@ jobs:
241285
if: |
242286
github.event_name == 'pull_request'
243287
runs-on: ubuntu-latest
244-
needs: [build-plugin]
288+
needs: [test-api, build-plugin]
245289
steps:
246290
- name: Checkout repo
247291
uses: actions/checkout@v4
248292

249293
- name: Make PR Release Folder
250294
run: mkdir pr-release/
251295

252-
- name: Download unraid-api binary tgz
253-
uses: actions/download-artifact@v4
254-
with:
255-
name: unraid-api
256-
path: pr-release
257-
258296
- name: Download plugin binary tgz
259297
uses: actions/download-artifact@v4
260298
with:
@@ -263,7 +301,7 @@ jobs:
263301
- name: Copy other release files to pr-release
264302
run: |
265303
cp archive/*.txz pr-release/
266-
cp plugins/dynamix.unraid.net.pr.plg pr-release/dynamix.unraid.net.plg
304+
cp plugins/pr/dynamix.unraid.net.plg pr-release/dynamix.unraid.net.plg
267305
268306
- name: Upload to Cloudflare
269307
uses: jakejarvis/s3-sync-action@v0.5.1
@@ -293,7 +331,7 @@ jobs:
293331
# Only release if this is a push to the main branch
294332
if: startsWith(github.ref, 'refs/heads/main')
295333
runs-on: ubuntu-latest
296-
needs: [build-plugin]
334+
needs: [test-api, build-plugin]
297335

298336
steps:
299337
- name: Checkout repo
@@ -302,12 +340,6 @@ jobs:
302340
- name: Make Staging Release Folder
303341
run: mkdir staging-release/
304342

305-
- name: Download unraid-api binary tgz
306-
uses: actions/download-artifact@v4
307-
with:
308-
name: unraid-api
309-
path: staging-release
310-
311343
- name: Download plugin binary tgz
312344
uses: actions/download-artifact@v4
313345
with:
@@ -316,7 +348,7 @@ jobs:
316348
- name: Copy Files for Staging Release
317349
run: |
318350
cp archive/*.txz staging-release/
319-
cp plugins/dynamix.unraid.net.staging.plg staging-release/dynamix.unraid.net.plg
351+
cp plugins/staging/dynamix.unraid.net.plg staging-release/dynamix.unraid.net.plg
320352
ls -al staging-release
321353
322354
- name: Upload Staging Plugin to Cloudflare Bucket
@@ -335,17 +367,11 @@ jobs:
335367
if: |
336368
startsWith(github.ref, 'refs/tags/v')
337369
runs-on: ubuntu-latest
338-
needs: [build-plugin]
339-
370+
needs: [test-api, build-plugin]
340371
steps:
341372
- name: Checkout repo
342373
uses: actions/checkout@v4
343374

344-
- name: Download unraid-api binary tgz
345-
uses: actions/download-artifact@v4
346-
with:
347-
name: unraid-api
348-
349375
- name: Download plugin binary tgz
350376
uses: actions/download-artifact@v4
351377
with:
@@ -355,7 +381,7 @@ jobs:
355381
run: |
356382
mkdir -p release/
357383
mv unraid-api-*.tgz release/
358-
mv plugins/dynamix.unraid.net.plg release/
384+
mv plugins/production/dynamix.unraid.net.plg release/
359385
mv archive/* release/
360386
361387
- name: Create Github release

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,6 @@ deploy/*
9292
!.env.example
9393

9494
fb_keepalive
95+
96+
# pnpm store
97+
.pnpm-store

api/.env.test

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
VERSION="THIS_WILL_BE_REPLACED_WHEN_BUILT"
2-
31
PATHS_UNRAID_DATA=./dev/data # Where we store plugin data (e.g. permissions.json)
42
PATHS_STATES=./dev/states # Where .ini files live (e.g. vars.ini)
3+
PATHS_AUTH_SESSIONS=./dev/sessions # Where user sessions live
4+
PATHS_AUTH_KEY=./dev/keys # Auth key directory
55
PATHS_DYNAMIX_BASE=./dev/dynamix # Dynamix's data directory
6+
PATHS_DYNAMIX_CONFIG_DEFAULT=./dev/dynamix/default.cfg # Dynamix's default config file, which ships with unraid
67
PATHS_DYNAMIX_CONFIG=./dev/dynamix/dynamix.cfg # Dynamix's config file
78
PATHS_MY_SERVERS_CONFIG=./dev/Unraid.net/myservers.cfg # My servers config file
89
PATHS_MY_SERVERS_FB=./dev/Unraid.net/fb_keepalive # My servers flashbackup timekeeper file
910
PATHS_KEYFILE_BASE=./dev/Unraid.net # Keyfile location
11+
PATHS_MACHINE_ID=./dev/data/machine-id
1012
PORT=5000
11-
NODE_ENV=test
13+
NODE_ENV="test"

api/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,5 @@ deploy/*
8080

8181
# IDE Settings Files
8282
.idea
83+
84+
!**/*.login.*

api/.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node-linker=hoisted
2+
shamefully-hoist=true

api/Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ WORKDIR /app
1919

2020
# Set app env
2121
ENV NODE_ENV=development
22+
ENV PNPM_HOME="/pnpm"
23+
ENV PATH="$PNPM_HOME:$PATH"
2224

23-
COPY tsconfig.json .eslintrc.ts .prettierrc.cjs .npmrc .env.production .env.staging ./
25+
# Install pnpm
26+
RUN corepack enable && corepack prepare pnpm@8.15.4 --activate && npm i -g npm@latest
2427

25-
COPY package.json package-lock.json ./
28+
COPY tsconfig.json .eslintrc.ts .prettierrc.cjs .npmrc .env.production .env.staging package.json pnpm-lock.yaml .npmrc ./
2629

2730
# Install deps
28-
RUN npm i
31+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install
2932

30-
EXPOSE 4000
33+
EXPOSE 3001
3134

3235
###########################################################
3336
# Builder Image
@@ -39,4 +42,4 @@ ENV NODE_ENV=production
3942

4043
COPY . .
4144

42-
CMD ["npm", "run", "build-and-pack"]
45+
CMD ["pnpm", "run", "build-and-pack"]

0 commit comments

Comments
 (0)