Merge pull request #960 from runtipi/release/2.2.0

Release 2.2.0
This commit is contained in:
Nicolas Meienberger 2023-11-28 22:29:01 +01:00 committed by GitHub
commit 59dbe672c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
121 changed files with 4392 additions and 1308 deletions

View file

@ -364,11 +364,38 @@
"contributions": [
"code"
]
},
{
"login": "cchalop1",
"name": "CHALOPIN Clément",
"avatar_url": "https://avatars.githubusercontent.com/u/28163855?v=4",
"profile": "http://cchalop1.com",
"contributions": [
"code"
]
},
{
"login": "geetansh",
"name": "Geetansh Jindal",
"avatar_url": "https://avatars.githubusercontent.com/u/9976198?v=4",
"profile": "https://github.com/geetansh",
"contributions": [
"code"
]
},
{
"login": "0livier",
"name": "Olivier Garcia",
"avatar_url": "https://avatars.githubusercontent.com/u/10607?v=4",
"profile": "https://github.com/0livier",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
"projectName": "runtipi",
"projectOwner": "meienberger",
"projectOwner": "runtipi",
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true,

View file

@ -11,25 +11,24 @@ jobs:
create-tag:
runs-on: ubuntu-latest
outputs:
tagname: ${{ steps.create_tag.outputs.tagname }}
tagname: ${{ steps.get_tag.outputs.tagname }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create Tag
id: create_tag
uses: butlerlogic/action-autotag@stable
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
with:
tag_prefix: 'v'
tag_suffix: '-alpha.${{ github.event.inputs.tag }}'
- name: Get tag from package.json
id: get_tag
run: |
VERSION=$(npm run version --silent)
echo "tagname=v${VERSION}-alpha.${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
build-images:
- uses: rickstaa/action-create-tag@v1
with:
tag: ${{ steps.get_tag.outputs.tagname }}
build-worker:
runs-on: ubuntu-latest
needs: create-tag
steps:
- name: Checkout code
uses: actions/checkout@v4
@ -51,7 +50,38 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
file: ./packages/worker/Dockerfile
platforms: linux/amd64
push: true
tags: ghcr.io/${{ github.repository_owner }}/worker:${{ needs.create-tag.outputs.tagname }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/worker:buildcache
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/worker:buildcache,mode=max
build-images:
runs-on: ubuntu-latest
needs: create-tag
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push images
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
push: true
tags: ghcr.io/${{ github.repository_owner }}/runtipi:${{ needs.create-tag.outputs.tagname }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/runtipi:buildcache
@ -60,7 +90,6 @@ jobs:
build-cli:
runs-on: ubuntu-latest
needs: create-tag
steps:
- name: Checkout code
uses: actions/checkout@v4
@ -107,7 +136,7 @@ jobs:
publish-release:
runs-on: ubuntu-latest
needs: [create-tag, build-images, build-cli]
needs: [create-tag, build-images, build-cli, build-worker]
steps:
- name: Download CLI
@ -116,35 +145,21 @@ jobs:
name: cli
path: cli
- name: Rename CLI
run: |
mv cli/bin/cli-x64 ./runtipi-cli-linux-x64
- name: Create alpha release
id: create_release
uses: actions/create-release@v1
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: |
**${{ needs.create-tag.outputs.tagname }}**
tag_name: ${{ needs.create-tag.outputs.tagname }}
release_name: ${{ needs.create-tag.outputs.tagname }}
name: ${{ needs.create-tag.outputs.tagname }}
draft: false
prerelease: true
- name: Upload X64 Linux CLI binary to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: cli/bin/cli-x64
asset_name: runtipi-cli-linux-x64
asset_content_type: application/octet-stream
- name: Upload ARM64 Linux CLI binary to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: cli/bin/cli-arm64
asset_name: runtipi-cli-linux-arm64
asset_content_type: application/octet-stream
files: |
runtipi-cli-linux-x64

View file

@ -8,27 +8,57 @@ on:
required: true
jobs:
get-tag:
create-tag:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.get_tag.outputs.tag }}
tagname: ${{ steps.get_tag.outputs.tagname }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Get tag from VERSION file
- name: Get tag from package.json
id: get_tag
run: |
VERSION=$(npm run version --silent)
echo "tag=v${VERSION}-beta.${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
echo "tagname=v${VERSION}-beta.${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
- uses: rickstaa/action-create-tag@v1
with:
tag: ${{ steps.get_tag.outputs.tagname }}
build-worker:
runs-on: ubuntu-latest
needs: create-tag
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push images
uses: docker/build-push-action@v5
with:
context: .
file: ./packages/worker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/${{ github.repository_owner }}/worker:${{ needs.create-tag.outputs.tagname }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/worker:buildcache
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/worker:buildcache,mode=max
build-images:
needs: get-tag
needs: create-tag
runs-on: ubuntu-latest
steps:
- name: Checkout code
@ -53,13 +83,13 @@ jobs:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/${{ github.repository_owner }}/runtipi:${{ needs.get-tag.outputs.tag }}
tags: ghcr.io/${{ github.repository_owner }}/runtipi:${{ needs.create-tag.outputs.tagname }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/runtipi:buildcache
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/runtipi:buildcache,mode=max
build-cli:
runs-on: ubuntu-latest
needs: get-tag
needs: create-tag
steps:
- name: Checkout code
uses: actions/checkout@v4
@ -93,7 +123,7 @@ jobs:
run: pnpm install
- name: Set version
run: pnpm -r --filter cli set-version ${{ needs.get-tag.outputs.tag }}
run: pnpm -r --filter cli set-version ${{ needs.create-tag.outputs.tagname }}
- name: Build CLI
run: pnpm -r --filter cli package
@ -104,28 +134,9 @@ jobs:
name: cli
path: packages/cli/dist
create-tag:
needs: [build-images, build-cli]
runs-on: ubuntu-latest
outputs:
tagname: ${{ steps.create_tag.outputs.tagname }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create Tag
id: create_tag
uses: butlerlogic/action-autotag@stable
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
with:
tag_prefix: 'v'
tag_suffix: '-beta.${{ github.event.inputs.tag }}'
publish-release:
runs-on: ubuntu-latest
needs: [create-tag, build-images, build-cli]
needs: [create-tag, build-images, build-cli, build-worker]
outputs:
id: ${{ steps.create_release.outputs.id }}
steps:
@ -135,38 +146,26 @@ jobs:
name: cli
path: cli
- name: Rename CLI
run: |
mv cli/bin/cli-x64 ./runtipi-cli-linux-x64
mv cli/bin/cli-arm64 ./runtipi-cli-linux-arm64
- name: Create beta release
id: create_release
uses: actions/create-release@v1
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: |
**${{ needs.create-tag.outputs.tagname }}**
tag_name: ${{ needs.create-tag.outputs.tagname }}
release_name: ${{ needs.create-tag.outputs.tagname }}
name: ${{ needs.create-tag.outputs.tagname }}
draft: false
prerelease: true
- name: Upload X64 Linux CLI binary to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: cli/bin/cli-x64
asset_name: runtipi-cli-linux-x64
asset_content_type: application/octet-stream
- name: Upload ARM64 Linux CLI binary to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: cli/bin/cli-arm64
asset_name: runtipi-cli-linux-arm64
asset_content_type: application/octet-stream
files: |
runtipi-cli-linux-x64
runtipi-cli-linux-arm64
e2e-tests:
needs: [create-tag, publish-release]

View file

@ -1,6 +1,6 @@
name: Tipi CI
on:
push:
pull_request:
env:
ROOT_FOLDER: /runtipi

View file

@ -72,9 +72,6 @@ jobs:
run: |
while ! ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ steps.get-droplet-ip.outputs.droplet_ip }} "echo 'SSH is ready'"; do sleep 5; done
- name: Wait 1 minute for Droplet to be ready
run: sleep 60
- name: Create docker group on Droplet
uses: fifsky/ssh-action@master
with:
@ -85,6 +82,9 @@ jobs:
user: root
key: ${{ secrets.SSH_KEY }}
- name: Wait 90 seconds for Docker to be ready on Droplet
run: sleep 90
- name: Deploy app to Droplet
uses: fifsky/ssh-action@master
with:

View file

@ -3,28 +3,28 @@ on:
workflow_dispatch:
jobs:
get-tag:
create-tag:
runs-on: ubuntu-latest
needs: [build-images, build-cli]
outputs:
tag: ${{ steps.get_tag.outputs.tag }}
tagname: ${{ steps.get_tag.outputs.tagname }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Get tag from VERSION file
- name: Get tag from package.json
id: get_tag
run: |
VERSION=$(npm run version --silent)
echo "tag=v${VERSION}" >> $GITHUB_OUTPUT
echo "tagname=v${VERSION}" >> $GITHUB_OUTPUT
- uses: rickstaa/action-create-tag@v1
with:
tag: ${{ steps.get_tag.outputs.tagname }}
build-images:
if: github.repository == 'runtipi/runtipi'
needs: get-tag
needs: create-tag
runs-on: ubuntu-latest
steps:
- name: Checkout
@ -49,14 +49,45 @@ jobs:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/${{ github.repository_owner }}/runtipi:${{ needs.get-tag.outputs.tag }},ghcr.io/${{ github.repository_owner }}/runtipi:latest
tags: ghcr.io/${{ github.repository_owner }}/runtipi:${{ needs.create-tag.outputs.tagname }},ghcr.io/${{ github.repository_owner }}/runtipi:latest
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/runtipi:buildcache
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/runtipi:buildcache,mode=max
build-worker:
runs-on: ubuntu-latest
needs: create-tag
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push images
uses: docker/build-push-action@v5
with:
context: .
file: ./packages/worker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/${{ github.repository_owner }}/worker:${{ needs.create-tag.outputs.tagname }},ghcr.io/${{ github.repository_owner }}/worker:latest
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/worker:buildcache
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/worker:buildcache,mode=max
build-cli:
runs-on: ubuntu-latest
timeout-minutes: 10
needs: get-tag
needs: create-tag
steps:
- name: Checkout code
uses: actions/checkout@v4
@ -90,7 +121,7 @@ jobs:
run: pnpm install
- name: Set version
run: pnpm -r --filter cli set-version ${{ needs.get-tag.outputs.tag }}
run: pnpm -r --filter cli set-version ${{ needs.create-tag.outputs.tagname }}
- name: Build CLI
run: pnpm -r --filter cli package
@ -101,23 +132,6 @@ jobs:
name: cli
path: packages/cli/dist
create-tag:
runs-on: ubuntu-latest
needs: [build-images, build-cli]
outputs:
tagname: ${{ steps.create_tag.outputs.tagname }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create Tag
id: create_tag
uses: butlerlogic/action-autotag@stable
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
with:
tag_prefix: 'v'
publish-release:
runs-on: ubuntu-latest
needs: [create-tag]
@ -130,38 +144,26 @@ jobs:
name: cli
path: cli
- name: Rename CLI
run: |
mv cli/bin/cli-x64 ./runtipi-cli-linux-x64
mv cli/bin/cli-arm64 ./runtipi-cli-linux-arm64
- name: Create release
id: create_release
uses: actions/create-release@v1
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: |
**${{ needs.create-tag.outputs.tagname }}**
tag_name: ${{ needs.create-tag.outputs.tagname }}
release_name: ${{ needs.create-tag.outputs.tagname }}
name: ${{ needs.create-tag.outputs.tagname }}
draft: false
prerelease: true
- name: Upload X64 Linux CLI binary to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: cli/bin/cli-x64
asset_name: runtipi-cli-linux-x64
asset_content_type: application/octet-stream
- name: Upload ARM64 Linux CLI binary to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: cli/bin/cli-arm64
asset_name: runtipi-cli-linux-arm64
asset_content_type: application/octet-stream
files: |
runtipi-cli-linux-x64
runtipi-cli-linux-arm64
e2e-tests:
needs: [create-tag, publish-release]
@ -176,7 +178,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Promote release
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |

4
.gitignore vendored
View file

@ -54,8 +54,7 @@ node_modules/
/data/
/repos/
/apps/
traefik/shared
traefik/tls
/traefik/
# media folder
media
@ -67,3 +66,4 @@ media
temp
./traefik/
/user-config/

View file

@ -33,7 +33,8 @@ RUN npm run build
FROM node_base AS app
ENV NODE_ENV production
# USER node
USER node
WORKDIR /app

View file

@ -1,9 +1,7 @@
# Tipi — A personal homeserver for everyone
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-38-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-41-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
[![License](https://img.shields.io/github/license/runtipi/runtipi)](https://github.com/runtipi/runtipi/blob/master/LICENSE)
@ -75,36 +73,36 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<table>
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://meienberger.dev/"><img src="https://avatars.githubusercontent.com/u/47644445?v=4?s=100" width="100px;" alt="Nicolas Meienberger"/><br /><sub><b>Nicolas Meienberger</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=meienberger" title="Code">💻</a> <a href="#infra-meienberger" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/meienberger/runtipi/commits?author=meienberger" title="Tests">⚠️</a> <a href="https://github.com/meienberger/runtipi/commits?author=meienberger" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ArneNaessens"><img src="https://avatars.githubusercontent.com/u/16622722?v=4?s=100" width="100px;" alt="ArneNaessens"/><br /><sub><b>ArneNaessens</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=ArneNaessens" title="Code">💻</a> <a href="#ideas-ArneNaessens" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/meienberger/runtipi/commits?author=ArneNaessens" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/DrMxrcy"><img src="https://avatars.githubusercontent.com/u/58747968?v=4?s=100" width="100px;" alt="DrMxrcy"/><br /><sub><b>DrMxrcy</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=DrMxrcy" title="Code">💻</a> <a href="#ideas-DrMxrcy" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/meienberger/runtipi/commits?author=DrMxrcy" title="Tests">⚠️</a> <a href="#content-DrMxrcy" title="Content">🖋</a> <a href="#promotion-DrMxrcy" title="Promotion">📣</a> <a href="#question-DrMxrcy" title="Answering Questions">💬</a> <a href="https://github.com/meienberger/runtipi/pulls?q=is%3Apr+reviewed-by%3ADrMxrcy" title="Reviewed Pull Requests">👀</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://cobre.dev"><img src="https://avatars.githubusercontent.com/u/36574329?v=4?s=100" width="100px;" alt="Cooper"/><br /><sub><b>Cooper</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=CobreDev" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/JTruj1ll0923"><img src="https://avatars.githubusercontent.com/u/6656643?v=4?s=100" width="100px;" alt="JTruj1ll0923"/><br /><sub><b>JTruj1ll0923</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=JTruj1ll0923" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Stetsed"><img src="https://avatars.githubusercontent.com/u/33891782?v=4?s=100" width="100px;" alt="Stetsed"/><br /><sub><b>Stetsed</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=Stetsed" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/blushell"><img src="https://avatars.githubusercontent.com/u/3621606?v=4?s=100" width="100px;" alt="Jones_Town"/><br /><sub><b>Jones_Town</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=blushell" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://meienberger.dev/"><img src="https://avatars.githubusercontent.com/u/47644445?v=4?s=100" width="100px;" alt="Nicolas Meienberger"/><br /><sub><b>Nicolas Meienberger</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=meienberger" title="Code">💻</a> <a href="#infra-meienberger" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/runtipi/runtipi/commits?author=meienberger" title="Tests">⚠️</a> <a href="https://github.com/runtipi/runtipi/commits?author=meienberger" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ArneNaessens"><img src="https://avatars.githubusercontent.com/u/16622722?v=4?s=100" width="100px;" alt="ArneNaessens"/><br /><sub><b>ArneNaessens</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=ArneNaessens" title="Code">💻</a> <a href="#ideas-ArneNaessens" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/runtipi/runtipi/commits?author=ArneNaessens" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/DrMxrcy"><img src="https://avatars.githubusercontent.com/u/58747968?v=4?s=100" width="100px;" alt="DrMxrcy"/><br /><sub><b>DrMxrcy</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=DrMxrcy" title="Code">💻</a> <a href="#ideas-DrMxrcy" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/runtipi/runtipi/commits?author=DrMxrcy" title="Tests">⚠️</a> <a href="#content-DrMxrcy" title="Content">🖋</a> <a href="#promotion-DrMxrcy" title="Promotion">📣</a> <a href="#question-DrMxrcy" title="Answering Questions">💬</a> <a href="https://github.com/runtipi/runtipi/pulls?q=is%3Apr+reviewed-by%3ADrMxrcy" title="Reviewed Pull Requests">👀</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://cobre.dev"><img src="https://avatars.githubusercontent.com/u/36574329?v=4?s=100" width="100px;" alt="Cooper"/><br /><sub><b>Cooper</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=CobreDev" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/JTruj1ll0923"><img src="https://avatars.githubusercontent.com/u/6656643?v=4?s=100" width="100px;" alt="JTruj1ll0923"/><br /><sub><b>JTruj1ll0923</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=JTruj1ll0923" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Stetsed"><img src="https://avatars.githubusercontent.com/u/33891782?v=4?s=100" width="100px;" alt="Stetsed"/><br /><sub><b>Stetsed</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=Stetsed" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/blushell"><img src="https://avatars.githubusercontent.com/u/3621606?v=4?s=100" width="100px;" alt="Jones_Town"/><br /><sub><b>Jones_Town</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=blushell" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://rushichaudhari.github.io/"><img src="https://avatars.githubusercontent.com/u/6279035?v=4?s=100" width="100px;" alt="Rushi Chaudhari"/><br /><sub><b>Rushi Chaudhari</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=rushic24" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/rblaine95"><img src="https://avatars.githubusercontent.com/u/4052340?v=4?s=100" width="100px;" alt="Robert Blaine"/><br /><sub><b>Robert Blaine</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=rblaine95" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://sethforprivacy.com"><img src="https://avatars.githubusercontent.com/u/40500387?v=4?s=100" width="100px;" alt="Seth For Privacy"/><br /><sub><b>Seth For Privacy</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=sethforprivacy" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/hqwuzhaoyi"><img src="https://avatars.githubusercontent.com/u/44605072?v=4?s=100" width="100px;" alt="Prajna"/><br /><sub><b>Prajna</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=hqwuzhaoyi" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/justincmoy"><img src="https://avatars.githubusercontent.com/u/14875982?v=4?s=100" width="100px;" alt="Justin Moy"/><br /><sub><b>Justin Moy</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=justincmoy" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/dextreem"><img src="https://avatars.githubusercontent.com/u/11060652?v=4?s=100" width="100px;" alt="dextreem"/><br /><sub><b>dextreem</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=dextreem" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/iBicha"><img src="https://avatars.githubusercontent.com/u/17722782?v=4?s=100" width="100px;" alt="Brahim Hadriche"/><br /><sub><b>Brahim Hadriche</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=iBicha" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://rushichaudhari.github.io/"><img src="https://avatars.githubusercontent.com/u/6279035?v=4?s=100" width="100px;" alt="Rushi Chaudhari"/><br /><sub><b>Rushi Chaudhari</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=rushic24" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/rblaine95"><img src="https://avatars.githubusercontent.com/u/4052340?v=4?s=100" width="100px;" alt="Robert Blaine"/><br /><sub><b>Robert Blaine</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=rblaine95" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://sethforprivacy.com"><img src="https://avatars.githubusercontent.com/u/40500387?v=4?s=100" width="100px;" alt="Seth For Privacy"/><br /><sub><b>Seth For Privacy</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=sethforprivacy" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/hqwuzhaoyi"><img src="https://avatars.githubusercontent.com/u/44605072?v=4?s=100" width="100px;" alt="Prajna"/><br /><sub><b>Prajna</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=hqwuzhaoyi" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/justincmoy"><img src="https://avatars.githubusercontent.com/u/14875982?v=4?s=100" width="100px;" alt="Justin Moy"/><br /><sub><b>Justin Moy</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=justincmoy" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/dextreem"><img src="https://avatars.githubusercontent.com/u/11060652?v=4?s=100" width="100px;" alt="dextreem"/><br /><sub><b>dextreem</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=dextreem" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/iBicha"><img src="https://avatars.githubusercontent.com/u/17722782?v=4?s=100" width="100px;" alt="Brahim Hadriche"/><br /><sub><b>Brahim Hadriche</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=iBicha" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://andrewbrereton.com"><img src="https://avatars.githubusercontent.com/u/682893?v=4?s=100" width="100px;" alt="Andrew Brereton"/><br /><sub><b>Andrew Brereton</b></sub></a><br /><a href="#content-andrewbrereton" title="Content">🖋</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://fsackur.github.io/"><img src="https://avatars.githubusercontent.com/u/3678789?v=4?s=100" width="100px;" alt="Freddie Sackur"/><br /><sub><b>Freddie Sackur</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=fsackur" title="Code">💻</a> <a href="https://github.com/meienberger/runtipi/commits?author=fsackur" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://fsackur.github.io/"><img src="https://avatars.githubusercontent.com/u/3678789?v=4?s=100" width="100px;" alt="Freddie Sackur"/><br /><sub><b>Freddie Sackur</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=fsackur" title="Code">💻</a> <a href="https://github.com/runtipi/runtipi/commits?author=fsackur" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://innocentius.github.io"><img src="https://avatars.githubusercontent.com/u/5344432?v=4?s=100" width="100px;" alt="Innocentius"/><br /><sub><b>Innocentius</b></sub></a><br /><a href="#translation-innocentius" title="Translation">🌍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/TetrisIQ"><img src="https://avatars.githubusercontent.com/u/24246993?v=4?s=100" width="100px;" alt="Alex"/><br /><sub><b>Alex</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=TetrisIQ" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://ryanc.cc"><img src="https://avatars.githubusercontent.com/u/21301288?v=4?s=100" width="100px;" alt="Ryan Wang"/><br /><sub><b>Ryan Wang</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=ruibaby" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/TetrisIQ"><img src="https://avatars.githubusercontent.com/u/24246993?v=4?s=100" width="100px;" alt="Alex"/><br /><sub><b>Alex</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=TetrisIQ" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://ryanc.cc"><img src="https://avatars.githubusercontent.com/u/21301288?v=4?s=100" width="100px;" alt="Ryan Wang"/><br /><sub><b>Ryan Wang</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=ruibaby" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/simonandr"><img src="https://avatars.githubusercontent.com/u/48092304?v=4?s=100" width="100px;" alt="simonandr"/><br /><sub><b>simonandr</b></sub></a><br /><a href="#content-simonandr" title="Content">🖋</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/demizeu"><img src="https://avatars.githubusercontent.com/u/121183951?v=4?s=100" width="100px;" alt="iepure"/><br /><sub><b>iepure</b></sub></a><br /><a href="#translation-demizeu" title="Translation">🌍</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/SergeyKodolov"><img src="https://avatars.githubusercontent.com/u/35339452?v=4?s=100" width="100px;" alt="Sergey Kodolov"/><br /><sub><b>Sergey Kodolov</b></sub></a><br /><a href="#translation-SergeyKodolov" title="Translation">🌍</a> <a href="https://github.com/meienberger/runtipi/commits?author=SergeyKodolov" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/sclaren"><img src="https://avatars.githubusercontent.com/u/915292?v=4?s=100" width="100px;" alt="sclaren"/><br /><sub><b>sclaren</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=sclaren" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mcmeel"><img src="https://avatars.githubusercontent.com/u/13773536?v=4?s=100" width="100px;" alt="mcmeel"/><br /><sub><b>mcmeel</b></sub></a><br /><a href="#question-mcmeel" title="Answering Questions">💬</a> <a href="#ideas-mcmeel" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/meienberger/runtipi/commits?author=mcmeel" title="Code">💻</a> <a href="https://github.com/meienberger/runtipi/commits?author=mcmeel" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/SergeyKodolov"><img src="https://avatars.githubusercontent.com/u/35339452?v=4?s=100" width="100px;" alt="Sergey Kodolov"/><br /><sub><b>Sergey Kodolov</b></sub></a><br /><a href="#translation-SergeyKodolov" title="Translation">🌍</a> <a href="https://github.com/runtipi/runtipi/commits?author=SergeyKodolov" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/sclaren"><img src="https://avatars.githubusercontent.com/u/915292?v=4?s=100" width="100px;" alt="sclaren"/><br /><sub><b>sclaren</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=sclaren" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mcmeel"><img src="https://avatars.githubusercontent.com/u/13773536?v=4?s=100" width="100px;" alt="mcmeel"/><br /><sub><b>mcmeel</b></sub></a><br /><a href="#question-mcmeel" title="Answering Questions">💬</a> <a href="#ideas-mcmeel" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/runtipi/runtipi/commits?author=mcmeel" title="Code">💻</a> <a href="https://github.com/runtipi/runtipi/commits?author=mcmeel" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/NoisyFridge"><img src="https://avatars.githubusercontent.com/u/73795785?v=4?s=100" width="100px;" alt="NoisyFridge"/><br /><sub><b>NoisyFridge</b></sub></a><br /><a href="#translation-NoisyFridge" title="Translation">🌍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Bvoxl"><img src="https://avatars.githubusercontent.com/u/67489519?v=4?s=100" width="100px;" alt="Bvoxl"/><br /><sub><b>Bvoxl</b></sub></a><br /><a href="#translation-Bvoxl" title="Translation">🌍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/m-lab-0"><img src="https://avatars.githubusercontent.com/u/116570617?v=4?s=100" width="100px;" alt="m-lab-0"/><br /><sub><b>m-lab-0</b></sub></a><br /><a href="#translation-m-lab-0" title="Translation">🌍</a></td>
@ -113,16 +111,19 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Schmanko"><img src="https://avatars.githubusercontent.com/u/94195393?v=4?s=100" width="100px;" alt="Schmanko"/><br /><sub><b>Schmanko</b></sub></a><br /><a href="#translation-Schmanko" title="Translation">🌍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://micro.nghialele.com"><img src="https://avatars.githubusercontent.com/u/129353223?v=4?s=100" width="100px;" alt="Nghia Lele"/><br /><sub><b>Nghia Lele</b></sub></a><br /><a href="#translation-nghialele" title="Translation">🌍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/amusingimpala75"><img src="https://avatars.githubusercontent.com/u/69653100?v=4?s=100" width="100px;" alt="amusingimpala75"/><br /><sub><b>amusingimpala75</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=amusingimpala75" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/amusingimpala75"><img src="https://avatars.githubusercontent.com/u/69653100?v=4?s=100" width="100px;" alt="amusingimpala75"/><br /><sub><b>amusingimpala75</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=amusingimpala75" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://m1n.omg.lol"><img src="https://avatars.githubusercontent.com/u/54779580?v=4?s=100" width="100px;" alt="David"/><br /><sub><b>David</b></sub></a><br /><a href="#translation-M1n-4d316e" title="Translation">🌍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/steveiliop56"><img src="https://avatars.githubusercontent.com/u/106091011?v=4?s=100" width="100px;" alt="Stavros"/><br /><sub><b>Stavros</b></sub></a><br /><a href="#translation-steveiliop56" title="Translation">🌍</a> <a href="https://github.com/meienberger/runtipi/commits?author=steveiliop56" title="Code">💻</a> <a href="https://github.com/meienberger/runtipi/commits?author=steveiliop56" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/steveiliop56"><img src="https://avatars.githubusercontent.com/u/106091011?v=4?s=100" width="100px;" alt="Stavros Iliopoulos"/><br /><sub><b>Stavros Iliopoulos</b></sub></a><br /><a href="#translation-steveiliop56" title="Translation">🌍</a> <a href="https://github.com/runtipi/runtipi/commits?author=steveiliop56" title="Code">💻</a> <a href="https://github.com/runtipi/runtipi/commits?author=steveiliop56" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/loxiry"><img src="https://avatars.githubusercontent.com/u/86959495?v=4?s=100" width="100px;" alt="loxiry"/><br /><sub><b>loxiry</b></sub></a><br /><a href="#translation-loxiry" title="Translation">🌍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/JigSawFr"><img src="https://avatars.githubusercontent.com/u/5781907?v=4?s=100" width="100px;" alt="JigSaw"/><br /><sub><b>JigSaw</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=JigSawFr" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/JigSawFr"><img src="https://avatars.githubusercontent.com/u/5781907?v=4?s=100" width="100px;" alt="JigSaw"/><br /><sub><b>JigSaw</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=JigSawFr" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/DireMunchkin"><img src="https://avatars.githubusercontent.com/u/1665676?v=4?s=100" width="100px;" alt="DireMunchkin"/><br /><sub><b>DireMunchkin</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=DireMunchkin" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/DireMunchkin"><img src="https://avatars.githubusercontent.com/u/1665676?v=4?s=100" width="100px;" alt="DireMunchkin"/><br /><sub><b>DireMunchkin</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=DireMunchkin" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/FabioCingottini"><img src="https://avatars.githubusercontent.com/u/32102735?v=4?s=100" width="100px;" alt="Fabio Cingottini"/><br /><sub><b>Fabio Cingottini</b></sub></a><br /><a href="#translation-FabioCingottini" title="Translation">🌍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/itsrllyhim"><img src="https://avatars.githubusercontent.com/u/143047010?v=4?s=100" width="100px;" alt="him"/><br /><sub><b>him</b></sub></a><br /><a href="https://github.com/meienberger/runtipi/commits?author=itsrllyhim" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/itsrllyhim"><img src="https://avatars.githubusercontent.com/u/143047010?v=4?s=100" width="100px;" alt="him"/><br /><sub><b>him</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=itsrllyhim" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://cchalop1.com"><img src="https://avatars.githubusercontent.com/u/28163855?v=4?s=100" width="100px;" alt="CHALOPIN Clément"/><br /><sub><b>CHALOPIN Clément</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=cchalop1" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/geetansh"><img src="https://avatars.githubusercontent.com/u/9976198?v=4?s=100" width="100px;" alt="Geetansh Jindal"/><br /><sub><b>Geetansh Jindal</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=geetansh" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/0livier"><img src="https://avatars.githubusercontent.com/u/10607?v=4?s=100" width="100px;" alt="Olivier Garcia"/><br /><sub><b>Olivier Garcia</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=0livier" title="Code">💻</a></td>
</tr>
</tbody>
</table>

View file

@ -55,6 +55,43 @@ services:
networks:
- tipi_main_network
tipi-worker:
build:
context: .
dockerfile: ./packages/worker/Dockerfile.dev
container_name: tipi-worker
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:3000/healthcheck']
interval: 5s
timeout: 10s
retries: 120
start_period: 5s
depends_on:
tipi-db:
condition: service_healthy
tipi-redis:
condition: service_healthy
env_file:
- .env
environment:
NODE_ENV: development
volumes:
# Dev mode
- ${PWD}/packages/worker/src:/app/packages/worker/src
# Production mode
- /proc:/host/proc:ro
- /var/run/docker.sock:/var/run/docker.sock
- ${PWD}/.env:/app/.env
- ${PWD}/state:/app/state
- ${PWD}/repos:/app/repos
- ${PWD}/apps:/app/apps
- ${STORAGE_PATH:-$PWD}/app-data:/storage/app-data
- ${PWD}/logs:/app/logs
- ${PWD}/traefik:/app/traefik
- ${PWD}/user-config:/app/user-config
networks:
- tipi_main_network
tipi-dashboard:
build:
context: .
@ -65,6 +102,8 @@ services:
condition: service_healthy
tipi-redis:
condition: service_healthy
tipi-worker:
condition: service_healthy
env_file:
- .env
environment:
@ -84,7 +123,7 @@ services:
- ${PWD}/apps:/runtipi/apps
- ${PWD}/logs:/app/logs
- ${PWD}/traefik:/runtipi/traefik
- ${STORAGE_PATH}:/app/storage
- ${STORAGE_PATH:-$PWD}:/app/storage
labels:
traefik.enable: true
traefik.http.services.dashboard.loadbalancer.server.port: 3000

View file

@ -55,6 +55,40 @@ services:
networks:
- tipi_main_network
tipi-worker:
build:
context: .
dockerfile: ./packages/worker/Dockerfile
container_name: tipi-worker
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:3000/healthcheck']
interval: 5s
timeout: 10s
retries: 120
start_period: 5s
depends_on:
tipi-db:
condition: service_healthy
tipi-redis:
condition: service_healthy
env_file:
- .env
environment:
NODE_ENV: production
volumes:
- /proc:/host/proc
- /var/run/docker.sock:/var/run/docker.sock
- ${PWD}/.env:/app/.env
- ${PWD}/state:/app/state
- ${PWD}/repos:/app/repos
- ${PWD}/apps:/app/apps
- ${STORAGE_PATH:-$PWD}/app-data:/storage/app-data
- ${PWD}/logs:/app/logs
- ${PWD}/traefik:/app/traefik
- ${PWD}/user-config:/app/user-config
networks:
- tipi_main_network
tipi-dashboard:
build:
context: .
@ -65,6 +99,8 @@ services:
condition: service_healthy
tipi-redis:
condition: service_healthy
tipi-worker:
condition: service_healthy
env_file:
- .env
environment:

View file

@ -1,6 +1,6 @@
{
"name": "runtipi",
"version": "2.1.0",
"version": "2.2.0",
"description": "A homeserver for everyone",
"scripts": {
"knip": "knip",
@ -11,7 +11,7 @@
"test:client": "jest --colors --selectProjects client --",
"test:server": "jest --colors --selectProjects server --",
"test:vite": "dotenv -e .env.test -- vitest run --coverage",
"dev": "npm run db:migrate && next dev",
"dev": "next dev",
"dev:watcher": "pnpm -r --filter cli dev",
"db:migrate": "NODE_ENV=development dotenv -e .env.local -- tsx ./src/server/run-migrations-dev.ts",
"lint": "next lint",
@ -46,12 +46,13 @@
"@runtipi/shared": "workspace:^",
"@tabler/core": "1.0.0-beta20",
"@tabler/icons-react": "^2.40.0",
"argon2": "^0.31.1",
"argon2": "^0.31.2",
"bullmq": "^4.13.0",
"clsx": "^2.0.0",
"connect-redis": "^7.1.0",
"drizzle-orm": "^0.28.6",
"fs-extra": "^11.1.1",
"let-it-go": "^1.0.0",
"lodash.merge": "^4.6.2",
"next": "14.0.1",
"next-client-cookies": "^1.0.6",
@ -92,7 +93,7 @@
"@testing-library/user-event": "^14.5.1",
"@total-typescript/shoehorn": "^0.1.1",
"@total-typescript/ts-reset": "^0.5.1",
"@types/fs-extra": "^11.0.3",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.7",
"@types/lodash.merge": "^4.6.8",
"@types/node": "20.8.10",
@ -122,7 +123,7 @@
"eslint-plugin-testing-library": "^6.1.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"knip": "^2.39.0",
"knip": "^2.41.3",
"memfs": "^4.6.0",
"msw": "^1.3.2",
"next-router-mock": "^0.9.10",

View file

@ -4,10 +4,12 @@ services:
tipi-reverse-proxy:
container_name: tipi-reverse-proxy
image: traefik:v2.8
restart: on-failure
restart: unless-stopped
depends_on:
- tipi-dashboard
ports:
- ${NGINX_PORT-80}:80
- ${NGINX_PORT_SSL-443}:443
- ${NGINX_PORT:-80}:80
- ${NGINX_PORT_SSL:-443}:443
command: --providers.docker
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
@ -22,7 +24,7 @@ services:
restart: on-failure
stop_grace_period: 1m
ports:
- 5432:5432
- ${POSTGRES_PORT:-5432}:5432
volumes:
- ./data/postgres:/var/lib/postgresql/data
environment:
@ -40,7 +42,7 @@ services:
tipi-redis:
container_name: tipi-redis
image: redis:7.2.0
restart: on-failure
restart: unless-stopped
command: redis-server --requirepass ${REDIS_PASSWORD}
ports:
- 6379:6379
@ -54,12 +56,16 @@ services:
networks:
- tipi_main_network
tipi-dashboard:
image: ghcr.io/runtipi/runtipi:${TIPI_VERSION}
restart: on-failure
container_name: tipi-dashboard
networks:
- tipi_main_network
tipi-worker:
container_name: tipi-worker
image: ghcr.io/runtipi/worker:${TIPI_VERSION}
restart: unless-stopped
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:3000/healthcheck']
interval: 5s
timeout: 10s
retries: 120
start_period: 5s
depends_on:
tipi-db:
condition: service_healthy
@ -70,13 +76,46 @@ services:
environment:
NODE_ENV: production
volumes:
- ./.env:/runtipi/.env
# Core
- /proc:/host/proc
- /var/run/docker.sock:/var/run/docker.sock
# App
- ./.env:/app/.env
- ./state:/app/state
- ./repos:/app/repos
- ./apps:/app/apps
- ./logs:/app/logs
- ./traefik:/app/traefik
- ./user-config:/app/user-config
- ./media:/app/media
- ${STORAGE_PATH:-.}:/storage
networks:
- tipi_main_network
tipi-dashboard:
image: ghcr.io/runtipi/runtipi:${TIPI_VERSION}
restart: unless-stopped
container_name: tipi-dashboard
networks:
- tipi_main_network
depends_on:
tipi-db:
condition: service_healthy
tipi-redis:
condition: service_healthy
tipi-worker:
condition: service_healthy
volumes:
- ./.env:/runtipi/.env:ro
- ./state:/runtipi/state
- ./repos:/runtipi/repos:ro
- ./apps:/runtipi/apps
- ./logs:/app/logs
- ./traefik:/runtipi/traefik
- ${STORAGE_PATH}:/app/storage
- ${STORAGE_PATH:-.}:/app/storage
env_file:
- .env
environment:
NODE_ENV: production
labels:
# Main
traefik.enable: true

View file

@ -5,7 +5,7 @@
"main": "index.js",
"bin": "dist/index.js",
"scripts": {
"test": "dotenv -e .env.test vitest -- --coverage --watch=false",
"test": "dotenv -e .env.test vitest -- --coverage --watch=false --passWithNoTests",
"test:watch": "dotenv -e .env.test vitest",
"package": "npm run build && pkg package.json && chmod +x dist/bin/cli-x64 && chmod +x dist/bin/cli-arm64",
"package:m1": "npm run build && pkg package.json -t node18-darwin-arm64",
@ -14,7 +14,8 @@
"build:meta": "esbuild ./src/index.ts --bundle --platform=node --target=node18 --outfile=dist/index.js --metafile=meta.json --analyze",
"dev": "dotenv -e ../../.env nodemon",
"lint": "eslint . --ext .ts",
"tsc": "tsc --noEmit"
"tsc": "tsc --noEmit",
"knip": "knip"
},
"pkg": {
"assets": "assets/**/*",
@ -31,10 +32,10 @@
"@faker-js/faker": "^8.2.0",
"@types/cli-progress": "^3.11.4",
"@types/node": "20.8.10",
"@types/web-push": "^3.6.2",
"dotenv-cli": "^7.3.0",
"esbuild": "^0.19.4",
"eslint-config-prettier": "^9.0.0",
"knip": "^2.41.3",
"memfs": "^4.6.0",
"nodemon": "^3.0.1",
"pkg": "^5.8.1",
@ -43,7 +44,6 @@
"vitest": "^0.34.6"
},
"dependencies": {
"@runtipi/postgres-migrations": "^5.3.0",
"@runtipi/shared": "workspace:^",
"axios": "^1.6.0",
"boxen": "^7.1.1",
@ -53,12 +53,8 @@
"cli-spinners": "^2.9.1",
"commander": "^11.1.0",
"dotenv": "^16.3.1",
"ioredis": "^5.3.2",
"log-update": "^5.0.1",
"pg": "^8.11.3",
"semver": "^7.5.4",
"systeminformation": "^5.21.15",
"web-push": "^3.6.6",
"zod": "^3.22.4"
}
}

View file

@ -1,300 +1,73 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-restricted-syntax */
import fs from 'fs';
import path from 'path';
import pg from 'pg';
import { Queue, QueueEvents } from 'bullmq';
import { SystemEvent, eventSchema } from '@runtipi/shared';
import { getEnv } from '@/utils/environment/environment';
import { pathExists } from '@/utils/fs-helpers';
import { compose } from '@/utils/docker-helpers';
import { copyDataDir, generateEnvFile } from './app.helpers';
import { fileLogger } from '@/utils/logger/file-logger';
import { logger } from '@/utils/logger/logger';
import { TerminalSpinner } from '@/utils/logger/terminal-spinner';
import { execAsync } from '@/utils/exec-async/execAsync';
const getDbClient = async () => {
const { postgresDatabase, postgresUsername, postgresPassword, postgresPort } = getEnv();
const client = new pg.Client({
host: '127.0.0.1',
database: postgresDatabase,
user: postgresUsername,
password: postgresPassword,
port: Number(postgresPort),
});
await client.connect();
return client;
};
export class AppExecutors {
private readonly logger;
constructor() {
this.logger = fileLogger;
this.logger = logger;
}
private handleAppError = (err: unknown) => {
if (err instanceof Error) {
this.logger.error(`An error occurred: ${err.message}`);
return { success: false, message: err.message };
}
private getQueue = () => {
const { redisPassword } = getEnv();
const queue = new Queue('events', { connection: { host: '127.0.0.1', port: 6379, password: redisPassword } });
const queueEvents = new QueueEvents('events', { connection: { host: '127.0.0.1', port: 6379, password: redisPassword } });
return { success: false, message: `An error occurred: ${err}` };
return { queue, queueEvents };
};
private getAppPaths = (appId: string) => {
const { rootFolderHost, storagePath, appsRepoId } = getEnv();
const appDataDirPath = path.join(storagePath, 'app-data', appId);
const appDirPath = path.join(rootFolderHost, 'apps', appId);
const configJsonPath = path.join(appDirPath, 'config.json');
const repoPath = path.join(rootFolderHost, 'repos', appsRepoId, 'apps', appId);
return { appDataDirPath, appDirPath, configJsonPath, repoPath };
};
/**
* Given an app id, ensures that the app folder exists in the apps folder
* If not, copies the app folder from the repo
* @param {string} appId - App id
*/
private ensureAppDir = async (appId: string) => {
const { rootFolderHost } = getEnv();
const { appDirPath, repoPath } = this.getAppPaths(appId);
const dockerFilePath = path.join(rootFolderHost, 'apps', appId, 'docker-compose.yml');
if (!(await pathExists(dockerFilePath))) {
// delete eventual app folder if exists
this.logger.info(`Deleting app ${appId} folder if exists`);
await fs.promises.rm(appDirPath, { recursive: true, force: true });
// Copy app folder from repo
this.logger.info(`Copying app ${appId} from repo ${getEnv().appsRepoId}`);
await fs.promises.cp(repoPath, appDirPath, { recursive: true });
}
};
/**
* Install an app from the repo
* @param {string} appId - The id of the app to install
* @param {Record<string, unknown>} config - The config of the app
*/
public installApp = async (appId: string, config: Record<string, unknown>) => {
try {
if (process.getuid && process.getgid) {
this.logger.info(`Installing app ${appId} as User ID: ${process.getuid()}, Group ID: ${process.getgid()}`);
} else {
this.logger.info(`Installing app ${appId}. No User ID or Group ID found.`);
}
const { rootFolderHost, appsRepoId } = getEnv();
const { appDirPath, repoPath, appDataDirPath } = this.getAppPaths(appId);
// Check if app exists in repo
const apps = await fs.promises.readdir(path.join(rootFolderHost, 'repos', appsRepoId, 'apps'));
if (!apps.includes(appId)) {
this.logger.error(`App ${appId} not found in repo ${appsRepoId}`);
return { success: false, message: `App ${appId} not found in repo ${appsRepoId}` };
}
// Delete app folder if exists
this.logger.info(`Deleting folder ${appDirPath} if exists`);
await fs.promises.rm(appDirPath, { recursive: true, force: true });
// Create app folder
this.logger.info(`Creating folder ${appDirPath}`);
await fs.promises.mkdir(appDirPath, { recursive: true });
// Copy app folder from repo
this.logger.info(`Copying folder ${repoPath} to ${appDirPath}`);
await fs.promises.cp(repoPath, appDirPath, { recursive: true });
// Create folder app-data folder
this.logger.info(`Creating folder ${appDataDirPath}`);
await fs.promises.mkdir(appDataDirPath, { recursive: true });
// Create app.env file
this.logger.info(`Creating app.env file for app ${appId}`);
await generateEnvFile(appId, config);
// Copy data dir
this.logger.info(`Copying data dir for app ${appId}`);
if (!(await pathExists(`${appDataDirPath}/data`))) {
await copyDataDir(appId);
}
await execAsync(`chmod -R a+rwx ${path.join(appDataDirPath)}`).catch(() => {
this.logger.error(`Error setting permissions for app ${appId}`);
});
// run docker-compose up
this.logger.info(`Running docker-compose up for app ${appId}`);
await compose(appId, 'up -d');
this.logger.info(`Docker-compose up for app ${appId} finished`);
return { success: true, message: `App ${appId} installed successfully` };
} catch (err) {
return this.handleAppError(err);
}
private generateJobId = (event: Record<string, unknown>) => {
const { appId, action } = event;
return `${appId}-${action}`;
};
/**
* Stops an app
* @param {string} appId - The id of the app to stop
* @param {Record<string, unknown>} config - The config of the app
*/
public stopApp = async (appId: string, config: Record<string, unknown>, skipEnvGeneration = false) => {
public stopApp = async (appId: string) => {
const spinner = new TerminalSpinner(`Stopping app ${appId}`);
spinner.start();
try {
spinner.start();
this.logger.info(`Stopping app ${appId}`);
const jobid = this.generateJobId({ appId, action: 'stop' });
await this.ensureAppDir(appId);
const { queue, queueEvents } = this.getQueue();
const event = { type: 'app', command: 'stop', appid: appId, form: {}, skipEnv: true } satisfies SystemEvent;
const job = await queue.add(jobid, eventSchema.parse(event));
const result = await job.waitUntilFinished(queueEvents, 1000 * 60 * 5);
if (!skipEnvGeneration) {
this.logger.info(`Regenerating app.env file for app ${appId}`);
await generateEnvFile(appId, config);
}
await compose(appId, 'rm --force --stop');
await queueEvents.close();
await queue.close();
this.logger.info(`App ${appId} stopped`);
spinner.done(`App ${appId} stopped`);
return { success: true, message: `App ${appId} stopped successfully` };
} catch (err) {
if (!result?.success) {
this.logger.error(result?.message);
spinner.fail(`Failed to stop app ${appId} see logs for more details (logs/error.log)`);
return this.handleAppError(err);
} else {
spinner.done(`App ${appId} stopped`);
}
};
public startApp = async (appId: string, config: Record<string, unknown>) => {
public startApp = async (appId: string) => {
const spinner = new TerminalSpinner(`Starting app ${appId}`);
try {
spinner.start();
const { appDataDirPath } = this.getAppPaths(appId);
spinner.start();
this.logger.info(`Starting app ${appId}`);
const jobid = this.generateJobId({ appId, action: 'start' });
this.logger.info(`Regenerating app.env file for app ${appId}`);
await this.ensureAppDir(appId);
await generateEnvFile(appId, config);
const { queue, queueEvents } = this.getQueue();
const event = { type: 'app', command: 'start', appid: appId, form: {}, skipEnv: true } satisfies SystemEvent;
const job = await queue.add(jobid, eventSchema.parse(event));
const result = await job.waitUntilFinished(queueEvents, 1000 * 60 * 5);
await compose(appId, 'up --detach --force-recreate --remove-orphans --pull always');
await queueEvents.close();
await queue.close();
this.logger.info(`App ${appId} started`);
this.logger.info(`Setting permissions for app ${appId}`);
await execAsync(`chmod -R a+rwx ${path.join(appDataDirPath)}`).catch(() => {
this.logger.error(`Error setting permissions for app ${appId}`);
});
spinner.done(`App ${appId} started`);
return { success: true, message: `App ${appId} started successfully` };
} catch (err) {
if (!result.success) {
spinner.fail(`Failed to start app ${appId} see logs for more details (logs/error.log)`);
return this.handleAppError(err);
}
};
public uninstallApp = async (appId: string, config: Record<string, unknown>) => {
try {
const { appDirPath, appDataDirPath } = this.getAppPaths(appId);
this.logger.info(`Uninstalling app ${appId}`);
this.logger.info(`Regenerating app.env file for app ${appId}`);
await this.ensureAppDir(appId);
await generateEnvFile(appId, config);
await compose(appId, 'down --remove-orphans --volumes --rmi all');
this.logger.info(`Deleting folder ${appDirPath}`);
await fs.promises.rm(appDirPath, { recursive: true, force: true }).catch((err) => {
this.logger.error(`Error deleting folder ${appDirPath}: ${err.message}`);
});
this.logger.info(`Deleting folder ${appDataDirPath}`);
await fs.promises.rm(appDataDirPath, { recursive: true, force: true }).catch((err) => {
this.logger.error(`Error deleting folder ${appDataDirPath}: ${err.message}`);
});
this.logger.info(`App ${appId} uninstalled`);
return { success: true, message: `App ${appId} uninstalled successfully` };
} catch (err) {
return this.handleAppError(err);
}
};
public updateApp = async (appId: string, config: Record<string, unknown>) => {
try {
const { appDirPath, repoPath } = this.getAppPaths(appId);
this.logger.info(`Updating app ${appId}`);
await this.ensureAppDir(appId);
await generateEnvFile(appId, config);
await compose(appId, 'up --detach --force-recreate --remove-orphans');
await compose(appId, 'down --rmi all --remove-orphans');
this.logger.info(`Deleting folder ${appDirPath}`);
await fs.promises.rm(appDirPath, { recursive: true, force: true });
this.logger.info(`Copying folder ${repoPath} to ${appDirPath}`);
await fs.promises.cp(repoPath, appDirPath, { recursive: true });
await compose(appId, 'pull');
return { success: true, message: `App ${appId} updated successfully` };
} catch (err) {
return this.handleAppError(err);
}
};
public regenerateAppEnv = async (appId: string, config: Record<string, unknown>) => {
try {
this.logger.info(`Regenerating app.env file for app ${appId}`);
await this.ensureAppDir(appId);
await generateEnvFile(appId, config);
return { success: true, message: `App ${appId} env file regenerated successfully` };
} catch (err) {
return this.handleAppError(err);
}
};
/**
* Start all apps with status running
*/
public startAllApps = async () => {
const spinner = new TerminalSpinner('Starting apps...');
const client = await getDbClient();
try {
// Get all apps with status running
const { rows } = await client.query(`SELECT * FROM app WHERE status = 'running'`);
// Update all apps with status different than running or stopped to stopped
await client.query(`UPDATE app SET status = 'stopped' WHERE status != 'stopped' AND status != 'running' AND status != 'missing'`);
// Start all apps
for (const row of rows) {
const { id, config } = row;
const { success } = await this.startApp(id, config);
if (!success) {
this.logger.error(`Error starting app ${id}`);
await client.query(`UPDATE app SET status = 'stopped' WHERE id = '${id}'`);
} else {
await client.query(`UPDATE app SET status = 'running' WHERE id = '${id}'`);
}
}
} catch (err) {
this.logger.error(`Error starting apps: ${err}`);
spinner.fail(`Error starting apps see logs for details (logs/error.log)`);
} finally {
await client.end();
} else {
spinner.done(`App ${appId} started`);
}
};
}

View file

@ -1,3 +1,2 @@
export { AppExecutors } from './app/app.executors';
export { RepoExecutors } from './repo/repo.executors';
export { SystemExecutors } from './system/system.executors';

View file

@ -1,12 +0,0 @@
import crypto from 'crypto';
/**
* Given a repo url, return a hash of it to be used as a folder name
*
* @param {string} repoUrl
*/
export const getRepoHash = (repoUrl: string) => {
const hash = crypto.createHash('sha256');
hash.update(repoUrl);
return hash.digest('hex');
};

View file

@ -1,7 +1,5 @@
/* eslint-disable no-restricted-syntax */
/* eslint-disable no-await-in-loop */
import { Queue } from 'bullmq';
import { Redis } from 'ioredis';
import fs from 'fs';
import cliProgress from 'cli-progress';
import semver from 'semver';
@ -9,20 +7,14 @@ import axios from 'axios';
import boxen from 'boxen';
import path from 'path';
import { spawn } from 'child_process';
import si from 'systeminformation';
import { Stream } from 'stream';
import dotenv from 'dotenv';
import { SystemEvent } from '@runtipi/shared';
import chalk from 'chalk';
import { killOtherWorkers } from 'src/services/watcher/watcher';
import { pathExists } from '@runtipi/shared';
import { AppExecutors } from '../app/app.executors';
import { copySystemFiles, generateSystemEnvFile, generateTlsCertificates } from './system.helpers';
import { copySystemFiles, generateSystemEnvFile } from './system.helpers';
import { TerminalSpinner } from '@/utils/logger/terminal-spinner';
import { pathExists } from '@/utils/fs-helpers';
import { getEnv } from '@/utils/environment/environment';
import { fileLogger } from '@/utils/logger/file-logger';
import { runPostgresMigrations } from '@/utils/migrations/run-migration';
import { getUserIds } from '@/utils/environment/user';
import { logger } from '@/utils/logger/logger';
import { execAsync } from '@/utils/exec-async/execAsync';
export class SystemExecutors {
@ -34,7 +26,7 @@ export class SystemExecutors {
constructor() {
this.rootFolder = process.cwd();
this.logger = fileLogger;
this.logger = logger;
this.envFile = path.join(this.rootFolder, '.env');
}
@ -49,59 +41,6 @@ export class SystemExecutors {
return { success: false, message: `An error occurred: ${err}` };
};
private getSystemLoad = async () => {
const { currentLoad } = await si.currentLoad();
const mem = await si.mem();
const [disk0] = await si.fsSize();
return {
cpu: { load: currentLoad },
memory: { total: mem.total, used: mem.used, available: mem.available },
disk: { total: disk0?.size, used: disk0?.used, available: disk0?.available },
};
};
private ensureFilePermissions = async (rootFolderHost: string) => {
const logger = new TerminalSpinner('');
const filesAndFolders = [
path.join(rootFolderHost, 'apps'),
path.join(rootFolderHost, 'logs'),
path.join(rootFolderHost, 'repos'),
path.join(rootFolderHost, 'state'),
path.join(rootFolderHost, 'traefik'),
path.join(rootFolderHost, '.env'),
path.join(rootFolderHost, 'VERSION'),
path.join(rootFolderHost, 'docker-compose.yml'),
];
const files600 = [path.join(rootFolderHost, 'traefik', 'shared', 'acme.json')];
this.logger.info('Setting file permissions a+rwx on required files');
// Give permission to read and write to all files and folders for the current user
for (const fileOrFolder of filesAndFolders) {
if (await pathExists(fileOrFolder)) {
this.logger.info(`Setting permissions on ${fileOrFolder}`);
await execAsync(`chmod -R a+rwx ${fileOrFolder}`).catch(() => {
logger.fail(`Failed to set permissions on ${fileOrFolder}`);
});
this.logger.info(`Successfully set permissions on ${fileOrFolder}`);
}
}
this.logger.info('Setting file permissions 600 on required files');
for (const fileOrFolder of files600) {
if (await pathExists(fileOrFolder)) {
this.logger.info(`Setting permissions on ${fileOrFolder}`);
await execAsync(`chmod 600 ${fileOrFolder}`).catch(() => {
logger.fail(`Failed to set permissions on ${fileOrFolder}`);
});
this.logger.info(`Successfully set permissions on ${fileOrFolder}`);
}
}
};
public cleanLogs = async () => {
try {
await this.logger.flush();
@ -113,20 +52,6 @@ export class SystemExecutors {
}
};
public systemInfo = async () => {
try {
const { rootFolderHost } = getEnv();
const systemLoad = await this.getSystemLoad();
await fs.promises.writeFile(path.join(rootFolderHost, 'state', 'system-info.json'), JSON.stringify(systemLoad, null, 2));
await fs.promises.chmod(path.join(rootFolderHost, 'state', 'system-info.json'), 0o777);
return { success: true, message: '' };
} catch (e) {
return this.handleSystemError(e);
}
};
/**
* This method will stop Tipi
* It will stop all the apps and then stop the main containers.
@ -143,7 +68,7 @@ export class SystemExecutors {
for (const app of apps) {
spinner.setMessage(`Stopping ${app}...`);
spinner.start();
await appExecutor.stopApp(app, {}, true);
await appExecutor.stopApp(app);
spinner.done(`${app} stopped`);
}
}
@ -167,41 +92,21 @@ export class SystemExecutors {
* This method will start Tipi.
* It will copy the system files, generate the system env file, pull the images and start the containers.
*/
public start = async (sudo = true, killWatchers = true) => {
public start = async () => {
const spinner = new TerminalSpinner('Starting Tipi...');
try {
await this.logger.flush();
const { isSudo } = getUserIds();
// Check if user is in docker group
spinner.setMessage('Checking docker permissions...');
spinner.start();
const { stdout: dockerVersion } = await execAsync('docker --version');
if (!sudo) {
console.log(
boxen(
"You are running in sudoless mode. While Tipi should work as expected, you'll probably run into permission issues and will have to manually fix them. We recommend running Tipi with sudo for beginners.",
{
title: '⛔Sudoless mode',
titleAlignment: 'center',
textAlignment: 'center',
padding: 1,
borderStyle: 'double',
borderColor: 'red',
margin: { top: 1, bottom: 1 },
width: 80,
},
),
);
}
this.logger.info('Killing other workers...');
if (killWatchers) {
await killOtherWorkers();
}
if (!isSudo && sudo) {
console.log(chalk.red('Tipi needs to run as root to start. Use sudo ./runtipi-cli start'));
throw new Error('Tipi needs to run as root to start. Use sudo ./runtipi-cli start');
if (!dockerVersion) {
spinner.fail('Your user is not allowed to run docker commands. Please add your user to the docker group or run Tipi as root.');
return { success: false, message: 'You need to be in the docker group to run Tipi' };
}
spinner.done('User allowed to run docker commands');
spinner.setMessage('Copying system files...');
spinner.start();
@ -211,10 +116,6 @@ export class SystemExecutors {
spinner.done('System files copied');
if (sudo) {
await this.ensureFilePermissions(this.rootFolder);
}
spinner.setMessage('Generating system env file...');
spinner.start();
this.logger.info('Generating system env file...');
@ -241,66 +142,6 @@ export class SystemExecutors {
await execAsync(`docker compose --env-file ${this.envFile} up --detach --remove-orphans --build`);
spinner.done('Containers started');
// start watcher cli in the background
spinner.setMessage('Starting watcher...');
spinner.start();
this.logger.info('Generating TLS certificates...');
await generateTlsCertificates({ domain: envMap.get('LOCAL_DOMAIN') });
if (killWatchers) {
this.logger.info('Starting watcher...');
const subprocess = spawn('./runtipi-cli', [process.argv[1] as string, 'watch'], { cwd: this.rootFolder, detached: true, stdio: ['ignore', 'ignore', 'ignore'] });
subprocess.unref();
}
spinner.done('Watcher started');
// Flush redis cache
this.logger.info('Flushing redis cache...');
const cache = new Redis({ host: '127.0.0.1', port: 6379, password: envMap.get('REDIS_PASSWORD'), lazyConnect: true });
await cache.connect();
await cache.flushdb();
await cache.quit();
this.logger.info('Starting queue...');
const queue = new Queue('events', { connection: { host: '127.0.0.1', port: 6379, password: envMap.get('REDIS_PASSWORD') } });
this.logger.info('Obliterating queue...');
await queue.obliterate({ force: true });
// Initial jobs
this.logger.info('Adding initial jobs to queue...');
await queue.add(`${Math.random().toString()}_system_info`, { type: 'system', command: 'system_info' } as SystemEvent);
await queue.add(`${Math.random().toString()}_repo_clone`, { type: 'repo', command: 'clone', url: envMap.get('APPS_REPO_URL') } as SystemEvent);
await queue.add(`${Math.random().toString()}_repo_update`, { type: 'repo', command: 'update', url: envMap.get('APPS_REPO_URL') } as SystemEvent);
// Scheduled jobs
this.logger.info('Adding scheduled jobs to queue...');
await queue.add(`${Math.random().toString()}_repo_update`, { type: 'repo', command: 'update', url: envMap.get('APPS_REPO_URL') } as SystemEvent, { repeat: { pattern: '*/30 * * * *' } });
await queue.add(`${Math.random().toString()}_system_info`, { type: 'system', command: 'system_info' } as SystemEvent, { repeat: { pattern: '* * * * *' } });
this.logger.info('Closing queue...');
await queue.close();
spinner.setMessage('Running database migrations...');
spinner.start();
this.logger.info('Running database migrations...');
await runPostgresMigrations({
postgresHost: '127.0.0.1',
postgresDatabase: envMap.get('POSTGRES_DBNAME') as string,
postgresUsername: envMap.get('POSTGRES_USERNAME') as string,
postgresPassword: envMap.get('POSTGRES_PASSWORD') as string,
postgresPort: envMap.get('POSTGRES_PORT') as string,
});
spinner.done('Database migrations complete');
// Start all apps
const appExecutor = new AppExecutors();
this.logger.info('Starting all apps...');
await appExecutor.startAllApps();
console.log(
boxen(
`Visit: http://${envMap.get('INTERNAL_IP')}:${envMap.get(
@ -332,7 +173,7 @@ export class SystemExecutors {
public restart = async () => {
try {
await this.stop();
await this.start(true, false);
await this.start();
return { success: true, message: '' };
} catch (e) {
return this.handleSystemError(e);

View file

@ -2,12 +2,8 @@ import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
import os from 'os';
import { envMapToString, envStringToMap, settingsSchema } from '@runtipi/shared';
import chalk from 'chalk';
import { pathExists } from '@/utils/fs-helpers';
import { getRepoHash } from '../repo/repo.helpers';
import { fileLogger } from '@/utils/logger/file-logger';
import { execAsync } from '@/utils/exec-async/execAsync';
import { envMapToString, envStringToMap, pathExists, settingsSchema } from '@runtipi/shared';
import { logger } from '@/utils/logger/logger';
type EnvKeys =
| 'APPS_REPO_ID'
@ -38,9 +34,6 @@ type EnvKeys =
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {});
const OLD_DEFAULT_REPO_URL = 'https://github.com/meienberger/runtipi-appstore';
const DEFAULT_REPO_URL = 'https://github.com/runtipi/runtipi-appstore';
/**
* Reads and returns the generated seed
*/
@ -147,173 +140,43 @@ export const generateSystemEnvFile = async () => {
const { data } = settings;
if (data.appsRepoUrl === OLD_DEFAULT_REPO_URL) {
data.appsRepoUrl = DEFAULT_REPO_URL;
}
const jwtSecret = envMap.get('JWT_SECRET') || (await deriveEntropy('jwt_secret'));
const repoId = getRepoHash(data.appsRepoUrl || DEFAULT_REPO_URL);
const postgresPassword = envMap.get('POSTGRES_PASSWORD') || (await deriveEntropy('postgres_password'));
const redisPassword = envMap.get('REDIS_PASSWORD') || (await deriveEntropy('redis_password'));
const version = await fs.promises.readFile(path.join(rootFolder, 'VERSION'), 'utf-8');
envMap.set('APPS_REPO_ID', repoId);
envMap.set('APPS_REPO_URL', data.appsRepoUrl || DEFAULT_REPO_URL);
envMap.set('TZ', Intl.DateTimeFormat().resolvedOptions().timeZone);
envMap.set('INTERNAL_IP', data.listenIp || getInternalIp());
envMap.set('DNS_IP', data.dnsIp || '9.9.9.9');
envMap.set('ARCHITECTURE', getArchitecture());
envMap.set('TIPI_VERSION', version);
envMap.set('JWT_SECRET', jwtSecret);
envMap.set('ROOT_FOLDER_HOST', rootFolder);
envMap.set('NGINX_PORT', String(data.port || 80));
envMap.set('NGINX_PORT_SSL', String(data.sslPort || 443));
envMap.set('DOMAIN', data.domain || 'example.com');
envMap.set('STORAGE_PATH', data.storagePath || rootFolder);
envMap.set('POSTGRES_HOST', 'tipi-db');
envMap.set('POSTGRES_DBNAME', 'tipi');
envMap.set('POSTGRES_USERNAME', 'tipi');
envMap.set('POSTGRES_PASSWORD', postgresPassword);
envMap.set('POSTGRES_PORT', String(5432));
envMap.set('POSTGRES_PORT', String(data.postgresPort || 5432));
envMap.set('REDIS_HOST', 'tipi-redis');
envMap.set('REDIS_PASSWORD', redisPassword);
envMap.set('DEMO_MODE', String(data.demoMode || 'false'));
envMap.set('GUEST_DASHBOARD', String(data.guestDashboard || 'false'));
envMap.set('LOCAL_DOMAIN', data.localDomain || 'tipi.lan');
envMap.set('NODE_ENV', 'production');
const currentUserGroup = process.getgid ? String(process.getgid()) : '1000';
const currentUserId = process.getuid ? String(process.getuid()) : '1000';
envMap.set('TIPI_GID', currentUserGroup);
envMap.set('TIPI_UID', currentUserId);
envMap.set('DOMAIN', data.domain || 'example.com');
envMap.set('LOCAL_DOMAIN', data.localDomain || 'tipi.lan');
await fs.promises.writeFile(envFilePath, envMapToString(envMap));
return envMap;
};
/**
* Sets the value of an environment variable in the .env file
*
* @param {string} key - The key of the environment variable
* @param {string} value - The value of the environment variable
*/
export const setEnvVariable = async (key: EnvKeys, value: string) => {
const rootFolder = process.cwd();
const envFilePath = path.join(rootFolder, '.env');
if (!(await pathExists(envFilePath))) {
await fs.promises.writeFile(envFilePath, '');
}
const envFile = await fs.promises.readFile(envFilePath, 'utf-8');
const envMap: Map<EnvKeys, string> = envStringToMap(envFile);
envMap.set(key, value);
await fs.promises.writeFile(envFilePath, envMapToString(envMap));
};
/**
* Copies the system files from the assets folder to the current working directory
*/
export const copySystemFiles = async () => {
// Remove old unused files
if (await pathExists(path.join(process.cwd(), 'scripts'))) {
fileLogger.info('Removing old scripts folder');
await fs.promises.rmdir(path.join(process.cwd(), 'scripts'), { recursive: true });
}
const assetsFolder = path.join('/snapshot', 'runtipi', 'packages', 'cli', 'assets');
// Copy docker-compose.yml file
fileLogger.info('Copying file docker-compose.yml');
logger.info('Copying file docker-compose.yml');
await fs.promises.copyFile(path.join(assetsFolder, 'docker-compose.yml'), path.join(process.cwd(), 'docker-compose.yml'));
// Copy VERSION file
fileLogger.info('Copying file VERSION');
logger.info('Copying file VERSION');
await fs.promises.copyFile(path.join(assetsFolder, 'VERSION'), path.join(process.cwd(), 'VERSION'));
// Copy traefik folder from assets
fileLogger.info('Creating traefik folders');
await fs.promises.mkdir(path.join(process.cwd(), 'traefik', 'dynamic'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'traefik', 'shared'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'traefik', 'tls'), { recursive: true });
fileLogger.info('Copying traefik files');
await fs.promises.copyFile(path.join(assetsFolder, 'traefik', 'traefik.yml'), path.join(process.cwd(), 'traefik', 'traefik.yml'));
await fs.promises.copyFile(path.join(assetsFolder, 'traefik', 'dynamic', 'dynamic.yml'), path.join(process.cwd(), 'traefik', 'dynamic', 'dynamic.yml'));
// Create base folders
fileLogger.info('Creating base folders');
await fs.promises.mkdir(path.join(process.cwd(), 'apps'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'app-data'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'state'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'repos'), { recursive: true });
// Create media folders
fileLogger.info('Creating media folders');
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'torrents', 'watch'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'torrents', 'complete'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'torrents', 'incomplete'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'usenet', 'watch'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'usenet', 'complete'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'usenet', 'incomplete'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'downloads', 'watch'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'downloads', 'complete'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'downloads', 'incomplete'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'data', 'books'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'data', 'comics'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'data', 'movies'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'data', 'music'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'data', 'tv'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'data', 'podcasts'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'data', 'images'), { recursive: true });
await fs.promises.mkdir(path.join(process.cwd(), 'media', 'data', 'roms'), { recursive: true });
};
/**
* Given a domain, generates the TLS certificates for it to be used with Traefik
*
* @param {string} data.domain The domain to generate the certificates for
*/
export const generateTlsCertificates = async (data: { domain?: string }) => {
if (!data.domain) {
return;
}
// If the certificate already exists, don't generate it again
if (await pathExists(path.join(process.cwd(), 'traefik', 'tls', `${data.domain}.txt`))) {
fileLogger.info(`TLS certificate for ${data.domain} already exists`);
return;
}
// Remove old certificates
if (await pathExists(path.join(process.cwd(), 'traefik', 'tls', 'cert.pem'))) {
fileLogger.info('Removing old TLS certificate');
await fs.promises.unlink(path.join(process.cwd(), 'traefik', 'tls', 'cert.pem'));
}
if (await pathExists(path.join(process.cwd(), 'traefik', 'tls', 'key.pem'))) {
fileLogger.info('Removing old TLS key');
await fs.promises.unlink(path.join(process.cwd(), 'traefik', 'tls', 'key.pem'));
}
const subject = `/O=runtipi.io/OU=IT/CN=*.${data.domain}/emailAddress=webmaster@${data.domain}`;
const subjectAltName = `DNS:*.${data.domain},DNS:${data.domain}`;
try {
fileLogger.info(`Generating TLS certificate for ${data.domain}`);
await execAsync(`openssl req -x509 -newkey rsa:4096 -keyout traefik/tls/key.pem -out traefik/tls/cert.pem -days 365 -subj "${subject}" -addext "subjectAltName = ${subjectAltName}" -nodes`);
fileLogger.info(`Writing txt file for ${data.domain}`);
await fs.promises.writeFile(path.join(process.cwd(), 'traefik', 'tls', `${data.domain}.txt`), '');
} catch (error) {
fileLogger.error(error);
console.error(chalk.red('✗'), 'Failed to generate TLS certificates');
}
};

View file

@ -3,7 +3,6 @@ import { program } from 'commander';
import chalk from 'chalk';
import { description, version } from '../package.json';
import { startWorker } from './services/watcher/watcher';
import { AppExecutors, SystemExecutors } from './executors';
const main = async () => {
@ -11,22 +10,13 @@ const main = async () => {
program.name('./runtipi-cli').usage('<command> [options]');
program
.command('watch')
.description('Watcher script for events queue')
.action(async () => {
console.log('Starting watcher');
startWorker();
});
program
.command('start')
.description('Start tipi')
.addHelpText('after', '\nExample call: sudo ./runtipi-cli start')
.option('--no-sudo', 'Skip sudo usage')
.action(async (options) => {
.action(async () => {
const systemExecutors = new SystemExecutors();
await systemExecutors.start(options.sudo);
await systemExecutors.start();
});
program
@ -81,10 +71,10 @@ const main = async () => {
const appExecutors = new AppExecutors();
switch (command) {
case 'start':
await appExecutors.startApp(app, {});
await appExecutors.startApp(app);
break;
case 'stop':
await appExecutors.stopApp(app, {}, true);
await appExecutors.stopApp(app);
break;
default:
console.log(chalk.red('✗'), 'Unknown command');

View file

@ -1,12 +0,0 @@
/**
* Returns the user id and group id of the current user
*/
export const getUserIds = () => {
if (process.getgid && process.getuid) {
const isSudo = process.getgid() === 0 && process.getuid() === 0;
return { uid: process.getuid(), gid: process.getgid(), isSudo };
}
return { uid: 1000, gid: 1000, isSudo: false };
};

View file

@ -0,0 +1,4 @@
import { FileLogger } from '@runtipi/shared';
import path from 'node:path';
export const logger = new FileLogger('cli', path.join(process.cwd(), 'logs'));

View file

@ -1 +1,2 @@
export * from './env-helpers';
export * from './fs-helpers';

View file

@ -1,3 +1,5 @@
export * from './schemas';
export * from './helpers';
export { createLogger } from './utils/logger';
export { FileLogger } from './lib/FileLogger';
export { execAsync } from './lib/exec-async';

View file

@ -1,6 +1,6 @@
import fs from 'fs';
import { createLogger } from '@runtipi/shared';
import path from 'path';
import { createLogger } from '../../utils/logger';
function streamLogToHistory(logsFolder: string, logFile: string) {
return new Promise((resolve, reject) => {
@ -19,10 +19,15 @@ function streamLogToHistory(logsFolder: string, logFile: string) {
});
}
class FileLogger {
private winstonLogger = createLogger('cli', path.join(process.cwd(), 'logs'));
export class FileLogger {
private winstonLogger;
private logsFolder = path.join(process.cwd(), 'logs');
private logsFolder;
constructor(name: string, folder: string, console?: boolean) {
this.winstonLogger = createLogger(name, folder, console);
this.logsFolder = folder;
}
public flush = async () => {
try {
@ -54,5 +59,3 @@ class FileLogger {
this.winstonLogger.debug(message.join(' '));
};
}
export const fileLogger = new FileLogger();

View file

@ -0,0 +1 @@
export { FileLogger } from './FileLogger';

View file

@ -0,0 +1,20 @@
import { exec } from 'child_process';
import { promisify } from 'util';
type ExecAsyncParams = [command: string];
type ExecResult = { stdout: string; stderr: string };
export const execAsync = async (...args: ExecAsyncParams): Promise<ExecResult> => {
try {
const { stdout, stderr } = await promisify(exec)(...args);
return { stdout, stderr };
} catch (error) {
if (error instanceof Error) {
return { stderr: error.message, stdout: '' };
}
return { stderr: String(error), stdout: '' };
}
};

View file

@ -0,0 +1 @@
export { execAsync } from './execAsync';

View file

@ -11,7 +11,6 @@ export const envSchema = z.object({
NODE_ENV: z.union([z.literal('development'), z.literal('production'), z.literal('test')]),
REDIS_HOST: z.string(),
redisPassword: z.string(),
status: z.union([z.literal('RUNNING'), z.literal('UPDATING'), z.literal('RESTARTING')]),
architecture: z.nativeEnum(ARCHITECTURES),
dnsIp: z.string().ip().trim(),
rootFolder: z.string(),
@ -59,9 +58,17 @@ export const envSchema = z.object({
if (typeof value === 'boolean') return value;
return value === 'true';
}),
allowAutoThemes: z
.string()
.or(z.boolean())
.optional()
.transform((value) => {
if (typeof value === 'boolean') return value;
return value === 'true';
}),
});
export const settingsSchema = envSchema
.partial()
.pick({ dnsIp: true, internalIp: true, appsRepoUrl: true, domain: true, storagePath: true, localDomain: true, demoMode: true, guestDashboard: true })
.pick({ dnsIp: true, internalIp: true, postgresPort: true, appsRepoUrl: true, domain: true, storagePath: true, localDomain: true, demoMode: true, guestDashboard: true, allowAutoThemes: true })
.and(z.object({ port: z.number(), sslPort: z.number(), listenIp: z.string().ip().trim() }).partial());

View file

@ -12,6 +12,7 @@ const appCommandSchema = z.object({
type: z.literal(EVENT_TYPES.APP),
command: z.union([z.literal('start'), z.literal('stop'), z.literal('install'), z.literal('uninstall'), z.literal('update'), z.literal('generate_env')]),
appid: z.string(),
skipEnv: z.boolean().optional().default(false),
form: z.object({}).catchall(z.any()),
});
@ -23,20 +24,14 @@ const repoCommandSchema = z.object({
const systemCommandSchema = z.object({
type: z.literal(EVENT_TYPES.SYSTEM),
command: z.union([z.literal('restart'), z.literal('system_info')]),
command: z.literal('system_info'),
});
const updateSchema = z.object({
type: z.literal(EVENT_TYPES.SYSTEM),
command: z.literal('update'),
version: z.string(),
});
export const eventSchema = appCommandSchema.or(repoCommandSchema).or(systemCommandSchema).or(updateSchema);
export const eventSchema = appCommandSchema.or(repoCommandSchema).or(systemCommandSchema);
export const eventResultSchema = z.object({
success: z.boolean(),
stdout: z.string(),
});
export type SystemEvent = z.infer<typeof eventSchema>;
export type SystemEvent = z.input<typeof eventSchema>;

View file

@ -12,7 +12,7 @@ type Transports = transports.ConsoleTransportInstance | transports.FileTransport
* @param {string} id - The id of the logger, used to identify the logger in the logs
* @param {string} logsFolder - The folder where the logs will be stored
*/
export const newLogger = (id: string, logsFolder: string) => {
export const newLogger = (id: string, logsFolder: string, console?: boolean) => {
if (!fs.existsSync(logsFolder)) {
fs.mkdirSync(logsFolder, { recursive: true });
}
@ -36,6 +36,8 @@ export const newLogger = (id: string, logsFolder: string) => {
if (process.env.NODE_ENV === 'development') {
tr.push(new transports.Console({ level: 'debug' }));
} else if (console) {
tr.push(new transports.Console({ level: 'info' }));
}
return createLogger({

14
packages/worker/.env.test Normal file
View file

@ -0,0 +1,14 @@
INTERNAL_IP=localhost
ARCHITECTURE=arm64
APPS_REPO_ID=repo-id
APPS_REPO_URL=https://test.com/test
ROOT_FOLDER_HOST=/runtipi
STORAGE_PATH=/runtipi
TIPI_VERSION=1
REDIS_PASSWORD=redis
REDIS_HOST=localhost
POSTGRES_HOST=localhost
POSTGRES_DBNAME=postgres
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_PORT=5433

View file

@ -0,0 +1,39 @@
module.exports = {
root: true,
plugins: ['@typescript-eslint', 'import'],
extends: ['plugin:@typescript-eslint/recommended', 'airbnb', 'airbnb-typescript', 'eslint:recommended', 'plugin:import/typescript', 'prettier'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
rules: {
'import/prefer-default-export': 0,
'class-methods-use-this': 0,
'import/extensions': [
'error',
'ignorePackages',
{
'': 'never',
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
},
],
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: ['build.js', '**/*.test.{ts,tsx}', '**/mocks/**', '**/__mocks__/**', '**/*.setup.{ts,js}', '**/*.config.{ts,js}', '**/tests/**'],
},
],
'arrow-body-style': 0,
'no-underscore-dangle': 0,
'no-console': 0,
},
globals: {
NodeJS: true,
},
};

2
packages/worker/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
dist/
coverage/

View file

@ -0,0 +1,6 @@
module.exports = {
singleQuote: true,
semi: true,
trailingComma: 'all',
printWidth: 200,
};

View file

@ -0,0 +1,67 @@
ARG NODE_VERSION="18.16"
ARG ALPINE_VERSION="3.18"
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS node_base
# ---- BUILDER BASE ----
FROM node_base AS builder_base
RUN npm install pnpm -g
RUN apk add curl
# ---- RUNNER BASE ----
FROM node_base AS runner_base
RUN apk add curl openssl git && rm -rf /var/cache/apk/*
ARG NODE_ENV="production"
# ---- BUILDER ----
FROM builder_base AS builder
WORKDIR /app
ARG TARGETARCH
ENV TARGETARCH=${TARGETARCH}
RUN echo "Building for ${TARGETARCH}"
RUN if [ "${TARGETARCH}" = "arm64" ]; then \
curl -L -o docker-binary "https://github.com/docker/compose/releases/download/v2.23.1/docker-compose-linux-aarch64"; \
elif [ "${TARGETARCH}" = "amd64" ]; then \
curl -L -o docker-binary "https://github.com/docker/compose/releases/download/v2.23.1/docker-compose-linux-x86_64"; \
else \
echo "Unsupported architecture"; \
fi
RUN chmod +x docker-binary
COPY ./pnpm-lock.yaml ./
COPY ./pnpm-workspace.yaml ./
COPY ./patches ./patches
RUN pnpm fetch --no-scripts
COPY ./packages ./packages
RUN pnpm install -r --prefer-offline
COPY ./packages/worker/build.js ./packages/worker/build.js
COPY ./packages/worker/src ./packages/worker/src
COPY ./packages/worker/package.json ./packages/worker/package.json
COPY ./packages/worker/assets ./packages/worker/assets
RUN pnpm -r build --filter @runtipi/worker
# ---- RUNNER ----
FROM runner_base AS app
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/packages/worker/dist .
COPY --from=builder /app/packages/worker/assets ./assets
COPY --from=builder /app/docker-binary /usr/local/bin/docker-compose
CMD ["node", "index.js", "start"]

View file

@ -0,0 +1,41 @@
ARG NODE_VERSION="18.16"
ARG ALPINE_VERSION="3.18"
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS node_base
# Install docker
RUN apk upgrade --update-cache --available && \
apk add openssl git docker docker-cli-compose curl && \
rm -rf /var/cache/apk/*
ARG TARGETARCH
ENV TARGETARCH=${TARGETARCH}
RUN echo "Building for ${TARGETARCH}"
RUN if [ "${TARGETARCH}" = "arm64" ]; then \
curl -L -o docker-binary "https://github.com/docker/compose/releases/download/v2.23.1/docker-compose-linux-aarch64"; \
elif [ "${TARGETARCH}" = "amd64" ]; then \
curl -L -o docker-binary "https://github.com/docker/compose/releases/download/v2.23.1/docker-compose-linux-x86_64"; \
fi
RUN chmod +x docker-binary
RUN mv docker-binary /usr/local/bin/docker-compose
RUN npm install pnpm -g
WORKDIR /app
COPY ./pnpm-lock.yaml ./
COPY ./pnpm-workspace.yaml ./
COPY ./patches ./patches
RUN pnpm fetch --no-scripts
COPY ./packages/worker/assets ./assets
COPY ./packages ./packages
RUN pnpm install -r --prefer-offline
CMD ["pnpm", "--filter", "@runtipi/worker", "-r", "dev"]

View file

@ -4,7 +4,7 @@ api:
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
endpoint: 'unix:///var/run/docker.sock'
watch: true
exposedByDefault: false
file:
@ -13,9 +13,9 @@ providers:
entryPoints:
web:
address: ":80"
address: ':80'
websecure:
address: ":443"
address: ':443'
http:
tls:
certResolver: myresolver
@ -23,7 +23,7 @@ entryPoints:
certificatesResolvers:
myresolver:
acme:
email: acme@thisprops.com
email: acme@thisprops.com
storage: /shared/acme.json
httpChallenge:
entryPoint: web

21
packages/worker/build.js Normal file
View file

@ -0,0 +1,21 @@
const { build } = require('esbuild');
const commandArgs = process.argv.slice(2);
async function bundle() {
const start = Date.now();
const options = {
entryPoints: ['./src/index.ts'],
outfile: './dist/index.js',
platform: 'node',
target: 'node18',
bundle: true,
color: true,
sourcemap: commandArgs.includes('--sourcemap'),
};
await build({ ...options, minify: true });
console.log(`Build time: ${Date.now() - start}ms`);
}
bundle();

View file

@ -0,0 +1,5 @@
{
"watch": ["src"],
"exec": "NODE_ENV=development tsx ./src/index.ts",
"ext": "js ts"
}

View file

@ -0,0 +1,42 @@
{
"name": "@runtipi/worker",
"version": "1.0.0",
"description": "",
"main": "src/index.ts",
"scripts": {
"test": "dotenv -e .env.test vitest -- --coverage --watch=false",
"test:watch": "dotenv -e .env.test vitest",
"build": "node build.js",
"tsc": "tsc",
"dev": "dotenv -e ../../.env nodemon",
"knip": "knip",
"lint": "eslint . --ext .ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@faker-js/faker": "^8.2.0",
"@types/web-push": "^3.6.3",
"dotenv-cli": "^7.3.0",
"esbuild": "^0.19.4",
"knip": "^2.41.3",
"memfs": "^4.6.0",
"nodemon": "^3.0.1",
"tsx": "^3.14.0",
"typescript": "^5.2.2",
"vite-tsconfig-paths": "^4.2.1",
"vitest": "^0.34.6"
},
"dependencies": {
"@runtipi/postgres-migrations": "^5.3.0",
"@runtipi/shared": "workspace:^",
"bullmq": "^4.13.0",
"dotenv": "^16.3.1",
"ioredis": "^5.3.2",
"pg": "^8.11.3",
"systeminformation": "^5.21.15",
"web-push": "^3.6.6",
"zod": "^3.22.4"
}
}

View file

@ -0,0 +1,2 @@
export const ROOT_FOLDER = '/app';
export const STORAGE_FOLDER = '/storage';

View file

@ -0,0 +1 @@
export * from './constants';

View file

@ -0,0 +1,94 @@
import { SystemEvent } from '@runtipi/shared';
import http from 'node:http';
import path from 'node:path';
import Redis from 'ioredis';
import dotenv from 'dotenv';
import { Queue } from 'bullmq';
import { copySystemFiles, ensureFilePermissions, generateSystemEnvFile, generateTlsCertificates } from '@/lib/system';
import { runPostgresMigrations } from '@/lib/migrations';
import { startWorker } from './watcher/watcher';
import { logger } from '@/lib/logger';
import { AppExecutors } from './services';
const rootFolder = '/app';
const envFile = path.join(rootFolder, '.env');
const main = async () => {
try {
await logger.flush();
logger.info('Copying system files...');
await copySystemFiles();
logger.info('Generating system env file...');
const envMap = await generateSystemEnvFile();
// Reload env variables after generating the env file
logger.info('Reloading env variables...');
dotenv.config({ path: envFile, override: true });
logger.info('Generating TLS certificates...');
await generateTlsCertificates({ domain: envMap.get('LOCAL_DOMAIN') });
logger.info('Ensuring file permissions...');
await ensureFilePermissions();
logger.info('Starting queue...');
const queue = new Queue('events', { connection: { host: envMap.get('REDIS_HOST'), port: 6379, password: envMap.get('REDIS_PASSWORD') } });
logger.info('Obliterating queue...');
await queue.obliterate({ force: true });
// Initial jobs
logger.info('Adding initial jobs to queue...');
await queue.add(`${Math.random().toString()}_system_info`, { type: 'system', command: 'system_info' } as SystemEvent);
await queue.add(`${Math.random().toString()}_repo_clone`, { type: 'repo', command: 'clone', url: envMap.get('APPS_REPO_URL') } as SystemEvent);
await queue.add(`${Math.random().toString()}_repo_update`, { type: 'repo', command: 'update', url: envMap.get('APPS_REPO_URL') } as SystemEvent);
// Scheduled jobs
logger.info('Adding scheduled jobs to queue...');
await queue.add(`${Math.random().toString()}_repo_update`, { type: 'repo', command: 'update', url: envMap.get('APPS_REPO_URL') } as SystemEvent, { repeat: { pattern: '*/30 * * * *' } });
await queue.add(`${Math.random().toString()}_system_info`, { type: 'system', command: 'system_info' } as SystemEvent, { repeat: { pattern: '* * * * *' } });
logger.info('Closing queue...');
await queue.close();
logger.info('Running database migrations...');
await runPostgresMigrations({
postgresHost: envMap.get('POSTGRES_HOST') as string,
postgresDatabase: envMap.get('POSTGRES_DBNAME') as string,
postgresUsername: envMap.get('POSTGRES_USERNAME') as string,
postgresPassword: envMap.get('POSTGRES_PASSWORD') as string,
postgresPort: envMap.get('POSTGRES_PORT') as string,
});
// Set status to running
logger.info('Setting status to running...');
const cache = new Redis({ host: envMap.get('REDIS_HOST'), port: 6379, password: envMap.get('REDIS_PASSWORD') });
await cache.set('status', 'RUNNING');
await cache.quit();
// Start all apps
const appExecutor = new AppExecutors();
logger.info('Starting all apps...');
appExecutor.startAllApps();
const server = http.createServer((req, res) => {
if (req.url === '/healthcheck') {
res.writeHead(200);
res.end('OK');
} else {
res.writeHead(404);
res.end('Not Found');
}
});
server.listen(3000, () => {
startWorker();
});
} catch (e) {
logger.error(e);
process.exit(1);
}
};
main();

View file

@ -0,0 +1,125 @@
// const spy = vi.spyOn(dockerHelpers, 'compose').mockImplementation(() => Promise.resolve({ stdout: '', stderr: randomError }));
import { vi, it, describe, expect } from 'vitest';
import { faker } from '@faker-js/faker';
import fs from 'fs';
import { compose } from './docker-helpers';
const execAsync = vi.fn().mockImplementation(() => Promise.resolve({ stdout: '', stderr: '' }));
vi.mock('@runtipi/shared', async (importOriginal) => {
const mod = (await importOriginal()) as object;
return {
...mod,
FileLogger: vi.fn().mockImplementation(() => ({
flush: vi.fn(),
error: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
debug: vi.fn(),
})),
execAsync: (cmd: string) => execAsync(cmd),
};
});
describe('docker helpers', async () => {
it('should call execAsync with correct args', async () => {
// arrange
const appId = faker.word.noun().toLowerCase();
const command = faker.word.noun().toLowerCase();
// act
await compose(appId, command);
// assert
const expected = [
'docker-compose',
`--env-file /storage/app-data/${appId}/app.env`,
`--project-name ${appId}`,
`-f /app/apps/${appId}/docker-compose.yml`,
'-f /app/repos/repo-id/apps/docker-compose.common.yml',
command,
].join(' ');
expect(execAsync).toHaveBeenCalledWith(expected);
});
it('should add user env file if exists', async () => {
// arrange
const appId = faker.word.noun().toLowerCase();
const command = faker.word.noun().toLowerCase();
await fs.promises.mkdir(`/app/user-config/${appId}`, { recursive: true });
const userEnvFile = `/app/user-config/${appId}/app.env`;
await fs.promises.writeFile(userEnvFile, 'test');
// act
await compose(appId, command);
// assert
const expected = [
'docker-compose',
`--env-file /storage/app-data/${appId}/app.env`,
`--env-file ${userEnvFile}`,
`--project-name ${appId}`,
`-f /app/apps/${appId}/docker-compose.yml`,
'-f /app/repos/repo-id/apps/docker-compose.common.yml',
command,
].join(' ');
expect(execAsync).toHaveBeenCalledWith(expected);
});
it('should add user compose file if exists', async () => {
// arrange
const appId = faker.word.noun().toLowerCase();
const command = faker.word.noun().toLowerCase();
await fs.promises.mkdir(`/app/user-config/${appId}`, { recursive: true });
const userComposeFile = `/app/user-config/${appId}/docker-compose.yml`;
await fs.promises.writeFile(userComposeFile, 'test');
// act
await compose(appId, command);
// assert
const expected = [
'docker-compose',
`--env-file /storage/app-data/${appId}/app.env`,
`--project-name ${appId}`,
`-f /app/apps/${appId}/docker-compose.yml`,
'-f /app/repos/repo-id/apps/docker-compose.common.yml',
`--file ${userComposeFile}`,
command,
].join(' ');
expect(execAsync).toHaveBeenCalledWith(expected);
});
it('should add arm64 compose file if exists and arch is arm64', async () => {
// arrange
vi.mock('@/lib/environment', async (importOriginal) => {
const mod = (await importOriginal()) as object;
return { ...mod, getEnv: () => ({ arch: 'arm64', appsRepoId: 'repo-id' }) };
});
const appId = faker.word.noun().toLowerCase();
const command = faker.word.noun().toLowerCase();
await fs.promises.mkdir(`/app/apps/${appId}`, { recursive: true });
const arm64ComposeFile = `/app/apps/${appId}/docker-compose.arm64.yml`;
await fs.promises.writeFile(arm64ComposeFile, 'test');
// act
await compose(appId, command);
// assert
const expected = [
'docker-compose',
`--env-file /storage/app-data/${appId}/app.env`,
`--project-name ${appId}`,
`-f ${arm64ComposeFile}`,
`-f /app/repos/repo-id/apps/docker-compose.common.yml`,
command,
].join(' ');
expect(execAsync).toHaveBeenCalledWith(expected);
});
});

View file

@ -1,12 +1,16 @@
import path from 'path';
import { getEnv } from '../environment/environment';
import { pathExists } from '../fs-helpers/fs-helpers';
import { fileLogger } from '../logger/file-logger';
import { execAsync } from '../exec-async/execAsync';
import { execAsync, pathExists } from '@runtipi/shared';
import { logger } from '@/lib/logger';
import { getEnv } from '@/lib/environment';
import { ROOT_FOLDER, STORAGE_FOLDER } from '@/config/constants';
const composeUp = async (args: string[]) => {
fileLogger.info(`Running docker compose with args ${args.join(' ')}`);
const { stdout, stderr } = await execAsync(`docker compose ${args.join(' ')}`);
logger.info(`Running docker compose with args ${args.join(' ')}`);
const { stdout, stderr } = await execAsync(`docker-compose ${args.join(' ')}`);
if (stderr && stderr.includes('Command failed:')) {
throw new Error(stderr);
}
return { stdout, stderr };
};
@ -17,14 +21,14 @@ const composeUp = async (args: string[]) => {
* @param {string} command - Command to execute
*/
export const compose = async (appId: string, command: string) => {
const { arch, rootFolderHost, appsRepoId, storagePath } = getEnv();
const appDataDirPath = path.join(storagePath, 'app-data', appId);
const appDirPath = path.join(rootFolderHost, 'apps', appId);
const { arch, appsRepoId } = getEnv();
const appDataDirPath = path.join(STORAGE_FOLDER, 'app-data', appId);
const appDirPath = path.join(ROOT_FOLDER, 'apps', appId);
const args: string[] = [`--env-file ${path.join(appDataDirPath, 'app.env')}`];
// User custom env file
const userEnvFile = path.join(rootFolderHost, 'user-config', appId, 'app.env');
const userEnvFile = path.join(ROOT_FOLDER, 'user-config', appId, 'app.env');
if (await pathExists(userEnvFile)) {
args.push(`--env-file ${userEnvFile}`);
}
@ -37,11 +41,11 @@ export const compose = async (appId: string, command: string) => {
}
args.push(`-f ${composeFile}`);
const commonComposeFile = path.join(rootFolderHost, 'repos', appsRepoId, 'apps', 'docker-compose.common.yml');
const commonComposeFile = path.join(ROOT_FOLDER, 'repos', appsRepoId, 'apps', 'docker-compose.common.yml');
args.push(`-f ${commonComposeFile}`);
// User defined overrides
const userComposeFile = path.join(rootFolderHost, 'user-config', appId, 'docker-compose.yml');
const userComposeFile = path.join(ROOT_FOLDER, 'user-config', appId, 'docker-compose.yml');
if (await pathExists(userComposeFile)) {
args.push(`--file ${userComposeFile}`);
}

View file

@ -0,0 +1,62 @@
import { z } from 'zod';
import dotenv from 'dotenv';
if (process.env.NODE_ENV === 'development') {
dotenv.config({ path: '.env.dev', override: true });
} else {
dotenv.config({ override: true });
}
const environmentSchema = z
.object({
STORAGE_PATH: z.string(),
ROOT_FOLDER_HOST: z.string(),
APPS_REPO_ID: z.string(),
ARCHITECTURE: z.enum(['arm64', 'amd64']),
INTERNAL_IP: z.string().ip().or(z.literal('localhost')),
TIPI_VERSION: z.string(),
REDIS_PASSWORD: z.string(),
REDIS_HOST: z.string(),
POSTGRES_PORT: z.string(),
POSTGRES_USERNAME: z.string(),
POSTGRES_PASSWORD: z.string(),
POSTGRES_DBNAME: z.string(),
POSTGRES_HOST: z.string(),
})
.transform((env) => {
const {
STORAGE_PATH = '/app',
ARCHITECTURE,
ROOT_FOLDER_HOST,
APPS_REPO_ID,
INTERNAL_IP,
TIPI_VERSION,
REDIS_PASSWORD,
REDIS_HOST,
POSTGRES_DBNAME,
POSTGRES_PASSWORD,
POSTGRES_USERNAME,
POSTGRES_PORT,
POSTGRES_HOST,
...rest
} = env;
return {
storagePath: STORAGE_PATH,
rootFolderHost: ROOT_FOLDER_HOST,
appsRepoId: APPS_REPO_ID,
arch: ARCHITECTURE,
tipiVersion: TIPI_VERSION,
internalIp: INTERNAL_IP,
redisPassword: REDIS_PASSWORD,
redisHost: REDIS_HOST,
postgresPort: POSTGRES_PORT,
postgresUsername: POSTGRES_USERNAME,
postgresPassword: POSTGRES_PASSWORD,
postgresDatabase: POSTGRES_DBNAME,
postgresHost: POSTGRES_HOST,
...rest,
};
});
export const getEnv = () => environmentSchema.parse(process.env);

View file

@ -0,0 +1 @@
export { getEnv } from './environment';

View file

@ -0,0 +1 @@
export { logger } from './logger';

View file

@ -0,0 +1,4 @@
import { FileLogger } from '@runtipi/shared';
import path from 'node:path';
export const logger = new FileLogger('worker', path.join('/app', 'logs'), true);

View file

@ -0,0 +1 @@
export { runPostgresMigrations } from './run-migration';

View file

@ -1,7 +1,8 @@
import path from 'path';
import pg from 'pg';
import { migrate } from '@runtipi/postgres-migrations';
import { fileLogger } from '../logger/file-logger';
import { logger } from '@/lib/logger';
import { ROOT_FOLDER } from '@/config/constants';
type MigrationParams = {
postgresHost: string;
@ -12,13 +13,13 @@ type MigrationParams = {
};
export const runPostgresMigrations = async (params: MigrationParams) => {
const assetsFolder = path.join('/snapshot', 'runtipi', 'packages', 'cli', 'assets');
const assetsFolder = path.join(ROOT_FOLDER, 'assets');
const { postgresHost, postgresDatabase, postgresUsername, postgresPassword, postgresPort } = params;
fileLogger.info('Starting database migration');
logger.info('Starting database migration');
fileLogger.info(`Connecting to database ${postgresDatabase} on ${postgresHost} as ${postgresUsername} on port ${postgresPort}`);
logger.info(`Connecting to database ${postgresDatabase} on ${postgresHost} as ${postgresUsername} on port ${postgresPort}`);
const client = new pg.Client({
user: postgresUsername,
@ -29,28 +30,28 @@ export const runPostgresMigrations = async (params: MigrationParams) => {
});
await client.connect();
fileLogger.info('Client connected');
logger.info('Client connected');
try {
const { rows } = await client.query('SELECT * FROM migrations');
// if rows contains a migration with name 'Initial1657299198975' (legacy typeorm) delete table migrations. As all migrations are idempotent we can safely delete the table and start over.
if (rows.find((row) => row.name === 'Initial1657299198975')) {
fileLogger.info('Found legacy migration. Deleting table migrations');
logger.info('Found legacy migration. Deleting table migrations');
await client.query('DROP TABLE migrations');
}
} catch (e) {
fileLogger.info('Migrations table not found, creating it');
logger.info('Migrations table not found, creating it');
}
fileLogger.info('Running migrations');
logger.info('Running migrations');
try {
await migrate({ client }, path.join(assetsFolder, 'migrations'), { skipCreateMigrationTable: true });
} catch (e) {
fileLogger.error('Error running migrations. Dropping table migrations and trying again');
logger.error('Error running migrations. Dropping table migrations and trying again');
await client.query('DROP TABLE migrations');
await migrate({ client }, path.join(assetsFolder, 'migrations'), { skipCreateMigrationTable: true });
}
fileLogger.info('Migration complete');
logger.info('Migration complete');
await client.end();
};

View file

@ -0,0 +1 @@
export { copySystemFiles, generateSystemEnvFile, ensureFilePermissions, generateTlsCertificates } from './system.helpers';

View file

@ -0,0 +1,278 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-restricted-syntax */
import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
import os from 'os';
import { envMapToString, envStringToMap, execAsync, pathExists, settingsSchema } from '@runtipi/shared';
import { logger } from '../logger/logger';
import { getRepoHash } from '../../services/repo/repo.helpers';
import { ROOT_FOLDER } from '@/config/constants';
type EnvKeys =
| 'APPS_REPO_ID'
| 'APPS_REPO_URL'
| 'TZ'
| 'INTERNAL_IP'
| 'DNS_IP'
| 'ARCHITECTURE'
| 'TIPI_VERSION'
| 'JWT_SECRET'
| 'ROOT_FOLDER_HOST'
| 'NGINX_PORT'
| 'NGINX_PORT_SSL'
| 'DOMAIN'
| 'STORAGE_PATH'
| 'POSTGRES_PORT'
| 'POSTGRES_HOST'
| 'POSTGRES_DBNAME'
| 'POSTGRES_PASSWORD'
| 'POSTGRES_USERNAME'
| 'REDIS_HOST'
| 'REDIS_PASSWORD'
| 'LOCAL_DOMAIN'
| 'DEMO_MODE'
| 'GUEST_DASHBOARD'
| 'TIPI_GID'
| 'TIPI_UID'
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {});
const OLD_DEFAULT_REPO_URL = 'https://github.com/meienberger/runtipi-appstore';
const DEFAULT_REPO_URL = 'https://github.com/runtipi/runtipi-appstore';
/**
* Reads and returns the generated seed
*/
const getSeed = async () => {
const seedFilePath = path.join(ROOT_FOLDER, 'state', 'seed');
if (!(await pathExists(seedFilePath))) {
throw new Error('Seed file not found');
}
const seed = await fs.promises.readFile(seedFilePath, 'utf-8');
return seed;
};
/**
* Derives a new entropy value from the provided entropy and the seed
* @param {string} entropy - The entropy value to derive from
*/
const deriveEntropy = async (entropy: string) => {
const seed = await getSeed();
const hmac = crypto.createHmac('sha256', seed);
hmac.update(entropy);
return hmac.digest('hex');
};
/**
* Generates a random seed if it does not exist yet
*/
const generateSeed = async () => {
if (!(await pathExists(path.join(ROOT_FOLDER, 'state', 'seed')))) {
const randomBytes = crypto.randomBytes(32);
const seed = randomBytes.toString('hex');
await fs.promises.writeFile(path.join(ROOT_FOLDER, 'state', 'seed'), seed);
}
};
/**
* Returns the architecture of the current system
*/
const getArchitecture = () => {
const arch = os.arch();
if (arch === 'arm64') return 'arm64';
if (arch === 'x64') return 'amd64';
throw new Error(`Unsupported architecture: ${arch}`);
};
/**
* Generates a valid .env file from the settings.json file
*/
export const generateSystemEnvFile = async () => {
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'state'), { recursive: true });
const settingsFilePath = path.join(ROOT_FOLDER, 'state', 'settings.json');
const envFilePath = path.join(ROOT_FOLDER, '.env');
if (!(await pathExists(envFilePath))) {
await fs.promises.writeFile(envFilePath, '');
}
const envFile = await fs.promises.readFile(envFilePath, 'utf-8');
const envMap: Map<EnvKeys, string> = envStringToMap(envFile);
if (!(await pathExists(settingsFilePath))) {
await fs.promises.writeFile(settingsFilePath, JSON.stringify({}));
}
const settingsFile = await fs.promises.readFile(settingsFilePath, 'utf-8');
const settings = settingsSchema.safeParse(JSON.parse(settingsFile));
if (!settings.success) {
throw new Error(`Invalid settings.json file: ${settings.error.message}`);
}
await generateSeed();
const { data } = settings;
if (data.appsRepoUrl === OLD_DEFAULT_REPO_URL) {
data.appsRepoUrl = DEFAULT_REPO_URL;
}
const jwtSecret = envMap.get('JWT_SECRET') || (await deriveEntropy('jwt_secret'));
const repoId = getRepoHash(data.appsRepoUrl || DEFAULT_REPO_URL);
const rootFolderHost = envMap.get('ROOT_FOLDER_HOST');
const internalIp = envMap.get('INTERNAL_IP');
if (!rootFolderHost) {
throw new Error('ROOT_FOLDER_HOST not set in .env file');
}
if (!internalIp) {
throw new Error('INTERNAL_IP not set in .env file');
}
envMap.set('APPS_REPO_ID', repoId);
envMap.set('APPS_REPO_URL', data.appsRepoUrl || DEFAULT_REPO_URL);
envMap.set('TZ', Intl.DateTimeFormat().resolvedOptions().timeZone);
envMap.set('INTERNAL_IP', data.listenIp || internalIp);
envMap.set('DNS_IP', data.dnsIp || '9.9.9.9');
envMap.set('ARCHITECTURE', getArchitecture());
envMap.set('JWT_SECRET', jwtSecret);
envMap.set('DOMAIN', data.domain || 'example.com');
envMap.set('STORAGE_PATH', data.storagePath || envMap.get('STORAGE_PATH') || rootFolderHost);
envMap.set('POSTGRES_HOST', 'tipi-db');
envMap.set('POSTGRES_DBNAME', 'tipi');
envMap.set('POSTGRES_USERNAME', 'tipi');
envMap.set('POSTGRES_PORT', String(5432));
envMap.set('REDIS_HOST', 'tipi-redis');
envMap.set('DEMO_MODE', String(data.demoMode || 'false'));
envMap.set('GUEST_DASHBOARD', String(data.guestDashboard || 'false'));
envMap.set('LOCAL_DOMAIN', data.localDomain || 'tipi.lan');
envMap.set('NODE_ENV', 'production');
await fs.promises.writeFile(envFilePath, envMapToString(envMap));
return envMap;
};
/**
* Copies the system files from the assets folder to the current working directory
*/
export const copySystemFiles = async () => {
// Remove old unused files
if (await pathExists(path.join(ROOT_FOLDER, 'scripts'))) {
logger.info('Removing old scripts folder');
await fs.promises.rmdir(path.join(ROOT_FOLDER, 'scripts'), { recursive: true });
}
const assetsFolder = path.join(ROOT_FOLDER, 'assets');
// Copy traefik folder from assets
logger.info('Creating traefik folders');
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'traefik', 'dynamic'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'traefik', 'shared'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'traefik', 'tls'), { recursive: true });
logger.info('Copying traefik files');
await fs.promises.copyFile(path.join(assetsFolder, 'traefik', 'traefik.yml'), path.join(ROOT_FOLDER, 'traefik', 'traefik.yml'));
await fs.promises.copyFile(path.join(assetsFolder, 'traefik', 'dynamic', 'dynamic.yml'), path.join(ROOT_FOLDER, 'traefik', 'dynamic', 'dynamic.yml'));
// Create base folders
logger.info('Creating base folders');
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'apps'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'app-data'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'state'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'repos'), { recursive: true });
// Create media folders
logger.info('Creating media folders');
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'torrents', 'watch'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'torrents', 'complete'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'torrents', 'incomplete'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'usenet', 'watch'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'usenet', 'complete'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'usenet', 'incomplete'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'downloads', 'watch'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'downloads', 'complete'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'downloads', 'incomplete'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'data', 'books'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'data', 'comics'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'data', 'movies'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'data', 'music'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'data', 'tv'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'data', 'podcasts'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'data', 'images'), { recursive: true });
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'media', 'data', 'roms'), { recursive: true });
};
/**
* Given a domain, generates the TLS certificates for it to be used with Traefik
*
* @param {string} data.domain The domain to generate the certificates for
*/
export const generateTlsCertificates = async (data: { domain?: string }) => {
if (!data.domain) {
return;
}
// If the certificate already exists, don't generate it again
if (await pathExists(path.join(ROOT_FOLDER, 'traefik', 'tls', `${data.domain}.txt`))) {
logger.info(`TLS certificate for ${data.domain} already exists`);
return;
}
// Remove old certificates
if (await pathExists(path.join(ROOT_FOLDER, 'traefik', 'tls', 'cert.pem'))) {
logger.info('Removing old TLS certificate');
await fs.promises.unlink(path.join(ROOT_FOLDER, 'traefik', 'tls', 'cert.pem'));
}
if (await pathExists(path.join(ROOT_FOLDER, 'traefik', 'tls', 'key.pem'))) {
logger.info('Removing old TLS key');
await fs.promises.unlink(path.join(ROOT_FOLDER, 'traefik', 'tls', 'key.pem'));
}
const subject = `/O=runtipi.io/OU=IT/CN=*.${data.domain}/emailAddress=webmaster@${data.domain}`;
const subjectAltName = `DNS:*.${data.domain},DNS:${data.domain}`;
try {
logger.info(`Generating TLS certificate for ${data.domain}`);
await execAsync(`openssl req -x509 -newkey rsa:4096 -keyout traefik/tls/key.pem -out traefik/tls/cert.pem -days 365 -subj "${subject}" -addext "subjectAltName = ${subjectAltName}" -nodes`);
logger.info(`Writing txt file for ${data.domain}`);
await fs.promises.writeFile(path.join(ROOT_FOLDER, 'traefik', 'tls', `${data.domain}.txt`), '');
} catch (error) {
logger.error(error);
}
};
export const ensureFilePermissions = async () => {
const filesAndFolders = [path.join(ROOT_FOLDER, 'state'), path.join(ROOT_FOLDER, 'traefik')];
const files600 = [path.join(ROOT_FOLDER, 'traefik', 'shared', 'acme.json')];
// Give permission to read and write to all files and folders for the current user
for (const fileOrFolder of filesAndFolders) {
if (await pathExists(fileOrFolder)) {
await execAsync(`chmod -R a+rwx ${fileOrFolder}`).catch(() => {});
}
}
for (const fileOrFolder of files600) {
if (await pathExists(fileOrFolder)) {
await execAsync(`chmod 600 ${fileOrFolder}`).catch(() => {});
}
}
};

View file

@ -2,13 +2,14 @@ import fs from 'fs';
import { describe, it, expect, vi } from 'vitest';
import path from 'path';
import { faker } from '@faker-js/faker';
import { pathExists } from '@runtipi/shared';
import { AppExecutors } from '../app.executors';
import { createAppConfig } from '@/tests/apps.factory';
import * as dockerHelpers from '@/utils/docker-helpers';
import { getEnv } from '@/utils/environment/environment';
import { pathExists } from '@/utils/fs-helpers';
import * as dockerHelpers from '@/lib/docker';
import { getEnv } from '@/lib/environment';
import { ROOT_FOLDER, STORAGE_FOLDER } from '@/config/constants';
const { storagePath, rootFolderHost, appsRepoId } = getEnv();
const { appsRepoId } = getEnv();
describe('test: app executors', () => {
const appExecutors = new AppExecutors();
@ -23,7 +24,7 @@ describe('test: app executors', () => {
const { message, success } = await appExecutors.installApp(config.id, config);
// assert
const envExists = await pathExists(path.join(storagePath, 'app-data', config.id, 'app.env'));
const envExists = await pathExists(path.join(STORAGE_FOLDER, 'app-data', config.id, 'app.env'));
expect(success).toBe(true);
expect(message).toBe(`App ${config.id} installed successfully`);
@ -32,17 +33,34 @@ describe('test: app executors', () => {
spy.mockRestore();
});
it('should return error if compose script fails', async () => {
// arrange
const randomError = faker.system.fileName();
const spy = vi.spyOn(dockerHelpers, 'compose').mockImplementation(() => {
throw new Error(randomError);
});
const config = createAppConfig({}, false);
// act
const { message, success } = await appExecutors.installApp(config.id, config);
// assert
expect(success).toBe(false);
expect(message).toContain(randomError);
spy.mockRestore();
});
it('should delete existing app folder', async () => {
// arrange
const config = createAppConfig();
await fs.promises.mkdir(path.join(rootFolderHost, 'apps', config.id), { recursive: true });
await fs.promises.writeFile(path.join(rootFolderHost, 'apps', config.id, 'test.txt'), 'test');
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'apps', config.id), { recursive: true });
await fs.promises.writeFile(path.join(ROOT_FOLDER, 'apps', config.id, 'test.txt'), 'test');
// act
await appExecutors.installApp(config.id, config);
// assert
const exists = await pathExists(path.join(storagePath, 'apps', config.id, 'test.txt'));
const exists = await pathExists(path.join(STORAGE_FOLDER, 'apps', config.id, 'test.txt'));
expect(exists).toBe(false);
});
@ -51,13 +69,13 @@ describe('test: app executors', () => {
// arrange
const config = createAppConfig();
const filename = faker.system.fileName();
await fs.promises.writeFile(path.join(storagePath, 'app-data', config.id, filename), 'test');
await fs.promises.writeFile(path.join(STORAGE_FOLDER, 'app-data', config.id, filename), 'test');
// act
await appExecutors.installApp(config.id, config);
// assert
const exists = await pathExists(path.join(storagePath, 'app-data', config.id, filename));
const exists = await pathExists(path.join(STORAGE_FOLDER, 'app-data', config.id, filename));
expect(exists).toBe(true);
});
@ -66,15 +84,15 @@ describe('test: app executors', () => {
// arrange
const config = createAppConfig({}, false);
const filename = faker.system.fileName();
await fs.promises.mkdir(path.join(rootFolderHost, 'repos', appsRepoId, 'apps', config.id, 'data'), { recursive: true });
await fs.promises.writeFile(path.join(rootFolderHost, 'repos', appsRepoId, 'apps', config.id, 'data', filename), 'test');
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'repos', appsRepoId, 'apps', config.id, 'data'), { recursive: true });
await fs.promises.writeFile(path.join(ROOT_FOLDER, 'repos', appsRepoId, 'apps', config.id, 'data', filename), 'test');
// act
await appExecutors.installApp(config.id, config);
// assert
const exists = await pathExists(path.join(storagePath, 'app-data', config.id, 'data', filename));
const data = await fs.promises.readFile(path.join(storagePath, 'app-data', config.id, 'data', filename), 'utf-8');
const exists = await pathExists(path.join(STORAGE_FOLDER, 'app-data', config.id, 'data', filename));
const data = await fs.promises.readFile(path.join(STORAGE_FOLDER, 'app-data', config.id, 'data', filename), 'utf-8');
expect(exists).toBe(true);
expect(data).toBe('test');
@ -84,16 +102,16 @@ describe('test: app executors', () => {
// arrange
const config = createAppConfig();
const filename = faker.system.fileName();
await fs.promises.writeFile(path.join(storagePath, 'app-data', config.id, 'data', filename), 'test');
await fs.promises.mkdir(path.join(rootFolderHost, 'repos', appsRepoId, 'apps', config.id, 'data'), { recursive: true });
await fs.promises.writeFile(path.join(rootFolderHost, 'repos', appsRepoId, 'apps', config.id, 'data', filename), 'yeah');
await fs.promises.writeFile(path.join(STORAGE_FOLDER, 'app-data', config.id, 'data', filename), 'test');
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'repos', appsRepoId, 'apps', config.id, 'data'), { recursive: true });
await fs.promises.writeFile(path.join(ROOT_FOLDER, 'repos', appsRepoId, 'apps', config.id, 'data', filename), 'yeah');
// act
await appExecutors.installApp(config.id, config);
// assert
const exists = await pathExists(path.join(storagePath, 'app-data', config.id, 'data', filename));
const data = await fs.promises.readFile(path.join(storagePath, 'app-data', config.id, 'data', filename), 'utf-8');
const exists = await pathExists(path.join(STORAGE_FOLDER, 'app-data', config.id, 'data', filename));
const data = await fs.promises.readFile(path.join(STORAGE_FOLDER, 'app-data', config.id, 'data', filename), 'utf-8');
expect(exists).toBe(true);
expect(data).toBe('test');

View file

@ -1,20 +1,18 @@
import fs from 'fs';
import { describe, it, expect } from 'vitest';
import { faker } from '@faker-js/faker';
import { pathExists } from '@runtipi/shared';
import { copyDataDir, generateEnvFile } from '../app.helpers';
import { createAppConfig } from '@/tests/apps.factory';
import { getAppEnvMap } from '../env.helpers';
import { getEnv } from '@/utils/environment/environment';
import { pathExists } from '@/utils/fs-helpers';
const { rootFolderHost, storagePath } = getEnv();
import { ROOT_FOLDER, STORAGE_FOLDER } from '@/config/constants';
describe('app helpers', () => {
describe('Test: generateEnvFile()', () => {
it('should throw an error if the app has an invalid config.json file', async () => {
// arrange
const appConfig = createAppConfig();
await fs.promises.writeFile(`${rootFolderHost}/apps/${appConfig.id}/config.json`, '{}');
await fs.promises.writeFile(`${ROOT_FOLDER}/apps/${appConfig.id}/config.json`, '{}');
// act & assert
expect(generateEnvFile(appConfig.id, {})).rejects.toThrowError(`App ${appConfig.id} has invalid config.json file`);
@ -50,8 +48,8 @@ describe('app helpers', () => {
// arrange
const appConfig = createAppConfig({ form_fields: [{ env_variable: 'RANDOM_FIELD', type: 'random', label: 'test', min: 32, max: 32, required: true }] });
const randomField = faker.string.alphanumeric(32);
await fs.promises.mkdir(`${rootFolderHost}/app-data/${appConfig.id}`, { recursive: true });
await fs.promises.writeFile(`${rootFolderHost}/app-data/${appConfig.id}/app.env`, `RANDOM_FIELD=${randomField}`);
await fs.promises.mkdir(`${STORAGE_FOLDER}/app-data/${appConfig.id}`, { recursive: true });
await fs.promises.writeFile(`${STORAGE_FOLDER}/app-data/${appConfig.id}/app.env`, `RANDOM_FIELD=${randomField}`);
// act
await generateEnvFile(appConfig.id, {});
@ -117,7 +115,7 @@ describe('app helpers', () => {
it('Should not re-create app-data folder if it already exists', async () => {
// arrange
const appConfig = createAppConfig({});
await fs.promises.mkdir(`${rootFolderHost}/app-data/${appConfig.id}`, { recursive: true });
await fs.promises.mkdir(`${ROOT_FOLDER}/app-data/${appConfig.id}`, { recursive: true });
// act
await generateEnvFile(appConfig.id, {});
@ -161,8 +159,8 @@ describe('app helpers', () => {
const vapidPublicKey = faker.string.alphanumeric(32);
// act
await fs.promises.mkdir(`${rootFolderHost}/app-data/${appConfig.id}`, { recursive: true });
await fs.promises.writeFile(`${rootFolderHost}/app-data/${appConfig.id}/app.env`, `VAPID_PRIVATE_KEY=${vapidPrivateKey}\nVAPID_PUBLIC_KEY=${vapidPublicKey}`);
await fs.promises.mkdir(`${STORAGE_FOLDER}/app-data/${appConfig.id}`, { recursive: true });
await fs.promises.writeFile(`${STORAGE_FOLDER}/app-data/${appConfig.id}/app.env`, `VAPID_PRIVATE_KEY=${vapidPrivateKey}\nVAPID_PUBLIC_KEY=${vapidPublicKey}`);
await generateEnvFile(appConfig.id, {});
const envmap = await getAppEnvMap(appConfig.id);
@ -181,13 +179,13 @@ describe('app helpers', () => {
await copyDataDir(appConfig.id);
// assert
expect(await pathExists(`${rootFolderHost}/apps/${appConfig.id}/data`)).toBe(false);
expect(await pathExists(`${ROOT_FOLDER}/apps/${appConfig.id}/data`)).toBe(false);
});
it('should copy data dir to app-data folder', async () => {
// arrange
const appConfig = createAppConfig({});
const dataDir = `${rootFolderHost}/apps/${appConfig.id}/data`;
const dataDir = `${ROOT_FOLDER}/apps/${appConfig.id}/data`;
await fs.promises.mkdir(dataDir, { recursive: true });
await fs.promises.writeFile(`${dataDir}/test.txt`, 'test');
@ -196,14 +194,14 @@ describe('app helpers', () => {
await copyDataDir(appConfig.id);
// assert
const appDataDir = `${storagePath}/app-data/${appConfig.id}`;
const appDataDir = `${STORAGE_FOLDER}/app-data/${appConfig.id}`;
expect(await fs.promises.readFile(`${appDataDir}/data/test.txt`, 'utf8')).toBe('test');
});
it('should copy folders recursively', async () => {
// arrange
const appConfig = createAppConfig({});
const dataDir = `${rootFolderHost}/apps/${appConfig.id}/data`;
const dataDir = `${ROOT_FOLDER}/apps/${appConfig.id}/data`;
await fs.promises.mkdir(dataDir, { recursive: true });
@ -217,7 +215,7 @@ describe('app helpers', () => {
await copyDataDir(appConfig.id);
// assert
const appDataDir = `${storagePath}/app-data/${appConfig.id}`;
const appDataDir = `${STORAGE_FOLDER}/app-data/${appConfig.id}`;
expect(await fs.promises.readFile(`${appDataDir}/data/subdir/subsubdir/test.txt`, 'utf8')).toBe('test');
expect(await fs.promises.readFile(`${appDataDir}/data/test.txt`, 'utf8')).toBe('test');
});
@ -225,8 +223,8 @@ describe('app helpers', () => {
it('should replace the content of .template files with the content of the app.env file', async () => {
// arrange
const appConfig = createAppConfig({});
const dataDir = `${rootFolderHost}/apps/${appConfig.id}/data`;
const appDataDir = `${storagePath}/app-data/${appConfig.id}`;
const dataDir = `${ROOT_FOLDER}/apps/${appConfig.id}/data`;
const appDataDir = `${STORAGE_FOLDER}/app-data/${appConfig.id}`;
await fs.promises.mkdir(dataDir, { recursive: true });
await fs.promises.mkdir(appDataDir, { recursive: true });

View file

@ -0,0 +1,297 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-restricted-syntax */
import fs from 'fs';
import path from 'path';
import pg from 'pg';
import { execAsync, pathExists } from '@runtipi/shared';
import { copyDataDir, generateEnvFile } from './app.helpers';
import { logger } from '@/lib/logger';
import { compose } from '@/lib/docker';
import { getEnv } from '@/lib/environment';
import { ROOT_FOLDER, STORAGE_FOLDER } from '@/config/constants';
const getDbClient = async () => {
const { postgresHost, postgresDatabase, postgresUsername, postgresPassword, postgresPort } = getEnv();
const client = new pg.Client({
host: postgresHost,
database: postgresDatabase,
user: postgresUsername,
password: postgresPassword,
port: Number(postgresPort),
});
await client.connect();
return client;
};
export class AppExecutors {
private readonly logger;
constructor() {
this.logger = logger;
}
private handleAppError = (err: unknown) => {
if (err instanceof Error) {
this.logger.error(`An error occurred: ${err.message}`);
return { success: false, message: err.message };
}
return { success: false, message: `An error occurred: ${err}` };
};
private getAppPaths = (appId: string) => {
const { appsRepoId } = getEnv();
const appDataDirPath = path.join(STORAGE_FOLDER, 'app-data', appId);
const appDirPath = path.join(ROOT_FOLDER, 'apps', appId);
const configJsonPath = path.join(appDirPath, 'config.json');
const repoPath = path.join(ROOT_FOLDER, 'repos', appsRepoId, 'apps', appId);
return { appDataDirPath, appDirPath, configJsonPath, repoPath };
};
/**
* Given an app id, ensures that the app folder exists in the apps folder
* If not, copies the app folder from the repo
* @param {string} appId - App id
*/
private ensureAppDir = async (appId: string) => {
const { appDirPath, repoPath } = this.getAppPaths(appId);
const dockerFilePath = path.join(ROOT_FOLDER, 'apps', appId, 'docker-compose.yml');
if (!(await pathExists(dockerFilePath))) {
// delete eventual app folder if exists
this.logger.info(`Deleting app ${appId} folder if exists`);
await fs.promises.rm(appDirPath, { recursive: true, force: true });
// Copy app folder from repo
this.logger.info(`Copying app ${appId} from repo ${getEnv().appsRepoId}`);
await fs.promises.cp(repoPath, appDirPath, { recursive: true });
}
};
/**
* Install an app from the repo
* @param {string} appId - The id of the app to install
* @param {Record<string, unknown>} config - The config of the app
*/
public installApp = async (appId: string, config: Record<string, unknown>) => {
try {
if (process.getuid && process.getgid) {
this.logger.info(`Installing app ${appId} as User ID: ${process.getuid()}, Group ID: ${process.getgid()}`);
} else {
this.logger.info(`Installing app ${appId}. No User ID or Group ID found.`);
}
const { appsRepoId } = getEnv();
const { appDirPath, repoPath, appDataDirPath } = this.getAppPaths(appId);
// Check if app exists in repo
const apps = await fs.promises.readdir(path.join(ROOT_FOLDER, 'repos', appsRepoId, 'apps'));
if (!apps.includes(appId)) {
this.logger.error(`App ${appId} not found in repo ${appsRepoId}`);
return { success: false, message: `App ${appId} not found in repo ${appsRepoId}` };
}
// Delete app folder if exists
this.logger.info(`Deleting folder ${appDirPath} if exists`);
await fs.promises.rm(appDirPath, { recursive: true, force: true });
// Create app folder
this.logger.info(`Creating folder ${appDirPath}`);
await fs.promises.mkdir(appDirPath, { recursive: true });
// Copy app folder from repo
this.logger.info(`Copying folder ${repoPath} to ${appDirPath}`);
await fs.promises.cp(repoPath, appDirPath, { recursive: true });
// Create folder app-data folder
this.logger.info(`Creating folder ${appDataDirPath}`);
await fs.promises.mkdir(appDataDirPath, { recursive: true });
// Create app.env file
this.logger.info(`Creating app.env file for app ${appId}`);
await generateEnvFile(appId, config);
// Copy data dir
this.logger.info(`Copying data dir for app ${appId}`);
if (!(await pathExists(`${appDataDirPath}/data`))) {
await copyDataDir(appId);
}
await execAsync(`chmod -R a+rwx ${path.join(appDataDirPath)}`).catch(() => {
this.logger.error(`Error setting permissions for app ${appId}`);
});
// run docker-compose up
this.logger.info(`Running docker-compose up for app ${appId}`);
await compose(appId, 'up -d');
this.logger.info(`Docker-compose up for app ${appId} finished`);
return { success: true, message: `App ${appId} installed successfully` };
} catch (err) {
return this.handleAppError(err);
}
};
/**
* Stops an app
* @param {string} appId - The id of the app to stop
* @param {Record<string, unknown>} config - The config of the app
*/
public stopApp = async (appId: string, config: Record<string, unknown>, skipEnvGeneration = false) => {
try {
this.logger.info(`Stopping app ${appId}`);
await this.ensureAppDir(appId);
if (!skipEnvGeneration) {
this.logger.info(`Regenerating app.env file for app ${appId}`);
await generateEnvFile(appId, config);
}
await compose(appId, 'rm --force --stop');
this.logger.info(`App ${appId} stopped`);
return { success: true, message: `App ${appId} stopped successfully` };
} catch (err) {
return this.handleAppError(err);
}
};
public startApp = async (appId: string, config: Record<string, unknown>, skipEnvGeneration = false) => {
try {
const { appDataDirPath } = this.getAppPaths(appId);
this.logger.info(`Starting app ${appId}`);
await this.ensureAppDir(appId);
if (!skipEnvGeneration) {
this.logger.info(`Regenerating app.env file for app ${appId}`);
await generateEnvFile(appId, config);
}
await compose(appId, 'up --detach --force-recreate --remove-orphans --pull always');
this.logger.info(`App ${appId} started`);
this.logger.info(`Setting permissions for app ${appId}`);
await execAsync(`chmod -R a+rwx ${path.join(appDataDirPath)}`).catch(() => {
this.logger.error(`Error setting permissions for app ${appId}`);
});
return { success: true, message: `App ${appId} started successfully` };
} catch (err) {
return this.handleAppError(err);
}
};
public uninstallApp = async (appId: string, config: Record<string, unknown>) => {
try {
const { appDirPath, appDataDirPath } = this.getAppPaths(appId);
this.logger.info(`Uninstalling app ${appId}`);
this.logger.info(`Regenerating app.env file for app ${appId}`);
await this.ensureAppDir(appId);
await generateEnvFile(appId, config);
try {
await compose(appId, 'down --remove-orphans --volumes --rmi all');
} catch (err) {
if (err instanceof Error && err.message.includes('conflict')) {
this.logger.warn(`Could not fully uninstall app ${appId}. Some images are in use by other apps. Consider cleaning unused images docker system prune -a`);
} else {
throw err;
}
}
this.logger.info(`Deleting folder ${appDirPath}`);
await fs.promises.rm(appDirPath, { recursive: true, force: true }).catch((err) => {
this.logger.error(`Error deleting folder ${appDirPath}: ${err.message}`);
});
this.logger.info(`Deleting folder ${appDataDirPath}`);
await fs.promises.rm(appDataDirPath, { recursive: true, force: true }).catch((err) => {
this.logger.error(`Error deleting folder ${appDataDirPath}: ${err.message}`);
});
this.logger.info(`App ${appId} uninstalled`);
return { success: true, message: `App ${appId} uninstalled successfully` };
} catch (err) {
return this.handleAppError(err);
}
};
public updateApp = async (appId: string, config: Record<string, unknown>) => {
try {
const { appDirPath, repoPath } = this.getAppPaths(appId);
this.logger.info(`Updating app ${appId}`);
await this.ensureAppDir(appId);
await generateEnvFile(appId, config);
await compose(appId, 'up --detach --force-recreate --remove-orphans');
await compose(appId, 'down --rmi all --remove-orphans');
this.logger.info(`Deleting folder ${appDirPath}`);
await fs.promises.rm(appDirPath, { recursive: true, force: true });
this.logger.info(`Copying folder ${repoPath} to ${appDirPath}`);
await fs.promises.cp(repoPath, appDirPath, { recursive: true });
await compose(appId, 'pull');
return { success: true, message: `App ${appId} updated successfully` };
} catch (err) {
return this.handleAppError(err);
}
};
public regenerateAppEnv = async (appId: string, config: Record<string, unknown>) => {
try {
this.logger.info(`Regenerating app.env file for app ${appId}`);
await this.ensureAppDir(appId);
await generateEnvFile(appId, config);
return { success: true, message: `App ${appId} env file regenerated successfully` };
} catch (err) {
return this.handleAppError(err);
}
};
/**
* Start all apps with status running
*/
public startAllApps = async () => {
const client = await getDbClient();
try {
// Get all apps with status running
const { rows } = await client.query(`SELECT * FROM app WHERE status = 'running'`);
// Update all apps with status different than running or stopped to stopped
await client.query(`UPDATE app SET status = 'stopped' WHERE status != 'stopped' AND status != 'running' AND status != 'missing'`);
// Start all apps
for (const row of rows) {
const { id, config } = row;
const { success } = await this.startApp(id, config);
if (!success) {
this.logger.error(`Error starting app ${id}`);
await client.query(`UPDATE app SET status = 'stopped' WHERE id = '${id}'`);
} else {
await client.query(`UPDATE app SET status = 'running' WHERE id = '${id}'`);
}
}
} catch (err) {
this.logger.error(`Error starting apps: ${err}`);
} finally {
await client.end();
}
};
}

View file

@ -1,11 +1,10 @@
import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
import { appInfoSchema, envMapToString, envStringToMap } from '@runtipi/shared';
import { getEnv } from '@/utils/environment/environment';
import { appInfoSchema, envMapToString, envStringToMap, execAsync, pathExists } from '@runtipi/shared';
import { generateVapidKeys, getAppEnvMap } from './env.helpers';
import { pathExists } from '@/utils/fs-helpers';
import { execAsync } from '@/utils/exec-async/execAsync';
import { getEnv } from '@/lib/environment';
import { ROOT_FOLDER, STORAGE_FOLDER } from '@/config/constants';
/**
* This function generates a random string of the provided length by using the SHA-256 hash algorithm.
@ -17,7 +16,7 @@ import { execAsync } from '@/utils/exec-async/execAsync';
*/
const getEntropy = async (name: string, length: number) => {
const hash = crypto.createHash('sha256');
const seed = await fs.promises.readFile(path.join(getEnv().rootFolderHost, 'state', 'seed'));
const seed = await fs.promises.readFile(path.join(ROOT_FOLDER, 'state', 'seed'));
hash.update(name + seed.toString());
return hash.digest('hex').substring(0, length);
@ -36,16 +35,16 @@ const getEntropy = async (name: string, length: number) => {
* @throws Will throw an error if the app has an invalid config.json file or if a required variable is missing.
*/
export const generateEnvFile = async (appId: string, config: Record<string, unknown>) => {
const { rootFolderHost, storagePath, internalIp } = getEnv();
const { internalIp, storagePath, rootFolderHost } = getEnv();
const configFile = await fs.promises.readFile(path.join(rootFolderHost, 'apps', appId, 'config.json'));
const configFile = await fs.promises.readFile(path.join(ROOT_FOLDER, 'apps', appId, 'config.json'));
const parsedConfig = appInfoSchema.safeParse(JSON.parse(configFile.toString()));
if (!parsedConfig.success) {
throw new Error(`App ${appId} has invalid config.json file`);
}
const baseEnvFile = await fs.promises.readFile(path.join(rootFolderHost, '.env'));
const baseEnvFile = await fs.promises.readFile(path.join(ROOT_FOLDER, '.env'));
const envMap = envStringToMap(baseEnvFile.toString());
// Default always present env variables
@ -101,12 +100,12 @@ export const generateEnvFile = async (appId: string, config: Record<string, unkn
}
// Create app-data folder if it doesn't exist
const appDataDirectoryExists = await fs.promises.stat(path.join(storagePath, 'app-data', appId)).catch(() => false);
const appDataDirectoryExists = await fs.promises.stat(path.join(STORAGE_FOLDER, 'app-data', appId)).catch(() => false);
if (!appDataDirectoryExists) {
await fs.promises.mkdir(path.join(storagePath, 'app-data', appId), { recursive: true });
await fs.promises.mkdir(path.join(STORAGE_FOLDER, 'app-data', appId), { recursive: true });
}
await fs.promises.writeFile(path.join(storagePath, 'app-data', appId, 'app.env'), envMapToString(envMap));
await fs.promises.writeFile(path.join(STORAGE_FOLDER, 'app-data', appId, 'app.env'), envMapToString(envMap));
};
/**
@ -133,40 +132,38 @@ const renderTemplate = (template: string, envMap: Map<string, string>) => {
* @param {string} id - The id of the app.
*/
export const copyDataDir = async (id: string) => {
const { rootFolderHost, storagePath } = getEnv();
const envMap = await getAppEnvMap(id);
// return if app does not have a data directory
if (!(await pathExists(`${rootFolderHost}/apps/${id}/data`))) {
if (!(await pathExists(`${ROOT_FOLDER}/apps/${id}/data`))) {
return;
}
// Create app-data folder if it doesn't exist
if (!(await pathExists(`${storagePath}/app-data/${id}/data`))) {
await fs.promises.mkdir(`${storagePath}/app-data/${id}/data`, { recursive: true });
if (!(await pathExists(`${STORAGE_FOLDER}/app-data/${id}/data`))) {
await fs.promises.mkdir(`${STORAGE_FOLDER}/app-data/${id}/data`, { recursive: true });
}
const dataDir = await fs.promises.readdir(`${rootFolderHost}/apps/${id}/data`);
const dataDir = await fs.promises.readdir(`${ROOT_FOLDER}/apps/${id}/data`);
const processFile = async (file: string) => {
if (file.endsWith('.template')) {
const template = await fs.promises.readFile(`${rootFolderHost}/apps/${id}/data/${file}`, 'utf-8');
const template = await fs.promises.readFile(`${ROOT_FOLDER}/apps/${id}/data/${file}`, 'utf-8');
const renderedTemplate = renderTemplate(template, envMap);
await fs.promises.writeFile(`${storagePath}/app-data/${id}/data/${file.replace('.template', '')}`, renderedTemplate);
await fs.promises.writeFile(`${STORAGE_FOLDER}/app-data/${id}/data/${file.replace('.template', '')}`, renderedTemplate);
} else {
await fs.promises.copyFile(`${rootFolderHost}/apps/${id}/data/${file}`, `${storagePath}/app-data/${id}/data/${file}`);
await fs.promises.copyFile(`${ROOT_FOLDER}/apps/${id}/data/${file}`, `${STORAGE_FOLDER}/app-data/${id}/data/${file}`);
}
};
const processDir = async (p: string) => {
await fs.promises.mkdir(`${storagePath}/app-data/${id}/data/${p}`, { recursive: true });
const files = await fs.promises.readdir(`${rootFolderHost}/apps/${id}/data/${p}`);
await fs.promises.mkdir(`${STORAGE_FOLDER}/app-data/${id}/data/${p}`, { recursive: true });
const files = await fs.promises.readdir(`${ROOT_FOLDER}/apps/${id}/data/${p}`);
await Promise.all(
files.map(async (file) => {
const fullPath = `${rootFolderHost}/apps/${id}/data/${p}/${file}`;
const fullPath = `${ROOT_FOLDER}/apps/${id}/data/${p}/${file}`;
if ((await fs.promises.lstat(fullPath)).isDirectory()) {
await processDir(`${p}/${file}`);
@ -179,7 +176,7 @@ export const copyDataDir = async (id: string) => {
await Promise.all(
dataDir.map(async (file) => {
const fullPath = `${rootFolderHost}/apps/${id}/data/${file}`;
const fullPath = `${ROOT_FOLDER}/apps/${id}/data/${file}`;
if ((await fs.promises.lstat(fullPath)).isDirectory()) {
await processDir(file);
@ -190,7 +187,7 @@ export const copyDataDir = async (id: string) => {
);
// Remove any .gitkeep files from the app-data folder at any level
if (await pathExists(`${storagePath}/app-data/${id}/data`)) {
await execAsync(`find ${storagePath}/app-data/${id}/data -name .gitkeep -delete`).catch(() => {});
if (await pathExists(`${STORAGE_FOLDER}/app-data/${id}/data`)) {
await execAsync(`find ${STORAGE_FOLDER}/app-data/${id}/data -name .gitkeep -delete`).catch(() => {});
}
};

View file

@ -1,7 +1,7 @@
import webpush from 'web-push';
import fs from 'fs';
import path from 'path';
import { getEnv } from '@/utils/environment/environment';
import { STORAGE_FOLDER } from '@/config/constants';
/**
* This function reads the env file for the app with the provided id and returns a Map containing the key-value pairs of the environment variables.
@ -11,7 +11,7 @@ import { getEnv } from '@/utils/environment/environment';
*/
export const getAppEnvMap = async (appId: string) => {
try {
const envFile = await fs.promises.readFile(path.join(getEnv().storagePath, 'app-data', appId, 'app.env'));
const envFile = await fs.promises.readFile(path.join(STORAGE_FOLDER, 'app-data', appId, 'app.env'));
const envVars = envFile.toString().split('\n');
const envVarsMap = new Map<string, string>();

View file

@ -0,0 +1,3 @@
export { AppExecutors } from './app/app.executors';
export { RepoExecutors } from './repo/repo.executors';
export { SystemExecutors } from './system/system.executors';

View file

@ -1,15 +1,13 @@
import { getEnv } from 'src/utils/environment/environment';
import path from 'path';
import { pathExists } from '@/utils/fs-helpers';
import { getRepoHash } from './repo.helpers';
import { fileLogger } from '@/utils/logger/file-logger';
import { execAsync } from '@/utils/exec-async/execAsync';
import { execAsync, pathExists } from '@runtipi/shared';
import { getRepoHash, getRepoBaseUrlAndBranch } from './repo.helpers';
import { logger } from '@/lib/logger';
export class RepoExecutors {
private readonly logger;
constructor() {
this.logger = fileLogger;
this.logger = logger;
}
/**
@ -28,23 +26,32 @@ export class RepoExecutors {
/**
* Given a repo url, clone it to the repos folder if it doesn't exist
*
* @param {string} repoUrl
* @param {string} url
*/
public cloneRepo = async (repoUrl: string) => {
public cloneRepo = async (url: string) => {
try {
const { rootFolderHost } = getEnv();
const repoHash = getRepoHash(repoUrl);
const repoPath = path.join(rootFolderHost, 'repos', repoHash);
// We may have a potential branch computed in the hash (see getRepoBaseUrlAndBranch)
// so we do it here before splitting the url into repoUrl and branch
const repoHash = getRepoHash(url);
const repoPath = path.join('/app', 'repos', repoHash);
if (await pathExists(repoPath)) {
this.logger.info(`Repo ${repoUrl} already exists`);
this.logger.info(`Repo ${url} already exists`);
return { success: true, message: '' };
}
this.logger.info(`Cloning repo ${repoUrl} to ${repoPath}`);
const [repoUrl, branch] = getRepoBaseUrlAndBranch(url);
await execAsync(`git clone ${repoUrl} ${repoPath}`);
let cloneCommand;
if (branch) {
this.logger.info(`Cloning repo ${repoUrl} on branch ${branch} to ${repoPath}`);
cloneCommand = `git clone -b ${branch} ${repoUrl} ${repoPath}`;
} else {
this.logger.info(`Cloning repo ${repoUrl} to ${repoPath}`);
cloneCommand = `git clone ${repoUrl} ${repoPath}`;
}
await execAsync(cloneCommand);
this.logger.info(`Cloned repo ${repoUrl} to ${repoPath}`);
return { success: true, message: '' };
@ -60,10 +67,8 @@ export class RepoExecutors {
*/
public pullRepo = async (repoUrl: string) => {
try {
const { rootFolderHost } = getEnv();
const repoHash = getRepoHash(repoUrl);
const repoPath = path.join(rootFolderHost, 'repos', repoHash);
const repoPath = path.join('/app', 'repos', repoHash);
if (!(await pathExists(repoPath))) {
this.logger.info(`Repo ${repoUrl} does not exist`);
@ -93,11 +98,7 @@ export class RepoExecutors {
});
this.logger.info(`Executing: git -C ${repoPath} fetch origin && git -C ${repoPath} reset --hard origin/${currentBranch}`);
await execAsync(`git -C ${repoPath} fetch origin && git -C ${repoPath} reset --hard origin/${currentBranch}`).then(({ stderr }) => {
if (stderr) {
this.logger.error(`stderr: ${stderr}`);
}
});
await execAsync(`git -C ${repoPath} fetch origin && git -C ${repoPath} reset --hard origin/${currentBranch}`);
this.logger.info(`Pulled repo ${repoUrl} to ${repoPath}`);
return { success: true, message: '' };

View file

@ -0,0 +1,27 @@
import crypto from 'crypto';
/**
* Given a repo url, return a hash of it to be used as a folder name
*
* @param {string} repoUrl
*/
export const getRepoHash = (repoUrl: string) => {
const hash = crypto.createHash('sha256');
hash.update(repoUrl);
return hash.digest('hex');
};
/**
* Extracts the base URL and branch from a repository URL.
* @param repoUrl The repository URL.
* @returns An array containing the base URL and branch, or just the base URL if no branch is found.
*/
export const getRepoBaseUrlAndBranch = (repoUrl: string) => {
const branchMatch = repoUrl.match(/^(.*)\/tree\/(.*)$/);
if (branchMatch) {
return [branchMatch[1], branchMatch[2]] ;
}
return [repoUrl, undefined] ;
};

View file

@ -0,0 +1,60 @@
import fs from 'fs';
import path from 'path';
import si from 'systeminformation';
import { logger } from '@/lib/logger';
import { ROOT_FOLDER } from '@/config/constants';
export class SystemExecutors {
private readonly logger;
constructor() {
this.logger = logger;
}
private handleSystemError = (err: unknown) => {
if (err instanceof Error) {
this.logger.error(`An error occurred: ${err.message}`);
return { success: false, message: err.message };
}
this.logger.error(`An error occurred: ${err}`);
return { success: false, message: `An error occurred: ${err}` };
};
private getSystemLoad = async () => {
const { currentLoad } = await si.currentLoad();
const memResult = { total: 0, used: 0, available: 0 };
try {
const memInfo = await fs.promises.readFile('/host/proc/meminfo');
memResult.total = Number(memInfo.toString().match(/MemTotal:\s+(\d+)/)?.[1] ?? 0) * 1024;
memResult.available = Number(memInfo.toString().match(/MemAvailable:\s+(\d+)/)?.[1] ?? 0) * 1024;
memResult.used = memResult.total - memResult.available;
} catch (e) {
this.logger.error(`Unable to read /host/proc/meminfo: ${e}`);
}
const [disk0] = await si.fsSize();
return {
cpu: { load: currentLoad },
memory: memResult,
disk: { total: disk0?.size, used: disk0?.used, available: disk0?.available },
};
};
public systemInfo = async () => {
try {
const systemLoad = await this.getSystemLoad();
await fs.promises.writeFile(path.join(ROOT_FOLDER, 'state', 'system-info.json'), JSON.stringify(systemLoad, null, 2));
await fs.promises.chmod(path.join(ROOT_FOLDER, 'state', 'system-info.json'), 0o777);
return { success: true, message: '' };
} catch (e) {
return this.handleSystemError(e);
}
};
}

View file

@ -1,18 +1,13 @@
import { eventSchema } from '@runtipi/shared';
import { Worker } from 'bullmq';
import { AppExecutors, RepoExecutors, SystemExecutors } from '@/executors';
import { getEnv } from '@/utils/environment/environment';
import { getUserIds } from '@/utils/environment/user';
import { fileLogger } from '@/utils/logger/file-logger';
import { execAsync } from '@/utils/exec-async/execAsync';
import { AppExecutors, RepoExecutors, SystemExecutors } from '@/services';
import { logger } from '@/lib/logger';
import { getEnv } from '@/lib/environment';
const runCommand = async (jobData: unknown) => {
const { gid, uid } = getUserIds();
fileLogger.info(`Running command with uid ${uid} and gid ${gid}`);
const { installApp, startApp, stopApp, uninstallApp, updateApp, regenerateAppEnv } = new AppExecutors();
const { cloneRepo, pullRepo } = new RepoExecutors();
const { systemInfo, restart, update } = new SystemExecutors();
const { systemInfo } = new SystemExecutors();
const event = eventSchema.safeParse(jobData);
@ -31,11 +26,11 @@ const runCommand = async (jobData: unknown) => {
}
if (data.command === 'stop') {
({ success, message } = await stopApp(data.appid, data.form));
({ success, message } = await stopApp(data.appid, data.form, data.skipEnv));
}
if (data.command === 'start') {
({ success, message } = await startApp(data.appid, data.form));
({ success, message } = await startApp(data.appid, data.form, data.skipEnv));
}
if (data.command === 'uninstall') {
@ -61,38 +56,11 @@ const runCommand = async (jobData: unknown) => {
if (data.command === 'system_info') {
({ success, message } = await systemInfo());
}
if (data.command === 'restart') {
({ success, message } = await restart());
}
if (data.command === 'update') {
({ success, message } = await update(data.version));
}
}
return { success, message };
};
export const killOtherWorkers = async () => {
const { stdout } = await execAsync('ps aux | grep "index.js watch" | grep -v grep | awk \'{print $2}\'');
const { stdout: stdoutInherit } = await execAsync('ps aux | grep "runtipi-cli watch" | grep -v grep | awk \'{print $2}\'');
fileLogger.info(`Killing other workers with pids ${stdout} and ${stdoutInherit}`);
const pids = stdout.split('\n').filter((pid: string) => pid !== '');
const pidsInherit = stdoutInherit.split('\n').filter((pid: string) => pid !== '');
pids.concat(pidsInherit).forEach((pid) => {
fileLogger.info(`Killing worker with pid ${pid}`);
try {
process.kill(Number(pid));
} catch (e) {
fileLogger.error(`Error killing worker with pid ${pid}: ${e}`);
}
});
};
/**
* Start the worker for the events queue
*/
@ -100,27 +68,27 @@ export const startWorker = async () => {
const worker = new Worker(
'events',
async (job) => {
fileLogger.info(`Processing job ${job.id} with data ${JSON.stringify(job.data)}`);
logger.info(`Processing job ${job.id} with data ${JSON.stringify(job.data)}`);
const { message, success } = await runCommand(job.data);
return { success, stdout: message };
},
{ connection: { host: '127.0.0.1', port: 6379, password: getEnv().redisPassword, connectTimeout: 60000 }, removeOnComplete: { count: 200 }, removeOnFail: { count: 500 } },
{ connection: { host: getEnv().redisHost, port: 6379, password: getEnv().redisPassword, connectTimeout: 60000 }, removeOnComplete: { count: 200 }, removeOnFail: { count: 500 } },
);
worker.on('ready', () => {
fileLogger.info('Worker is ready');
logger.info('Worker is ready');
});
worker.on('completed', (job) => {
fileLogger.info(`Job ${job.id} completed with result:`, JSON.stringify(job.returnvalue));
logger.info(`Job ${job.id} completed with result:`, JSON.stringify(job.returnvalue));
});
worker.on('failed', (job) => {
fileLogger.error(`Job ${job?.id} failed with reason ${job?.failedReason}`);
logger.error(`Job ${job?.id} failed with reason ${job?.failedReason}`);
});
worker.on('error', async (e) => {
fileLogger.debug(`Worker error: ${e}`);
logger.debug(`Worker error: ${e}`);
});
};

View file

@ -0,0 +1,38 @@
import { faker } from '@faker-js/faker';
import fs from 'fs';
import { APP_CATEGORIES, AppInfo, appInfoSchema } from '@runtipi/shared';
import { ROOT_FOLDER, STORAGE_FOLDER } from '@/config/constants';
export const createAppConfig = (props?: Partial<AppInfo>, isInstalled = true) => {
const appInfo = appInfoSchema.parse({
id: faker.string.alphanumeric(32),
available: true,
port: faker.number.int({ min: 30, max: 65535 }),
name: faker.string.alphanumeric(32),
description: faker.string.alphanumeric(32),
tipi_version: 1,
short_desc: faker.string.alphanumeric(32),
author: faker.string.alphanumeric(32),
source: faker.internet.url(),
categories: [APP_CATEGORIES.AUTOMATION],
...props,
});
const mockFiles: Record<string, string | string[]> = {};
mockFiles[`${ROOT_FOLDER}/.env`] = 'TEST=test';
mockFiles[`${ROOT_FOLDER}/repos/repo-id/apps/${appInfo.id}/config.json`] = JSON.stringify(appInfoSchema.parse(appInfo));
mockFiles[`${ROOT_FOLDER}/repos/repo-id/apps/${appInfo.id}/docker-compose.yml`] = 'compose';
mockFiles[`${ROOT_FOLDER}/repos/repo-id/apps/${appInfo.id}/metadata/description.md`] = 'md desc';
if (isInstalled) {
mockFiles[`${ROOT_FOLDER}/apps/${appInfo.id}/config.json`] = JSON.stringify(appInfoSchema.parse(appInfo));
mockFiles[`${ROOT_FOLDER}/apps/${appInfo.id}/docker-compose.yml`] = 'compose';
mockFiles[`${ROOT_FOLDER}/apps/${appInfo.id}/metadata/description.md`] = 'md desc';
mockFiles[`${STORAGE_FOLDER}/app-data/${appInfo.id}/data/test.txt`] = 'data';
}
// @ts-expect-error - custom mock method
fs.__applyMockFiles(mockFiles);
return appInfo;
};

View file

@ -0,0 +1,41 @@
import { fs, vol } from 'memfs';
const copyFolderRecursiveSync = (src: string, dest: string) => {
const exists = vol.existsSync(src);
const stats = vol.statSync(src);
const isDirectory = exists && stats.isDirectory();
if (isDirectory) {
vol.mkdirSync(dest, { recursive: true });
vol.readdirSync(src).forEach((childItemName) => {
copyFolderRecursiveSync(`${src}/${childItemName}`, `${dest}/${childItemName}`);
});
} else {
vol.copyFileSync(src, dest);
}
};
export const fsMock = {
default: {
...fs,
promises: {
...fs.promises,
cp: copyFolderRecursiveSync,
},
copySync: (src: string, dest: string) => {
copyFolderRecursiveSync(src, dest);
},
__resetAllMocks: () => {
vol.reset();
},
__applyMockFiles: (newMockFiles: Record<string, string>) => {
// Create folder tree
vol.fromJSON(newMockFiles, 'utf8');
},
__createMockFiles: (newMockFiles: Record<string, string>) => {
vol.reset();
// Create folder tree
vol.fromJSON(newMockFiles, 'utf8');
},
__printVol: () => console.log(vol.toTree()),
},
};

View file

@ -0,0 +1,42 @@
import fs from 'fs';
import path from 'path';
import { vi, beforeEach } from 'vitest';
import { getEnv } from '@/lib/environment';
import { ROOT_FOLDER } from '@/config/constants';
vi.mock('@runtipi/shared', async (importOriginal) => {
const mod = (await importOriginal()) as object;
return {
...mod,
createLogger: vi.fn().mockReturnValue({
info: vi.fn(),
error: vi.fn(),
}),
FileLogger: vi.fn().mockImplementation(() => ({
flush: vi.fn(),
error: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
debug: vi.fn(),
})),
};
});
vi.mock('fs', async () => {
const { fsMock } = await import('@/tests/mocks/fs');
return {
...fsMock,
};
});
beforeEach(async () => {
// @ts-expect-error - custom mock method
fs.__resetAllMocks();
const { appsRepoId } = getEnv();
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'state'), { recursive: true });
await fs.promises.writeFile(path.join(ROOT_FOLDER, 'state', 'seed'), 'seed');
await fs.promises.mkdir(path.join(ROOT_FOLDER, 'repos', appsRepoId, 'apps'), { recursive: true });
});

View file

@ -0,0 +1,55 @@
{
"compilerOptions": {
"target": "es2017",
"baseUrl": ".",
"outDir": "./dist",
"paths": {
"@/lib/*": [
"./src/lib/*"
],
"@/services": [
"./src/services"
],
"@/config/*": [
"./src/config/*"
],
"@/tests/*": [
"./tests/*"
],
},
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "CommonJS",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"strictNullChecks": true,
"allowSyntheticDefaultImports": true,
"noUncheckedIndexedAccess": true,
"types": [
"node"
],
"experimentalDecorators": true
},
"include": [
"**/*.ts",
"**/*.tsx",
"**/*.mjs",
"**/*.js",
"**/*.jsx"
],
"exclude": [
"node_modules"
]
}

View file

@ -0,0 +1,10 @@
import { defineConfig } from 'vitest/config';
import tsconfigPaths from 'vite-tsconfig-paths';
export default defineConfig({
plugins: [tsconfigPaths()],
test: {
setupFiles: ['./tests/vite.setup.ts'],
coverage: { all: true, reporter: ['lcov', 'text-summary'] },
},
});

File diff suppressed because it is too large Load diff

BIN
public/tipi-christmas.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View file

@ -74,6 +74,7 @@ function install_generic() {
function install_docker() {
local os="${1}"
echo "Installing docker for os ${os}"
echo "Your sudo password might be asked to install docker"
if [[ "${os}" == "debian" ]]; then
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates curl gnupg lsb-release
@ -134,6 +135,14 @@ if ! command -v docker >/dev/null; then
exit 1
fi
fi
# Make sure user is in docker group
if ! groups | grep -q '\bdocker\b'; then
sudo usermod -aG docker "$USER"
fi
# Reload user groups
newgrp docker
fi
function check_dependency_and_install() {
@ -185,10 +194,4 @@ fi
curl --location "$URL" -o ./runtipi-cli
chmod +x ./runtipi-cli
# Check if git is installed
if ! command -v git >/dev/null; then
echo "Git is not installed. Please install git and restart the script."
exit 1
fi
sudo ./runtipi-cli start
./runtipi-cli start

View file

@ -1,10 +1,13 @@
import React from 'react';
import Image from 'next/image';
import { getCurrentLocale } from 'src/utils/getCurrentLocale';
import { getLogo } from '@/lib/themes';
import { getConfig } from '@/server/core/TipiConfig';
import { LanguageSelector } from '../components/LanguageSelector';
export default async function AuthLayout({ children }: { children: React.ReactNode }) {
const locale = getCurrentLocale();
const { allowAutoThemes } = getConfig();
return (
<div className="page page-center">
@ -15,7 +18,7 @@ export default async function AuthLayout({ children }: { children: React.ReactNo
<div className="text-center mb-4">
<Image
alt="Tipi logo"
src="/tipi.png"
src={getLogo(allowAutoThemes)}
height={50}
width={50}
style={{

View file

@ -16,6 +16,7 @@ import { AppStatus } from '@/components/AppStatus';
import { AppStatus as AppStatusEnum } from '@/server/db/schema';
import { castAppConfig } from '@/lib/helpers/castAppConfig';
import { AppService } from '@/server/services/apps/apps.service';
import { resetAppAction } from '@/actions/app-actions/reset-app-action';
import { InstallModal } from '../InstallModal';
import { StopModal } from '../StopModal';
import { UninstallModal } from '../UninstallModal';
@ -24,6 +25,7 @@ import { UpdateSettingsModal } from '../UpdateSettingsModal/UpdateSettingsModal'
import { AppActions } from '../AppActions';
import { AppDetailsTabs } from '../AppDetailsTabs';
import { FormValues } from '../InstallForm';
import { ResetAppModal } from '../ResetAppModal';
interface IProps {
app: Awaited<ReturnType<AppService['getApp']>>;
@ -40,6 +42,7 @@ export const AppDetailsContainer: React.FC<IProps> = ({ app, localDomain }) => {
const stopDisclosure = useDisclosure();
const updateDisclosure = useDisclosure();
const updateSettingsDisclosure = useDisclosure();
const resetAppDisclosure = useDisclosure();
const installMutation = useAction(installAppAction, {
onSuccess: (data) => {
@ -91,11 +94,11 @@ export const AppDetailsContainer: React.FC<IProps> = ({ app, localDomain }) => {
const updateMutation = useAction(updateAppAction, {
onSuccess: (data) => {
setCustomStatus(app.status);
if (!data.success) {
setCustomStatus(app.status);
toast.error(data.failure.reason);
} else {
setCustomStatus('stopped');
toast.success(t('apps.app-details.update-success'));
}
},
@ -111,6 +114,19 @@ export const AppDetailsContainer: React.FC<IProps> = ({ app, localDomain }) => {
},
});
const resetMutation = useAction(resetAppAction, {
onSuccess: (data) => {
if (!data.success) {
toast.error(data.failure.reason);
resetAppDisclosure.close();
} else {
resetAppDisclosure.close();
toast.success(t('apps.app-details.app-reset-success'));
setCustomStatus('running');
}
},
});
const updateAvailable = Number(app.version || 0) < Number(app?.latestVersion || 0);
const handleInstallSubmit = async (values: FormValues) => {
@ -147,6 +163,17 @@ export const AppDetailsContainer: React.FC<IProps> = ({ app, localDomain }) => {
updateMutation.execute({ id: app.id });
};
const handleResetSubmit = () => {
setCustomStatus('stopping');
resetMutation.execute({ id: app.id });
resetAppDisclosure.open();
};
const openResetAppModal = () => {
updateSettingsDisclosure.close();
resetAppDisclosure.open();
};
const handleOpen = (type: OpenType) => {
let url = '';
const { https } = app.info;
@ -177,12 +204,15 @@ export const AppDetailsContainer: React.FC<IProps> = ({ app, localDomain }) => {
<StopModal onConfirm={handleStopSubmit} isOpen={stopDisclosure.isOpen} onClose={stopDisclosure.close} info={app.info} />
<UninstallModal onConfirm={handleUnistallSubmit} isOpen={uninstallDisclosure.isOpen} onClose={uninstallDisclosure.close} info={app.info} />
<UpdateModal onConfirm={handleUpdateSubmit} isOpen={updateDisclosure.isOpen} onClose={updateDisclosure.close} info={app.info} newVersion={newVersion} />
<ResetAppModal onConfirm={handleResetSubmit} isOpen={resetAppDisclosure.isOpen} onClose={resetAppDisclosure.close} info={app.info} isLoading={resetMutation.status === 'executing'} />
<UpdateSettingsModal
onSubmit={handleUpdateSettingsSubmit}
isOpen={updateSettingsDisclosure.isOpen}
onClose={updateSettingsDisclosure.close}
info={app.info}
config={castAppConfig(app?.config)}
onReset={openResetAppModal}
status={customStatus}
/>
<div className="card-header d-flex flex-column flex-md-row">
<AppLogo id={app.id} size={130} alt={app.info.name} />

View file

@ -9,6 +9,7 @@ import { type FormField, type AppInfo } from '@runtipi/shared';
import { Switch } from '@/components/ui/Switch';
import { Input } from '@/components/ui/Input';
import { Button } from '@/components/ui/Button';
import { AppStatus } from '@/server/db/schema';
import { validateAppConfig } from '../../utils/validators';
interface IProps {
@ -17,6 +18,8 @@ interface IProps {
initalValues?: { [key: string]: unknown };
info: AppInfo;
loading?: boolean;
onReset?: () => void;
status?: AppStatus;
}
export type FormValues = {
@ -29,7 +32,7 @@ export type FormValues = {
const hiddenTypes = ['random'];
const typeFilter = (field: FormField) => !hiddenTypes.includes(field.type);
export const InstallForm: React.FC<IProps> = ({ formFields, info, onSubmit, initalValues, loading }) => {
export const InstallForm: React.FC<IProps> = ({ formFields, info, onSubmit, initalValues, loading, onReset, status }) => {
const t = useTranslations('apps.app-details.install-form');
const {
register,
@ -56,6 +59,11 @@ export const InstallForm: React.FC<IProps> = ({ formFields, info, onSubmit, init
}
}, [initalValues, isDirty, setValue]);
const onClickReset = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.preventDefault();
if (onReset) onReset();
};
const renderField = (field: FormField) => {
const label = (
<>
@ -166,6 +174,11 @@ export const InstallForm: React.FC<IProps> = ({ formFields, info, onSubmit, init
<Button loading={loading} type="submit" className="btn-success">
{initalValues ? t('submit-update') : t('sumbit-install')}
</Button>
{initalValues && onReset && (
<Button loading={status === 'stopping'} onClick={onClickReset} className="btn-danger ms-2">
{t('reset')}
</Button>
)}
</form>
);
};

View file

@ -0,0 +1,38 @@
import { IconAlertTriangle } from '@tabler/icons-react';
import React from 'react';
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader } from '@/components/ui/Dialog';
import { useTranslations } from 'next-intl';
import { AppInfo } from '@runtipi/shared';
import { Button } from '@/components/ui/Button';
interface IProps {
info: AppInfo;
isOpen: boolean;
onClose: () => void;
onConfirm: () => void;
isLoading?: boolean;
}
export const ResetAppModal: React.FC<IProps> = ({ info, isOpen, onClose, onConfirm, isLoading }) => {
const t = useTranslations('apps.app-details.reset-app-form');
return (
<Dialog open={isOpen} onOpenChange={onClose}>
<DialogContent type="danger" size="sm">
<DialogHeader>
<h5 className="modal-title">{t('title', { name: info.name })}</h5>
</DialogHeader>
<DialogDescription className="text-center py-4">
<IconAlertTriangle className="icon mb-2 text-danger icon-lg" />
<h3>{t('warning')}</h3>
<div className="text-muted">{t('subtitle')}</div>
</DialogDescription>
<DialogFooter>
<Button loading={isLoading} onClick={onConfirm} className="btn-danger">
{t('submit')}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
};

View file

@ -0,0 +1 @@
export { ResetAppModal } from './ResetAppModal';

View file

@ -3,6 +3,7 @@ import { Dialog, DialogContent, DialogDescription, DialogHeader } from '@/compon
import { useTranslations } from 'next-intl';
import { AppInfo } from '@runtipi/shared';
import { ScrollArea } from '@/components/ui/ScrollArea';
import { AppStatus } from '@/server/db/schema';
import { InstallForm, type FormValues } from '../InstallForm';
interface IProps {
@ -11,9 +12,11 @@ interface IProps {
isOpen: boolean;
onClose: () => void;
onSubmit: (values: FormValues) => void;
onReset: () => void;
status?: AppStatus;
}
export const UpdateSettingsModal: React.FC<IProps> = ({ info, config, isOpen, onClose, onSubmit }) => {
export const UpdateSettingsModal: React.FC<IProps> = ({ info, config, isOpen, onClose, onSubmit, onReset, status }) => {
const t = useTranslations('apps.app-details.update-settings-form');
return (
@ -24,7 +27,7 @@ export const UpdateSettingsModal: React.FC<IProps> = ({ info, config, isOpen, on
</DialogHeader>
<ScrollArea maxHeight={500}>
<DialogDescription>
<InstallForm onSubmit={onSubmit} formFields={info.form_fields} info={info} initalValues={{ ...config }} />
<InstallForm onSubmit={onSubmit} formFields={info.form_fields} info={info} initalValues={{ ...config }} onReset={onReset} status={status} />
</DialogDescription>
</ScrollArea>
</DialogContent>

View file

@ -26,7 +26,7 @@ export default async function Page() {
if (app.info?.available)
return (
<Link href={`/apps/${app.id}`} className={clsx('col-sm-6 col-lg-4', styles.link)} passHref>
<Link key={app.id} href={`/apps/${app.id}`} className={clsx('col-sm-6 col-lg-4', styles.link)} passHref>
<AppTile key={app.id} app={app.info} status={app.status} updateAvailable={updateAvailable} />
</Link>
);

View file

@ -13,14 +13,16 @@ import { useAction } from 'next-safe-action/hook';
import { logoutAction } from '@/actions/logout/logout-action';
import Script from 'next/script';
import { useRouter } from 'next/navigation';
import { getLogo } from '@/lib/themes';
import { NavBar } from '../NavBar';
interface IProps {
isUpdateAvailable?: boolean;
authenticated?: boolean;
autoTheme: boolean;
}
export const Header: React.FC<IProps> = ({ isUpdateAvailable, authenticated = true }) => {
export const Header: React.FC<IProps> = ({ isUpdateAvailable, authenticated = true, autoTheme }) => {
const { setDarkMode } = useUIStore();
const t = useTranslations('header');
@ -55,7 +57,7 @@ export const Header: React.FC<IProps> = ({ isUpdateAvailable, authenticated = tr
className={clsx('navbar-brand-image me-3')}
width={100}
height={100}
src="/tipi.png"
src={getLogo(autoTheme)}
style={{
width: '30px',
maxWidth: '30px',

View file

@ -5,6 +5,7 @@ import { SystemServiceClass } from '@/server/services/system';
import semver from 'semver';
import clsx from 'clsx';
import { AppServiceClass } from '@/server/services/apps/apps.service';
import { getConfig } from '@/server/core/TipiConfig';
import { Header } from './components/Header';
import { PageTitle } from './components/PageTitle';
import styles from './layout.module.scss';
@ -12,6 +13,7 @@ import { LayoutActions } from './components/LayoutActions/LayoutActions';
export default async function DashboardLayout({ children }: { children: React.ReactNode }) {
const user = await getUserFromCookie();
const { allowAutoThemes } = getConfig();
const { apps } = await AppServiceClass.listApps();
@ -25,7 +27,7 @@ export default async function DashboardLayout({ children }: { children: React.Re
return (
<div className="page">
<Header isUpdateAvailable={!isLatest} />
<Header isUpdateAvailable={!isLatest} autoTheme={allowAutoThemes} />
<div className="page-wrapper">
<div className="page-header d-print-none">
<div className="container-xl">

View file

@ -2,16 +2,10 @@
import React from 'react';
import semver from 'semver';
import { toast } from 'react-hot-toast';
import { Markdown } from '@/components/Markdown';
import { IconStar } from '@tabler/icons-react';
import { useTranslations } from 'next-intl';
import { useDisclosure } from '@/client/hooks/useDisclosure';
import { Button } from '@/components/ui/Button';
import { useSystemStore } from '@/client/state/systemStore';
import { useAction } from 'next-safe-action/hook';
import { restartAction } from '@/actions/settings/restart';
import { RestartModal } from '../RestartModal';
type Props = { version: { current: string; latest: string; body?: string | null } };
@ -19,29 +13,9 @@ export const GeneralActions = (props: Props) => {
const t = useTranslations();
const { version } = props;
const [loading, setLoading] = React.useState(false);
const { setPollStatus, setStatus } = useSystemStore();
const restartDisclosure = useDisclosure();
const defaultVersion = '0.0.0';
const isLatest = semver.gte(version.current || defaultVersion, version.latest || defaultVersion);
const restartMutation = useAction(restartAction, {
onSuccess: (data) => {
if (data.success) {
setPollStatus(true);
setStatus('RESTARTING');
} else {
restartDisclosure.close();
setLoading(false);
toast.error(data.failure.reason);
}
},
onExecute: () => {
setLoading(true);
},
});
const renderUpdate = () => {
if (isLatest) {
return <Button disabled>{t('settings.actions.already-latest')}</Button>;
@ -66,19 +40,11 @@ export const GeneralActions = (props: Props) => {
};
return (
<>
<div className="card-body">
<h2 className="mb-4">{t('settings.actions.title')}</h2>
<h3 className="card-title mt-4">{t('settings.actions.current-version', { version: version.current })}</h3>
<p className="card-subtitle">{isLatest ? t('settings.actions.stay-up-to-date') : t('settings.actions.new-version', { version: version.latest })}</p>
{renderUpdate()}
<h3 className="card-title mt-4">{t('settings.actions.maintenance-title')}</h3>
<p className="card-subtitle">{t('settings.actions.maintenance-subtitle')}</p>
<div>
<Button onClick={restartDisclosure.open}>{t('settings.actions.restart')}</Button>
</div>
</div>
<RestartModal isOpen={restartDisclosure.isOpen} onClose={restartDisclosure.close} onConfirm={() => restartMutation.execute()} loading={loading} />
</>
<div className="card-body">
<h2 className="mb-4">{t('settings.actions.title')}</h2>
<h3 className="card-title mt-4">{t('settings.actions.current-version', { version: version.current })}</h3>
<p className="card-subtitle">{isLatest ? t('settings.actions.stay-up-to-date') : t('settings.actions.new-version', { version: version.latest })}</p>
{renderUpdate()}
</div>
);
};

View file

@ -1,28 +0,0 @@
import React from 'react';
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader } from '@/components/ui/Dialog';
import { Button } from '@/components/ui/Button';
interface IProps {
isOpen: boolean;
onClose: () => void;
onConfirm: () => void;
loading: boolean;
}
export const RestartModal: React.FC<IProps> = ({ isOpen, onClose, onConfirm, loading }) => (
<Dialog open={isOpen} onOpenChange={onClose}>
<DialogContent type="danger" size="sm">
<DialogHeader>
<h5 className="modal-title">Restart Tipi</h5>
</DialogHeader>
<DialogDescription>
<div className="text-muted">Would you like to restart your Tipi server?</div>
</DialogDescription>
<DialogFooter>
<Button onClick={onConfirm} className="btn-danger" loading={loading}>
Restart
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);

View file

@ -1 +0,0 @@
export { RestartModal } from './RestartModal';

View file

@ -6,6 +6,7 @@ import { useTranslations } from 'next-intl';
import { useAction } from 'next-safe-action/hook';
import { updateSettingsAction } from '@/actions/settings/update-settings';
import { Locale } from '@/shared/internationalization/locales';
import { useRouter } from 'next/navigation';
import { SettingsForm, SettingsFormValues } from '../SettingsForm';
type Props = {
@ -16,12 +17,15 @@ type Props = {
export const SettingsContainer = ({ initialValues, currentLocale }: Props) => {
const t = useTranslations();
const router = useRouter();
const updateSettingsMutation = useAction(updateSettingsAction, {
onSuccess: (data) => {
if (!data.success) {
toast.error(data.failure.reason);
} else {
toast.success(t('settings.settings.settings-updated'));
router.refresh();
}
},
});

View file

@ -19,6 +19,7 @@ export type SettingsFormValues = {
storagePath?: string;
localDomain?: string;
guestDashboard?: boolean;
allowAutoThemes?: boolean;
};
interface IProps {
@ -139,6 +140,29 @@ export const SettingsForm = (props: IProps) => {
)}
/>
</div>
<div className="mb-3">
<Controller
control={control}
name="allowAutoThemes"
defaultValue={false}
render={({ field: { onChange, value, ref, ...rest } }) => (
<Switch
className="mb-3"
ref={ref}
checked={value}
onCheckedChange={onChange}
{...rest}
label={
<>
{t('allow-auto-themes')}
<Tooltip anchorSelect=".allow-auto-themes-hint">{t('allow-auto-themes-hint')}</Tooltip>
<span className={clsx('ms-1 form-help allow-auto-themes-hint')}>?</span>
</>
}
/>
)}
/>
</div>
<div className="mb-3">
<Input
{...register('domain')}

Some files were not shown because too many files have changed in this diff Show more