Compare commits
339 commits
release/2.
...
develop
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c962f030e3 | ||
![]() |
1f5701120f | ||
![]() |
249103f0a6 | ||
![]() |
bb1f343ac9 | ||
![]() |
6b371de137 | ||
![]() |
7133a2a2dc | ||
![]() |
44d40b4a34 | ||
![]() |
03e2604ca0 | ||
![]() |
ba3d860176 | ||
![]() |
250e78450f | ||
![]() |
d11299eeb8 | ||
![]() |
6cd7ca1a4e | ||
![]() |
bb9f26b2b1 | ||
![]() |
30890bedd5 | ||
![]() |
3876e8ee55 | ||
![]() |
92d5a7b6a3 | ||
![]() |
ca3dc64fd4 | ||
![]() |
59dbe672c8 | ||
![]() |
42349c5a27 | ||
![]() |
8104a9f3f7 | ||
![]() |
83e96cfd31 | ||
![]() |
4d69fc4cff | ||
![]() |
37c551da1f | ||
![]() |
852128f551 | ||
![]() |
bffa31c0b7 | ||
![]() |
0f129a7809 | ||
![]() |
79b448adf3 | ||
![]() |
dffa3ed670 | ||
![]() |
ef1ac3633b | ||
![]() |
e520afdeff | ||
![]() |
52499cb0bd | ||
![]() |
cfeb9d4e19 | ||
![]() |
a1515ac7b8 | ||
![]() |
396d08dde0 | ||
![]() |
3c7dcfeb5e | ||
![]() |
9b5bcc7147 | ||
![]() |
5c276bd235 | ||
![]() |
c1723bb36b | ||
![]() |
31c3de78b8 | ||
![]() |
197f6e3998 | ||
![]() |
abff9a4d5a | ||
![]() |
91a361add1 | ||
![]() |
68b3e4e8bd | ||
![]() |
f893cf482d | ||
![]() |
88878fccda | ||
![]() |
64325150d5 | ||
![]() |
203db0160a | ||
![]() |
0261cf577c | ||
![]() |
166d9b49f2 | ||
![]() |
213b9ed482 | ||
![]() |
de3141e1f8 | ||
![]() |
6ec79ac1e8 | ||
![]() |
5dbc996b92 | ||
![]() |
f76af65212 | ||
![]() |
1357efa0e3 | ||
![]() |
4da6193ae9 | ||
![]() |
f61e6b2dae | ||
![]() |
230ae0a412 | ||
![]() |
7c967271d7 | ||
![]() |
3d85051915 | ||
![]() |
467fc070d9 | ||
![]() |
14b4331d1d | ||
![]() |
dc427acced | ||
![]() |
769f671749 | ||
![]() |
fb861e26be | ||
![]() |
ab71d75fd1 | ||
![]() |
8743422741 | ||
![]() |
47e19b967f | ||
![]() |
f43bec37bb | ||
![]() |
0fe29a9a80 | ||
![]() |
0f1c7d4ee5 | ||
![]() |
bd336c652e | ||
![]() |
c1ac3060f2 | ||
![]() |
bbe0c961cc | ||
![]() |
c18b00e78b | ||
![]() |
60e28fd6b2 | ||
![]() |
2ef93c50eb | ||
![]() |
ef541f1d77 | ||
![]() |
3dd7ef7cdd | ||
![]() |
922b7722f1 | ||
![]() |
ce0bc75046 | ||
![]() |
7d7cee3405 | ||
![]() |
56acfbbb64 | ||
![]() |
e6d838f3d1 | ||
![]() |
3bfb015b13 | ||
![]() |
dd32bd631f | ||
![]() |
8bfafac7bd | ||
![]() |
e0d52e79c1 | ||
![]() |
2dcb358392 | ||
![]() |
9efacb5797 | ||
![]() |
8e19c8b0e8 | ||
![]() |
bdfb019df2 | ||
![]() |
af8509aacc | ||
![]() |
55e0cd155e | ||
![]() |
417785ee24 | ||
![]() |
5f18ff16de | ||
![]() |
09461527ee | ||
![]() |
ff6c90849e | ||
![]() |
d032bbdc5f | ||
![]() |
df59d21ce7 | ||
![]() |
f38c3416a4 | ||
![]() |
ff9bf2760b | ||
![]() |
87c891d760 | ||
![]() |
566f4f0d1e | ||
![]() |
e81e26fb07 | ||
![]() |
bb7bd60be0 | ||
![]() |
d823eba976 | ||
![]() |
45e71539db | ||
![]() |
47fb287bd5 | ||
![]() |
871d72e3b4 | ||
![]() |
fa35eb3509 | ||
![]() |
275b60c363 | ||
![]() |
1333414ca1 | ||
![]() |
92238dd8c9 | ||
![]() |
5b743f2d0a | ||
![]() |
c18a1d87e1 | ||
![]() |
15130cbe5a | ||
![]() |
1296c6c3ce | ||
![]() |
49c6a8f9b7 | ||
![]() |
955b4ccc18 | ||
![]() |
8c0956aa56 | ||
![]() |
cea9697b6d | ||
![]() |
677fb12ad4 | ||
![]() |
e6ffa7df12 | ||
![]() |
eccc1decad | ||
![]() |
822c979458 | ||
![]() |
79153b6b78 | ||
![]() |
0eb7218063 | ||
![]() |
a2d9610c22 | ||
![]() |
c4d25792ad | ||
![]() |
9c4597da8e | ||
![]() |
1d6228a96a | ||
![]() |
8af4028027 | ||
![]() |
3ddcf3732e | ||
![]() |
ab3dcabbf9 | ||
![]() |
c0723257e6 | ||
![]() |
5830d16382 | ||
![]() |
fd6c5afe2c | ||
![]() |
9b9541cee7 | ||
![]() |
bf8f635680 | ||
![]() |
9688e059f3 | ||
![]() |
6c0f7548f7 | ||
![]() |
e8b362914a | ||
![]() |
a4af320fba | ||
![]() |
8b221dcf0a | ||
![]() |
5b7615a8ee | ||
![]() |
e06e946376 | ||
![]() |
a9d8f2e35f | ||
![]() |
d93bf2cb7c | ||
![]() |
01062d0041 | ||
![]() |
28811c5429 | ||
![]() |
bb887f284e | ||
![]() |
0fe2ab13ab | ||
![]() |
bcb1b37110 | ||
![]() |
6341140e9d | ||
![]() |
ac6f54312d | ||
![]() |
96a00de418 | ||
![]() |
2af1239c67 | ||
![]() |
d2c6909959 | ||
![]() |
a51e26e0dc | ||
![]() |
3a41c0c9c0 | ||
![]() |
17f13690a5 | ||
![]() |
63869cc1f3 | ||
![]() |
d5a313fc03 | ||
![]() |
36a683a36e | ||
![]() |
9a95a980ad | ||
![]() |
5be75ad98b | ||
![]() |
f38b66c6e8 | ||
![]() |
f39232e1a7 | ||
![]() |
435ff66522 | ||
![]() |
ef0298665c | ||
![]() |
302f819d02 | ||
![]() |
3ebb345373 | ||
![]() |
d76a1fe8af | ||
![]() |
82b9cfa96d | ||
![]() |
9e1137da9e | ||
![]() |
3388fdaf88 | ||
![]() |
2cdc7e2d5b | ||
![]() |
db1e544f12 | ||
![]() |
0888e4a873 | ||
![]() |
9612ff3336 | ||
![]() |
8ab15acf84 | ||
![]() |
1f4b215497 | ||
![]() |
1925b0cb75 | ||
![]() |
04b9c9d5e0 | ||
![]() |
8dd4c78641 | ||
![]() |
89fe3156a5 | ||
![]() |
cb77164ae6 | ||
![]() |
ee92eade81 | ||
![]() |
62b91f5d91 | ||
![]() |
8919700245 | ||
![]() |
7f9346ff80 | ||
![]() |
ed127b1735 | ||
![]() |
92e661890e | ||
![]() |
3a6f19e8df | ||
![]() |
b85fbc3224 | ||
![]() |
5db75f1d14 | ||
![]() |
12cafc6a97 | ||
![]() |
50f509d04e | ||
![]() |
d5766070c4 | ||
![]() |
3972340fe7 | ||
![]() |
b18bf2a265 | ||
![]() |
a2e46a84bb | ||
![]() |
1dd64af4ed | ||
![]() |
9f1e09098a | ||
![]() |
b1cd37ddba | ||
![]() |
80550b1de7 | ||
![]() |
7b62c1b1ee | ||
![]() |
28217d1f5a | ||
![]() |
24b6cb6b00 | ||
![]() |
f75c412295 | ||
![]() |
8bf51997ac | ||
![]() |
55084119f6 | ||
![]() |
e816b77b25 | ||
![]() |
86daa95258 | ||
![]() |
96499d2ef7 | ||
![]() |
7ded3aace4 | ||
![]() |
30c7d6ea4d | ||
![]() |
00382f99d3 | ||
![]() |
8682442735 | ||
![]() |
2847ceab78 | ||
![]() |
ec228bb071 | ||
![]() |
81fe58c54d | ||
![]() |
5711910aa0 | ||
![]() |
1f3cafcc4c | ||
![]() |
dc7b5a4c78 | ||
![]() |
e2641d64da | ||
![]() |
8a7d2cfd56 | ||
![]() |
7197ae712a | ||
![]() |
23f2f9fe53 | ||
![]() |
4985e57197 | ||
![]() |
ae60ce162d | ||
![]() |
7fe2675c72 | ||
![]() |
c6265b48eb | ||
![]() |
733ac5bbed | ||
![]() |
20a0461ee6 | ||
![]() |
deeaaf012c | ||
![]() |
adbb347f28 | ||
![]() |
60222dddd4 | ||
![]() |
2f34560fa2 | ||
![]() |
26f2ba4e46 | ||
![]() |
01fe1445af | ||
![]() |
e68369f532 | ||
![]() |
bedb07bc8f | ||
![]() |
238c43440b | ||
![]() |
7c4edde4e7 | ||
![]() |
7f130b2978 | ||
![]() |
4850e348fe | ||
![]() |
5468bb08d5 | ||
![]() |
b11ba9b532 | ||
![]() |
b8c5d50d45 | ||
![]() |
f6fcddce9d | ||
![]() |
7f9a5dded6 | ||
![]() |
6affffa83e | ||
![]() |
82f7705650 | ||
![]() |
985c8502ce | ||
![]() |
ab68c055af | ||
![]() |
e41f68cced | ||
![]() |
96305bf13b | ||
![]() |
9dd46d7397 | ||
![]() |
03efbda77d | ||
![]() |
13cd46450f | ||
![]() |
4cf0ae2592 | ||
![]() |
b81fd4db36 | ||
![]() |
7176971224 | ||
![]() |
38bca76219 | ||
![]() |
98c723100d | ||
![]() |
043bb7f894 | ||
![]() |
8920fdb33d | ||
![]() |
ce5d9520f4 | ||
![]() |
f43988a561 | ||
![]() |
a1a1cab530 | ||
![]() |
c9e57eb01d | ||
![]() |
0719e4782d | ||
![]() |
870a737c65 | ||
![]() |
f0cd9bf13f | ||
![]() |
0c175fee74 | ||
![]() |
752c1db155 | ||
![]() |
725ba21144 | ||
![]() |
341c433385 | ||
![]() |
8758393620 | ||
![]() |
53a9a9db3d | ||
![]() |
2c1f5eacb8 | ||
![]() |
1edea9bea6 | ||
![]() |
134d9212fa | ||
![]() |
11700a3f10 | ||
![]() |
db506509e9 | ||
![]() |
481996ec76 | ||
![]() |
3fcba91e5b | ||
![]() |
4d86d80e3e | ||
![]() |
ac12afb1f2 | ||
![]() |
886edeb8b0 | ||
![]() |
9779555526 | ||
![]() |
884f1d3640 | ||
![]() |
faeab592c1 | ||
![]() |
143a3ebd0a | ||
![]() |
f40501b3a0 | ||
![]() |
56cb75831d | ||
![]() |
32dc6c28ba | ||
![]() |
c25d1dec69 | ||
![]() |
adabdac2a9 | ||
![]() |
b61cc75a92 | ||
![]() |
86aa9a9cc4 | ||
![]() |
bbdc40f93e | ||
![]() |
6cfe41a64f | ||
![]() |
cfa308bb04 | ||
![]() |
f197551902 | ||
![]() |
f8595d205a | ||
![]() |
ce98159b2d | ||
![]() |
5bb6ea047e | ||
![]() |
fbab23305e | ||
![]() |
9a08b8de67 | ||
![]() |
c982fc639b | ||
![]() |
66e6d93ef5 | ||
![]() |
4e63224b07 | ||
![]() |
c8857d0ecb | ||
![]() |
a9f5349aa8 | ||
![]() |
d959a1b7d8 | ||
![]() |
ec9112e941 | ||
![]() |
4577adb008 | ||
![]() |
fae4c7f9bc | ||
![]() |
12ad9045c9 | ||
![]() |
32768252fa | ||
![]() |
bb035cb84c | ||
![]() |
cf5f14c0bb | ||
![]() |
b0794eae47 | ||
![]() |
a90fbd869c | ||
![]() |
7ff9930893 | ||
![]() |
b57bc8595a | ||
![]() |
ab950340e2 | ||
![]() |
f928b5a056 | ||
![]() |
43415f9e14 | ||
![]() |
57dc28f518 | ||
![]() |
ee17e0cb78 | ||
![]() |
468fd0e07a | ||
![]() |
4dc0885004 | ||
![]() |
1dfdbec246 | ||
![]() |
fd7a5aa0d0 | ||
![]() |
27f5ccda82 |
208 changed files with 4593 additions and 4671 deletions
|
@ -364,11 +364,47 @@
|
|||
"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"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "qcoudeyr",
|
||||
"name": "qcoudeyr",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/124463277?v=4",
|
||||
"profile": "https://github.com/qcoudeyr",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 7,
|
||||
"projectName": "runtipi",
|
||||
"projectOwner": "meienberger",
|
||||
"projectOwner": "runtipi",
|
||||
"repoType": "github",
|
||||
"repoHost": "https://github.com",
|
||||
"skipCi": true,
|
||||
|
|
122
.github/workflows/alpha-release.yml
vendored
122
.github/workflows/alpha-release.yml
vendored
|
@ -11,65 +11,95 @@ 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@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Create Tag
|
||||
id: create_tag
|
||||
uses: butlerlogic/action-autotag@stable
|
||||
env:
|
||||
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
|
||||
- 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
|
||||
|
||||
- uses: rickstaa/action-create-tag@v1
|
||||
with:
|
||||
tag_prefix: 'v'
|
||||
tag_suffix: '-alpha.${{ github.event.inputs.tag }}'
|
||||
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
|
||||
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@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push images
|
||||
uses: docker/build-push-action@v4
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
tags: meienberger/runtipi:${{ needs.create-tag.outputs.tagname }}
|
||||
cache-from: type=registry,ref=meienberger/runtipi:buildcache
|
||||
cache-to: type=registry,ref=meienberger/runtipi:buildcache,mode=max
|
||||
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: create-tag
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
node-version: 20
|
||||
|
||||
- uses: pnpm/action-setup@v2.2.4
|
||||
- uses: pnpm/action-setup@v2.4.0
|
||||
name: Install pnpm
|
||||
id: pnpm-install
|
||||
with:
|
||||
|
@ -99,51 +129,37 @@ jobs:
|
|||
run: pnpm -r --filter cli package
|
||||
|
||||
- name: Upload CLI
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: cli
|
||||
path: packages/cli/dist
|
||||
|
||||
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
|
||||
uses: actions/download-artifact@v2
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
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
|
||||
|
|
144
.github/workflows/beta-release.yml
vendored
144
.github/workflows/beta-release.yml
vendored
|
@ -8,67 +8,98 @@ 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@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v3
|
||||
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
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push images
|
||||
uses: docker/build-push-action@v4
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: meienberger/runtipi:${{ needs.get-tag.outputs.tag }}
|
||||
cache-from: type=registry,ref=meienberger/runtipi:buildcache
|
||||
cache-to: type=registry,ref=meienberger/runtipi:buildcache,mode=max
|
||||
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@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
node-version: 20
|
||||
|
||||
- uses: pnpm/action-setup@v2.2.4
|
||||
- uses: pnpm/action-setup@v2.4.0
|
||||
name: Install pnpm
|
||||
id: pnpm-install
|
||||
with:
|
||||
|
@ -92,80 +123,49 @@ 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
|
||||
|
||||
- name: Upload CLI
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
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@v3
|
||||
|
||||
- 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:
|
||||
- name: Download CLI
|
||||
uses: actions/download-artifact@v2
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
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]
|
||||
|
|
20
.github/workflows/ci.yml
vendored
20
.github/workflows/ci.yml
vendored
|
@ -1,6 +1,6 @@
|
|||
name: Tipi CI
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
ROOT_FOLDER: /runtipi
|
||||
|
@ -38,14 +38,14 @@ jobs:
|
|||
--health-retries 5
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
node-version: 20
|
||||
|
||||
- uses: pnpm/action-setup@v2.2.4
|
||||
- uses: pnpm/action-setup@v2.4.0
|
||||
name: Install pnpm
|
||||
id: pnpm-install
|
||||
with:
|
||||
|
@ -76,7 +76,7 @@ jobs:
|
|||
|
||||
- name: Get number of CPU cores
|
||||
id: cpu-cores
|
||||
uses: SimenB/github-actions-cpu-cores@v1
|
||||
uses: SimenB/github-actions-cpu-cores@v2
|
||||
|
||||
- name: Run tests
|
||||
run: pnpm run test --max-workers ${{ steps.cpu-cores.outputs.count }}
|
||||
|
@ -101,14 +101,14 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
node-version: 20
|
||||
|
||||
- uses: pnpm/action-setup@v2.2.4
|
||||
- uses: pnpm/action-setup@v2.4.0
|
||||
name: Install pnpm
|
||||
id: pnpm-install
|
||||
with:
|
||||
|
|
2
.github/workflows/dependency-review.yml
vendored
2
.github/workflows/dependency-review.yml
vendored
|
@ -15,6 +15,6 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 'Checkout Repository'
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
- name: 'Dependency Review'
|
||||
uses: actions/dependency-review-action@v3
|
||||
|
|
18
.github/workflows/e2e.yml
vendored
18
.github/workflows/e2e.yml
vendored
|
@ -29,7 +29,7 @@ jobs:
|
|||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install SSH key
|
||||
uses: shimataro/ssh-key-action@v2
|
||||
|
@ -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:
|
||||
|
@ -110,9 +110,9 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
needs: [deploy]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: pnpm/action-setup@v2.2.4
|
||||
- uses: pnpm/action-setup@v2.4.0
|
||||
name: Install pnpm
|
||||
id: pnpm-install
|
||||
with:
|
||||
|
@ -132,9 +132,9 @@ jobs:
|
|||
restore-keys: |
|
||||
${{ runner.os }}-pnpm-store-
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
node-version: 20
|
||||
|
||||
- name: Create .env.e2e file with Droplet IP
|
||||
run: |
|
||||
|
@ -181,7 +181,7 @@ jobs:
|
|||
uses: actions/configure-pages@v3
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-pages-artifact@v1
|
||||
uses: actions/upload-pages-artifact@v2
|
||||
with:
|
||||
path: playwright-report/
|
||||
|
||||
|
|
41
.github/workflows/release-candidate.yml
vendored
41
.github/workflows/release-candidate.yml
vendored
|
@ -1,41 +0,0 @@
|
|||
name: Release candidate
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
# Build images and publish RCs to DockerHub
|
||||
build-images:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Get tag from VERSION file
|
||||
id: meta
|
||||
run: |
|
||||
VERSION=$(npm run version --silent)
|
||||
TAG=${VERSION}
|
||||
echo "tag=${TAG}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build and push images
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: meienberger/runtipi:rc-${{ steps.meta.outputs.TAG }}
|
||||
cache-from: type=registry,ref=meienberger/runtipi:buildcache
|
||||
cache-to: type=registry,ref=meienberger/runtipi:buildcache,mode=max
|
147
.github/workflows/release.yml
vendored
147
.github/workflows/release.yml
vendored
|
@ -3,69 +3,101 @@ 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@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v3
|
||||
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
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push images
|
||||
uses: docker/build-push-action@v4
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: meienberger/runtipi:latest,meienberger/runtipi:${{ needs.get-tag.outputs.tag }}
|
||||
cache-from: type=registry,ref=meienberger/runtipi:buildcache
|
||||
cache-to: type=registry,ref=meienberger/runtipi:buildcache,mode=max
|
||||
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@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
node-version: 20
|
||||
|
||||
- uses: pnpm/action-setup@v2.2.4
|
||||
- uses: pnpm/action-setup@v2.4.0
|
||||
name: Install pnpm
|
||||
id: pnpm-install
|
||||
with:
|
||||
|
@ -89,78 +121,49 @@ 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
|
||||
|
||||
- name: Upload CLI
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
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@v3
|
||||
|
||||
- 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]
|
||||
needs: [create-tag, build-images, build-worker, build-cli]
|
||||
outputs:
|
||||
id: ${{ steps.create_release.outputs.id }}
|
||||
steps:
|
||||
- name: Download CLI
|
||||
uses: actions/download-artifact@v2
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
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]
|
||||
|
@ -175,12 +178,12 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Promote release
|
||||
uses: actions/github-script@v4
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const id = '${{ needs.publish-release.outputs.id }}';
|
||||
github.repos.updateRelease({
|
||||
github.rest.repos.updateRelease({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
release_id: id,
|
||||
|
|
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -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/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
ARG NODE_VERSION="18.16"
|
||||
ARG NODE_VERSION="20.10"
|
||||
ARG ALPINE_VERSION="3.18"
|
||||
|
||||
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS node_base
|
||||
|
@ -33,7 +33,8 @@ RUN npm run build
|
|||
FROM node_base AS app
|
||||
|
||||
ENV NODE_ENV production
|
||||
# USER node
|
||||
|
||||
USER node
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
ARG NODE_VERSION="18.16"
|
||||
ARG NODE_VERSION="20.10"
|
||||
ARG ALPINE_VERSION="3.18"
|
||||
|
||||
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION}
|
||||
|
|
60
README.md
60
README.md
|
@ -1,9 +1,7 @@
|
|||
# Tipi — A personal homeserver for everyone
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||
|
||||
[](#contributors-)
|
||||
|
||||
[](#contributors-)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||
|
||||
[](https://github.com/runtipi/runtipi/blob/master/LICENSE)
|
||||
|
@ -14,6 +12,8 @@
|
|||

|
||||
[](https://crowdin.com/project/runtipi)
|
||||
|
||||
> 💡 Tipi is built with TypeScript, Next.js app router and Drizzle ORM! If you want to collaborate on a cool project, join the discussion on Discord!
|
||||
|
||||
#### Join the discussion
|
||||
|
||||
[](https://discord.gg/Bu9qEPnHsc)
|
||||
|
@ -73,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>
|
||||
|
@ -111,16 +111,20 @@ 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>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/qcoudeyr"><img src="https://avatars.githubusercontent.com/u/124463277?v=4?s=100" width="100px;" alt="qcoudeyr"/><br /><sub><b>qcoudeyr</b></sub></a><br /><a href="https://github.com/runtipi/runtipi/commits?author=qcoudeyr" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -2,8 +2,10 @@ import { test, expect } from '@playwright/test';
|
|||
import { loginUser } from './fixtures/fixtures';
|
||||
import { clearDatabase } from './helpers/db';
|
||||
import { testUser } from './helpers/constants';
|
||||
import { setSettings } from './helpers/settings';
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await setSettings({});
|
||||
await clearDatabase();
|
||||
await loginUser(page);
|
||||
|
||||
|
@ -31,3 +33,49 @@ test('user can change their password', async ({ page }) => {
|
|||
|
||||
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
|
||||
});
|
||||
|
||||
test('user can change their email', async ({ page }) => {
|
||||
// Change email
|
||||
const newEmail = 'tester2@test.com';
|
||||
|
||||
await page.getByRole('tab', { name: 'Security' }).click();
|
||||
await page.getByRole('button', { name: 'Change username' }).click();
|
||||
await page.getByPlaceholder('New username').click();
|
||||
await page.getByPlaceholder('New username').fill(newEmail);
|
||||
|
||||
// Wrong password
|
||||
await page.getByPlaceholder('Password', { exact: true }).click();
|
||||
await page.getByPlaceholder('Password', { exact: true }).fill('incorrect');
|
||||
|
||||
await page.getByRole('button', { name: 'Change username' }).click();
|
||||
|
||||
await expect(page.getByText('Invalid password')).toBeVisible();
|
||||
|
||||
// Wrong email
|
||||
await page.getByPlaceholder('Password', { exact: true }).click();
|
||||
await page.getByPlaceholder('Password', { exact: true }).fill(testUser.password);
|
||||
await page.getByPlaceholder('New username').click();
|
||||
await page.getByPlaceholder('New username').fill('incorrect');
|
||||
|
||||
await page.getByRole('button', { name: 'Change username' }).click();
|
||||
|
||||
await expect(page.getByText('Must be a valid email address')).toBeVisible();
|
||||
|
||||
// Correct email and password
|
||||
await page.getByPlaceholder('New username').click();
|
||||
await page.getByPlaceholder('New username').fill(newEmail);
|
||||
|
||||
await page.getByRole('button', { name: 'Change username' }).click();
|
||||
|
||||
await expect(page.getByText('Username changed successfully')).toBeVisible();
|
||||
|
||||
// Login with new email
|
||||
await page.getByPlaceholder('you@example.com').click();
|
||||
await page.getByPlaceholder('you@example.com').fill(newEmail);
|
||||
await page.getByPlaceholder('Your password').click();
|
||||
await page.getByPlaceholder('Your password').fill(testUser.password);
|
||||
|
||||
await page.getByRole('button', { name: 'Login' }).click();
|
||||
|
||||
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
|
||||
});
|
||||
|
|
58
e2e/0005-guest-dashboard.spec.ts
Normal file
58
e2e/0005-guest-dashboard.spec.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
import { test, expect } from '@playwright/test';
|
||||
import { appTable } from '@/server/db/schema';
|
||||
import { setSettings } from './helpers/settings';
|
||||
import { loginUser } from './fixtures/fixtures';
|
||||
import { clearDatabase, db } from './helpers/db';
|
||||
|
||||
test.beforeEach(async () => {
|
||||
await clearDatabase();
|
||||
await setSettings({});
|
||||
});
|
||||
|
||||
test('user can activate the guest dashboard and see it when logged out', async ({ page }) => {
|
||||
await loginUser(page);
|
||||
await page.goto('/settings');
|
||||
|
||||
await page.getByRole('tab', { name: 'Settings' }).click();
|
||||
await page.getByLabel('guestDashboard').setChecked(true);
|
||||
await page.getByRole('button', { name: 'Save' }).click();
|
||||
await page.getByTestId('logout-button').click();
|
||||
|
||||
await expect(page.getByText('No apps to display')).toBeVisible();
|
||||
});
|
||||
|
||||
test('logged out users can see the apps on the guest dashboard', async ({ browser }) => {
|
||||
await setSettings({ guestDashboard: true });
|
||||
await db.insert(appTable).values({ config: {}, isVisibleOnGuestDashboard: true, id: 'hello-world', exposed: true, domain: 'duckduckgo.com', status: 'running' });
|
||||
await db.insert(appTable).values({ config: {}, isVisibleOnGuestDashboard: false, id: 'actual-budget', exposed: false, status: 'running' });
|
||||
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
await page.goto('/');
|
||||
await expect(page.getByText(/Hello World web server/)).toBeVisible();
|
||||
const locator = page.locator('text=Actual Budget');
|
||||
expect(locator).not.toBeVisible();
|
||||
|
||||
const [newPage] = await Promise.all([context.waitForEvent('page'), await page.getByRole('link', { name: /Hello World/ }).click()]);
|
||||
|
||||
await newPage.waitForLoadState();
|
||||
expect(newPage.url()).toBe('https://duckduckgo.com/');
|
||||
await newPage.close();
|
||||
|
||||
await context.close();
|
||||
});
|
||||
|
||||
test('user can deactivate the guest dashboard and not see it when logged out', async ({ page }) => {
|
||||
await loginUser(page);
|
||||
await page.goto('/settings');
|
||||
|
||||
await page.getByRole('tab', { name: 'Settings' }).click();
|
||||
await page.getByLabel('guestDashboard').setChecked(false);
|
||||
await page.getByRole('button', { name: 'Save' }).click();
|
||||
await page.getByTestId('logout-button').click();
|
||||
|
||||
await page.goto('/');
|
||||
|
||||
// We should be redirected to the login page
|
||||
await expect(page.getByRole('heading', { name: 'Login' })).toBeVisible();
|
||||
});
|
|
@ -1,10 +1,12 @@
|
|||
import { clearDatabase } from './db';
|
||||
import { setSettings } from './settings';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function globalSetup() {
|
||||
await clearDatabase();
|
||||
await setSettings({});
|
||||
}
|
||||
|
||||
export default globalSetup;
|
||||
|
|
8
e2e/helpers/settings.ts
Normal file
8
e2e/helpers/settings.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { promises } from 'fs';
|
||||
import path from 'path';
|
||||
import { z } from 'zod';
|
||||
import { settingsSchema } from '@runtipi/shared';
|
||||
|
||||
export const setSettings = async (settings: z.infer<typeof settingsSchema>) => {
|
||||
await promises.writeFile(path.join(__dirname, '../../state/settings.json'), JSON.stringify(settings));
|
||||
};
|
1
next-env.d.ts
vendored
1
next-env.d.ts
vendored
|
@ -1,6 +1,5 @@
|
|||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
/// <reference types="next/navigation-types/compat/navigation" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||
|
|
|
@ -6,7 +6,6 @@ const nextConfig = {
|
|||
transpilePackages: ['@runtipi/shared'],
|
||||
experimental: {
|
||||
serverComponentsExternalPackages: ['bullmq'],
|
||||
serverActions: true,
|
||||
},
|
||||
serverRuntimeConfig: {
|
||||
INTERNAL_IP: process.env.INTERNAL_IP,
|
||||
|
|
91
package.json
91
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "runtipi",
|
||||
"version": "2.0.6",
|
||||
"version": "2.2.1",
|
||||
"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",
|
||||
|
@ -32,45 +32,48 @@
|
|||
"tsc": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hookform/resolvers": "^3.3.1",
|
||||
"@hookform/resolvers": "^3.3.2",
|
||||
"@otplib/core": "^12.0.1",
|
||||
"@otplib/plugin-crypto": "^12.0.1",
|
||||
"@otplib/plugin-thirty-two": "^12.0.1",
|
||||
"@radix-ui/react-dialog": "^1.0.5",
|
||||
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
||||
"@radix-ui/react-scroll-area": "^1.0.5",
|
||||
"@radix-ui/react-select": "^2.0.0",
|
||||
"@radix-ui/react-switch": "^1.0.3",
|
||||
"@radix-ui/react-tabs": "^1.0.4",
|
||||
"@runtipi/postgres-migrations": "^5.3.0",
|
||||
"@runtipi/shared": "workspace:^",
|
||||
"@tabler/core": "1.0.0-beta19",
|
||||
"@tabler/icons-react": "^2.38.0",
|
||||
"argon2": "^0.31.1",
|
||||
"bullmq": "^4.12.3",
|
||||
"@tabler/core": "1.0.0-beta20",
|
||||
"@tabler/icons-react": "^2.42.0",
|
||||
"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",
|
||||
"geist": "^1.2.0",
|
||||
"let-it-go": "^1.0.0",
|
||||
"lodash.merge": "^4.6.2",
|
||||
"next": "13.5.4",
|
||||
"next-client-cookies": "^1.0.5",
|
||||
"next-intl": "^2.20.2",
|
||||
"next-safe-action": "^3.4.0",
|
||||
"next": "14.0.1",
|
||||
"next-client-cookies": "^1.0.6",
|
||||
"next-intl": "^2.22.1",
|
||||
"next-safe-action": "^5.0.2",
|
||||
"pg": "^8.11.3",
|
||||
"qrcode.react": "^3.1.0",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"react-hook-form": "^7.47.0",
|
||||
"react-hook-form": "^7.48.2",
|
||||
"react-hot-toast": "^2.4.1",
|
||||
"react-markdown": "^9.0.0",
|
||||
"react-select": "^5.7.7",
|
||||
"react-tooltip": "^5.21.5",
|
||||
"react-select": "^5.8.0",
|
||||
"react-tooltip": "^5.25.0",
|
||||
"redaxios": "^0.5.1",
|
||||
"redis": "^4.6.10",
|
||||
"rehype-raw": "^7.0.0",
|
||||
"remark-breaks": "^4.0.0",
|
||||
"remark-gfm": "^4.0.0",
|
||||
"sass": "^1.69.2",
|
||||
"sass": "^1.69.5",
|
||||
"semver": "^7.5.4",
|
||||
"sharp": "0.32.6",
|
||||
"swr": "^2.2.4",
|
||||
|
@ -78,57 +81,57 @@
|
|||
"uuid": "^9.0.1",
|
||||
"validator": "^13.11.0",
|
||||
"winston": "^3.11.0",
|
||||
"zod": "^3.21.4",
|
||||
"zustand": "^4.4.3"
|
||||
"zod": "^3.22.4",
|
||||
"zustand": "^4.4.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.23.0",
|
||||
"@faker-js/faker": "^8.1.0",
|
||||
"@playwright/test": "^1.38.1",
|
||||
"@babel/core": "^7.23.2",
|
||||
"@faker-js/faker": "^8.2.0",
|
||||
"@playwright/test": "^1.39.0",
|
||||
"@testing-library/dom": "^9.3.3",
|
||||
"@testing-library/jest-dom": "^6.1.3",
|
||||
"@testing-library/jest-dom": "^6.1.4",
|
||||
"@testing-library/react": "^14.0.0",
|
||||
"@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.2",
|
||||
"@types/jest": "^29.5.5",
|
||||
"@types/lodash.merge": "^4.6.7",
|
||||
"@types/node": "20.8.4",
|
||||
"@types/pg": "^8.10.5",
|
||||
"@types/react": "18.2.28",
|
||||
"@types/react-dom": "18.2.13",
|
||||
"@types/semver": "^7.5.3",
|
||||
"@types/uuid": "^9.0.5",
|
||||
"@types/validator": "^13.11.2",
|
||||
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
||||
"@typescript-eslint/parser": "^6.7.5",
|
||||
"@vitejs/plugin-react": "^4.1.0",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/jest": "^29.5.11",
|
||||
"@types/lodash.merge": "^4.6.8",
|
||||
"@types/node": "20.8.10",
|
||||
"@types/pg": "^8.10.7",
|
||||
"@types/react": "18.2.39",
|
||||
"@types/react-dom": "18.2.14",
|
||||
"@types/semver": "^7.5.4",
|
||||
"@types/uuid": "^9.0.6",
|
||||
"@types/validator": "^13.11.5",
|
||||
"@typescript-eslint/eslint-plugin": "^6.13.1",
|
||||
"@typescript-eslint/parser": "^6.10.0",
|
||||
"@vitejs/plugin-react": "^4.1.1",
|
||||
"@vitest/coverage-v8": "^0.34.6",
|
||||
"dotenv-cli": "^7.3.0",
|
||||
"eslint": "8.51.0",
|
||||
"eslint": "8.52.0",
|
||||
"eslint-config-airbnb": "^19.0.4",
|
||||
"eslint-config-airbnb-typescript": "^17.1.0",
|
||||
"eslint-config-next": "13.5.4",
|
||||
"eslint-config-next": "14.0.3",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-import-resolver-typescript": "^3.6.1",
|
||||
"eslint-plugin-import": "^2.28.1",
|
||||
"eslint-plugin-jest": "^27.4.2",
|
||||
"eslint-plugin-import": "^2.29.0",
|
||||
"eslint-plugin-jest": "^27.6.0",
|
||||
"eslint-plugin-jest-dom": "^5.1.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.7.1",
|
||||
"eslint-plugin-jsx-a11y": "^6.8.0",
|
||||
"eslint-plugin-react": "^7.33.2",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-testing-library": "^6.0.2",
|
||||
"eslint-plugin-testing-library": "^6.1.0",
|
||||
"jest": "^29.7.0",
|
||||
"jest-environment-jsdom": "^29.7.0",
|
||||
"knip": "^2.33.1",
|
||||
"knip": "^2.41.3",
|
||||
"memfs": "^4.6.0",
|
||||
"msw": "^1.3.2",
|
||||
"next-router-mock": "^0.9.10",
|
||||
"prettier": "^3.0.3",
|
||||
"ts-jest": "^29.1.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsx": "^3.13.0",
|
||||
"tsx": "^3.14.0",
|
||||
"typescript": "5.2.2",
|
||||
"vite-tsconfig-paths": "^4.2.1",
|
||||
"vitest": "^0.34.6",
|
||||
|
@ -148,8 +151,6 @@
|
|||
},
|
||||
"homepage": "https://github.com/runtipi/runtipi#readme",
|
||||
"pnpm": {
|
||||
"patchedDependencies": {
|
||||
"next-safe-action@3.4.0": "patches/next-safe-action@3.4.0.patch"
|
||||
}
|
||||
"patchedDependencies": {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -19,10 +21,10 @@ services:
|
|||
tipi-db:
|
||||
container_name: tipi-db
|
||||
image: postgres:14
|
||||
restart: on-failure
|
||||
restart: unless-stopped
|
||||
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: meienberger/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
|
||||
|
|
|
@ -8,7 +8,7 @@ async function bundle() {
|
|||
entryPoints: ['./src/index.ts'],
|
||||
outfile: './dist/index.js',
|
||||
platform: 'node',
|
||||
target: 'node18',
|
||||
target: 'node20',
|
||||
bundle: true,
|
||||
color: true,
|
||||
sourcemap: commandArgs.includes('--sourcemap'),
|
||||
|
|
|
@ -1,26 +1,27 @@
|
|||
{
|
||||
"name": "@runtipi/cli",
|
||||
"version": "2.0.6",
|
||||
"version": "2.1.0",
|
||||
"description": "",
|
||||
"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",
|
||||
"package:m1": "npm run build && pkg package.json -t node20-darwin-arm64",
|
||||
"set-version": "node -e \"require('fs').writeFileSync('assets/VERSION', process.argv[1])\"",
|
||||
"build": "node build.js",
|
||||
"build:meta": "esbuild ./src/index.ts --bundle --platform=node --target=node18 --outfile=dist/index.js --metafile=meta.json --analyze",
|
||||
"build:meta": "esbuild ./src/index.ts --bundle --platform=node --target=node20 --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/**/*",
|
||||
"targets": [
|
||||
"node18-linux-x64",
|
||||
"node18-linux-arm64"
|
||||
"node20-linux-x64",
|
||||
"node20-linux-arm64"
|
||||
],
|
||||
"outputPath": "dist/bin"
|
||||
},
|
||||
|
@ -28,37 +29,32 @@
|
|||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@faker-js/faker": "^8.1.0",
|
||||
"@types/cli-progress": "^3.11.3",
|
||||
"@types/node": "20.8.4",
|
||||
"@types/web-push": "^3.6.1",
|
||||
"@faker-js/faker": "^8.2.0",
|
||||
"@types/cli-progress": "^3.11.5",
|
||||
"@types/node": "20.8.10",
|
||||
"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",
|
||||
"vite": "^4.4.11",
|
||||
"vite": "^4.5.0",
|
||||
"vite-tsconfig-paths": "^4.2.1",
|
||||
"vitest": "^0.34.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@runtipi/postgres-migrations": "^5.3.0",
|
||||
"@runtipi/shared": "workspace:^",
|
||||
"axios": "^1.5.1",
|
||||
"axios": "^1.6.0",
|
||||
"boxen": "^7.1.1",
|
||||
"bullmq": "^4.12.3",
|
||||
"bullmq": "^4.13.0",
|
||||
"chalk": "^5.3.0",
|
||||
"cli-progress": "^3.12.0",
|
||||
"cli-spinners": "^2.9.1",
|
||||
"commander": "^11.0.0",
|
||||
"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.11",
|
||||
"web-push": "^3.6.6",
|
||||
"zod": "^3.21.4"
|
||||
"zod": "^3.22.4"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,294 +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) => {
|
||||
try {
|
||||
this.logger.info(`Stopping app ${appId}`);
|
||||
public stopApp = async (appId: string) => {
|
||||
const spinner = new TerminalSpinner(`Stopping app ${appId}`);
|
||||
spinner.start();
|
||||
|
||||
this.logger.info(`Regenerating app.env file for app ${appId}`);
|
||||
await this.ensureAppDir(appId);
|
||||
const jobid = this.generateJobId({ appId, action: 'stop' });
|
||||
|
||||
if (!skipEnvGeneration) {
|
||||
await generateEnvFile(appId, config);
|
||||
}
|
||||
await compose(appId, 'rm --force --stop');
|
||||
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);
|
||||
|
||||
this.logger.info(`App ${appId} stopped`);
|
||||
return { success: true, message: `App ${appId} stopped successfully` };
|
||||
} catch (err) {
|
||||
return this.handleAppError(err);
|
||||
await queueEvents.close();
|
||||
await queue.close();
|
||||
|
||||
if (!result?.success) {
|
||||
this.logger.error(result?.message);
|
||||
spinner.fail(`Failed to stop app ${appId} see logs for more details (logs/error.log)`);
|
||||
} else {
|
||||
spinner.done(`App ${appId} stopped`);
|
||||
}
|
||||
};
|
||||
|
||||
public startApp = async (appId: string, config: Record<string, unknown>) => {
|
||||
try {
|
||||
const { appDataDirPath } = this.getAppPaths(appId);
|
||||
public startApp = async (appId: string) => {
|
||||
const spinner = new TerminalSpinner(`Starting app ${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);
|
||||
await compose(appId, 'up --detach --force-recreate --remove-orphans --pull always');
|
||||
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);
|
||||
|
||||
this.logger.info(`App ${appId} started`);
|
||||
await queueEvents.close();
|
||||
await queue.close();
|
||||
|
||||
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);
|
||||
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) {
|
||||
spinner.setMessage(`Starting app ${row.id}`);
|
||||
spinner.start();
|
||||
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}'`);
|
||||
spinner.fail(`Error starting app ${id}`);
|
||||
} else {
|
||||
await client.query(`UPDATE app SET status = 'running' WHERE id = '${id}'`);
|
||||
spinner.done(`App ${id} started`);
|
||||
}
|
||||
}
|
||||
} 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();
|
||||
if (!result.success) {
|
||||
spinner.fail(`Failed to start app ${appId} see logs for more details (logs/error.log)`);
|
||||
} else {
|
||||
spinner.done(`App ${appId} started`);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
export { AppExecutors } from './app/app.executors';
|
||||
export { RepoExecutors } from './repo/repo.executors';
|
||||
export { SystemExecutors } from './system/system.executors';
|
||||
|
|
|
@ -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');
|
||||
};
|
|
@ -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,66 +41,9 @@ 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 {
|
||||
const { rootFolderHost } = getEnv();
|
||||
|
||||
await fs.promises.rm(path.join(rootFolderHost, 'logs'), { recursive: true, force: true });
|
||||
await fs.promises.mkdir(path.join(rootFolderHost, 'logs'));
|
||||
|
||||
await this.logger.flush();
|
||||
this.logger.info('Logs cleaned successfully');
|
||||
|
||||
return { success: true, message: '' };
|
||||
|
@ -117,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.
|
||||
|
@ -147,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`);
|
||||
}
|
||||
}
|
||||
|
@ -171,52 +92,30 @@ 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 {
|
||||
const { isSudo } = getUserIds();
|
||||
|
||||
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');
|
||||
}
|
||||
await this.logger.flush();
|
||||
|
||||
// Check if user is in docker group
|
||||
spinner.setMessage('Checking docker permissions...');
|
||||
spinner.start();
|
||||
const { stdout: dockerVersion } = await execAsync('docker --version');
|
||||
|
||||
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();
|
||||
|
||||
this.logger.info('Copying system files...');
|
||||
await copySystemFiles();
|
||||
|
||||
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...');
|
||||
|
@ -243,65 +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);
|
||||
|
||||
// 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(
|
||||
|
@ -333,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);
|
||||
|
|
|
@ -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'
|
||||
|
@ -32,14 +28,12 @@ type EnvKeys =
|
|||
| '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
|
||||
*/
|
||||
|
@ -146,172 +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('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');
|
||||
}
|
||||
};
|
||||
|
|
|
@ -3,28 +3,20 @@ import { program } from 'commander';
|
|||
|
||||
import chalk from 'chalk';
|
||||
import { description, version } from '../package.json';
|
||||
import { startWorker } from './services/watcher/watcher';
|
||||
import { SystemExecutors } from './executors';
|
||||
import { AppExecutors, SystemExecutors } from './executors';
|
||||
|
||||
const main = async () => {
|
||||
program.description(description).version(version);
|
||||
|
||||
program
|
||||
.command('watch')
|
||||
.description('Watcher script for events queue')
|
||||
.action(async () => {
|
||||
console.log('Starting watcher');
|
||||
startWorker();
|
||||
});
|
||||
program.name('./runtipi-cli').usage('<command> [options]');
|
||||
|
||||
program
|
||||
.command('start')
|
||||
.description('Start tipi')
|
||||
.option('--no-permissions', 'Skip permissions check')
|
||||
.option('--no-sudo', 'Skip sudo usage')
|
||||
.action(async (options) => {
|
||||
.addHelpText('after', '\nExample call: sudo ./runtipi-cli start')
|
||||
.action(async () => {
|
||||
const systemExecutors = new SystemExecutors();
|
||||
await systemExecutors.start(options.sudo);
|
||||
await systemExecutors.start();
|
||||
});
|
||||
|
||||
program
|
||||
|
@ -69,6 +61,26 @@ const main = async () => {
|
|||
await systemExecutors.cleanLogs();
|
||||
});
|
||||
|
||||
// Start app: ./cli app start <app>
|
||||
// Stop app: ./cli app stop <app>
|
||||
program
|
||||
.command('app [command] <app>')
|
||||
.addHelpText('after', '\nExample call: sudo ./runtipi-cli app start <app>')
|
||||
.description('App management')
|
||||
.action(async (command, app) => {
|
||||
const appExecutors = new AppExecutors();
|
||||
switch (command) {
|
||||
case 'start':
|
||||
await appExecutors.startApp(app);
|
||||
break;
|
||||
case 'stop':
|
||||
await appExecutors.stopApp(app);
|
||||
break;
|
||||
default:
|
||||
console.log(chalk.red('✗'), 'Unknown command');
|
||||
}
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
};
|
||||
|
||||
|
|
|
@ -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 };
|
||||
};
|
|
@ -1,4 +0,0 @@
|
|||
import { createLogger } from '@runtipi/shared';
|
||||
import path from 'path';
|
||||
|
||||
export const fileLogger = createLogger('cli', path.join(process.cwd(), 'logs'));
|
4
packages/cli/src/utils/logger/logger.ts
Normal file
4
packages/cli/src/utils/logger/logger.ts
Normal 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'));
|
|
@ -11,7 +11,7 @@
|
|||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"winston": "^3.9.0",
|
||||
"zod": "^3.21.4"
|
||||
"winston": "^3.11.0",
|
||||
"zod": "^3.22.4"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
export * from './env-helpers';
|
||||
export * from './fs-helpers';
|
||||
|
|
|
@ -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';
|
||||
|
|
61
packages/shared/src/lib/FileLogger/FileLogger.ts
Normal file
61
packages/shared/src/lib/FileLogger/FileLogger.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { createLogger } from '../../utils/logger';
|
||||
|
||||
function streamLogToHistory(logsFolder: string, logFile: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const appLogReadStream = fs.createReadStream(path.join(logsFolder, logFile), 'utf-8');
|
||||
const appLogHistoryWriteStream = fs.createWriteStream(path.join(logsFolder, `${logFile}.history`), { flags: 'a' });
|
||||
|
||||
appLogReadStream
|
||||
.pipe(appLogHistoryWriteStream)
|
||||
.on('finish', () => {
|
||||
fs.writeFileSync(path.join(logsFolder, logFile), '');
|
||||
resolve(true);
|
||||
})
|
||||
.on('error', (error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export class FileLogger {
|
||||
private winstonLogger;
|
||||
|
||||
private logsFolder;
|
||||
|
||||
constructor(name: string, folder: string, console?: boolean) {
|
||||
this.winstonLogger = createLogger(name, folder, console);
|
||||
this.logsFolder = folder;
|
||||
}
|
||||
|
||||
public flush = async () => {
|
||||
try {
|
||||
if (fs.existsSync(path.join(this.logsFolder, 'app.log'))) {
|
||||
await streamLogToHistory(this.logsFolder, 'app.log');
|
||||
}
|
||||
if (fs.existsSync(path.join(this.logsFolder, 'error.log'))) {
|
||||
await streamLogToHistory(this.logsFolder, 'error.log');
|
||||
}
|
||||
this.winstonLogger.info('Logs flushed');
|
||||
} catch (error) {
|
||||
this.winstonLogger.error('Error flushing logs', error);
|
||||
}
|
||||
};
|
||||
|
||||
public error = (...message: unknown[]) => {
|
||||
this.winstonLogger.error(message.join(' '));
|
||||
};
|
||||
|
||||
public info = (...message: unknown[]) => {
|
||||
this.winstonLogger.info(message.join(' '));
|
||||
};
|
||||
|
||||
public warn = (...message: unknown[]) => {
|
||||
this.winstonLogger.warn(message.join(' '));
|
||||
};
|
||||
|
||||
public debug = (...message: unknown[]) => {
|
||||
this.winstonLogger.debug(message.join(' '));
|
||||
};
|
||||
}
|
1
packages/shared/src/lib/FileLogger/index.ts
Normal file
1
packages/shared/src/lib/FileLogger/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { FileLogger } from './FileLogger';
|
20
packages/shared/src/lib/exec-async/execAsync.tsx
Normal file
20
packages/shared/src/lib/exec-async/execAsync.tsx
Normal 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: '' };
|
||||
}
|
||||
};
|
1
packages/shared/src/lib/exec-async/index.ts
Normal file
1
packages/shared/src/lib/exec-async/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { execAsync } from './execAsync';
|
|
@ -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(),
|
||||
|
@ -43,6 +42,14 @@ export const envSchema = z.object({
|
|||
if (typeof value === 'boolean') return value;
|
||||
return value === 'true';
|
||||
}),
|
||||
guestDashboard: z
|
||||
.string()
|
||||
.or(z.boolean())
|
||||
.optional()
|
||||
.transform((value) => {
|
||||
if (typeof value === 'boolean') return value;
|
||||
return value === 'true';
|
||||
}),
|
||||
seePreReleaseVersions: z
|
||||
.string()
|
||||
.or(z.boolean())
|
||||
|
@ -51,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 })
|
||||
.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());
|
||||
|
|
|
@ -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>;
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
|
@ -34,8 +34,10 @@ export const newLogger = (id: string, logsFolder: string) => {
|
|||
);
|
||||
exceptionHandlers = [new transports.File({ filename: path.join(logsFolder, 'error.log') })];
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
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({
|
||||
|
@ -45,7 +47,7 @@ export const newLogger = (id: string, logsFolder: string) => {
|
|||
colorize(),
|
||||
timestamp(),
|
||||
align(),
|
||||
printf((info) => `${info.timestamp} - ${info.level} > ${info.message}`),
|
||||
printf((info) => `${id}: ${info.timestamp} - ${info.level} > ${info.message}`),
|
||||
),
|
||||
transports: tr,
|
||||
exceptionHandlers,
|
||||
|
|
14
packages/worker/.env.test
Normal file
14
packages/worker/.env.test
Normal 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
|
39
packages/worker/.eslintrc.js
Normal file
39
packages/worker/.eslintrc.js
Normal 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
2
packages/worker/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
dist/
|
||||
coverage/
|
6
packages/worker/.prettierrc.js
Normal file
6
packages/worker/.prettierrc.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
singleQuote: true,
|
||||
semi: true,
|
||||
trailingComma: 'all',
|
||||
printWidth: 200,
|
||||
};
|
67
packages/worker/Dockerfile
Normal file
67
packages/worker/Dockerfile
Normal file
|
@ -0,0 +1,67 @@
|
|||
ARG NODE_VERSION="20.10"
|
||||
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"]
|
||||
|
41
packages/worker/Dockerfile.dev
Normal file
41
packages/worker/Dockerfile.dev
Normal file
|
@ -0,0 +1,41 @@
|
|||
ARG NODE_VERSION="20.10"
|
||||
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"]
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
-- Update app table to add "is_visible_on_guest_dashboard" column
|
||||
ALTER TABLE "app"
|
||||
ADD COLUMN IF NOT EXISTS "is_visible_on_guest_dashboard" boolean DEFAULT FALSE;
|
||||
|
||||
-- Set default value to false
|
||||
UPDATE
|
||||
"app"
|
||||
SET
|
||||
"is_visible_on_guest_dashboard" = FALSE
|
||||
WHERE
|
||||
"is_visible_on_guest_dashboard" IS NULL;
|
||||
|
||||
-- Set is_visible_on_guest_dashboard column to not null constraint
|
||||
ALTER TABLE "app"
|
||||
ALTER COLUMN "is_visible_on_guest_dashboard" SET NOT NULL;
|
|
@ -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
21
packages/worker/build.js
Normal 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: 'node20',
|
||||
bundle: true,
|
||||
color: true,
|
||||
sourcemap: commandArgs.includes('--sourcemap'),
|
||||
};
|
||||
|
||||
await build({ ...options, minify: true });
|
||||
console.log(`Build time: ${Date.now() - start}ms`);
|
||||
}
|
||||
|
||||
bundle();
|
5
packages/worker/nodemon.json
Normal file
5
packages/worker/nodemon.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"watch": ["src"],
|
||||
"exec": "NODE_ENV=development tsx ./src/index.ts",
|
||||
"ext": "js ts"
|
||||
}
|
42
packages/worker/package.json
Normal file
42
packages/worker/package.json
Normal 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"
|
||||
}
|
||||
}
|
2
packages/worker/src/config/constants.ts
Normal file
2
packages/worker/src/config/constants.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export const ROOT_FOLDER = '/app';
|
||||
export const STORAGE_FOLDER = '/storage';
|
1
packages/worker/src/config/index.ts
Normal file
1
packages/worker/src/config/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './constants';
|
94
packages/worker/src/index.ts
Normal file
94
packages/worker/src/index.ts
Normal 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();
|
125
packages/worker/src/lib/docker/docker-helpers.test.ts
Normal file
125
packages/worker/src/lib/docker/docker-helpers.test.ts
Normal 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);
|
||||
});
|
||||
});
|
|
@ -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}`);
|
||||
}
|
62
packages/worker/src/lib/environment/environment.ts
Normal file
62
packages/worker/src/lib/environment/environment.ts
Normal 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);
|
1
packages/worker/src/lib/environment/index.ts
Normal file
1
packages/worker/src/lib/environment/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { getEnv } from './environment';
|
1
packages/worker/src/lib/logger/index.ts
Normal file
1
packages/worker/src/lib/logger/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { logger } from './logger';
|
4
packages/worker/src/lib/logger/logger.ts
Normal file
4
packages/worker/src/lib/logger/logger.ts
Normal 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);
|
1
packages/worker/src/lib/migrations/index.ts
Normal file
1
packages/worker/src/lib/migrations/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { runPostgresMigrations } from './run-migration';
|
|
@ -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();
|
||||
};
|
1
packages/worker/src/lib/system/index.ts
Normal file
1
packages/worker/src/lib/system/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { copySystemFiles, generateSystemEnvFile, ensureFilePermissions, generateTlsCertificates } from './system.helpers';
|
278
packages/worker/src/lib/system/system.helpers.ts
Normal file
278
packages/worker/src/lib/system/system.helpers.ts
Normal 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(() => {});
|
||||
}
|
||||
}
|
||||
};
|
|
@ -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');
|
|
@ -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 });
|
297
packages/worker/src/services/app/app.executors.ts
Normal file
297
packages/worker/src/services/app/app.executors.ts
Normal 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();
|
||||
}
|
||||
};
|
||||
}
|
|
@ -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
|
||||
|
@ -97,15 +96,16 @@ export const generateEnvFile = async (appId: string, config: Record<string, unkn
|
|||
} else {
|
||||
envMap.set('APP_DOMAIN', `${internalIp}:${parsedConfig.data.port}`);
|
||||
envMap.set('APP_HOST', internalIp);
|
||||
envMap.set('APP_PROTOCOL', 'http');
|
||||
}
|
||||
|
||||
// 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));
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -132,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}`);
|
||||
|
@ -178,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);
|
||||
|
@ -189,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(() => {});
|
||||
}
|
||||
};
|
|
@ -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>();
|
||||
|
3
packages/worker/src/services/index.ts
Normal file
3
packages/worker/src/services/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export { AppExecutors } from './app/app.executors';
|
||||
export { RepoExecutors } from './repo/repo.executors';
|
||||
export { SystemExecutors } from './system/system.executors';
|
|
@ -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: '' };
|
27
packages/worker/src/services/repo/repo.helpers.ts
Normal file
27
packages/worker/src/services/repo/repo.helpers.ts
Normal 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] ;
|
||||
};
|
60
packages/worker/src/services/system/system.executors.ts
Normal file
60
packages/worker/src/services/system/system.executors.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
}
|
|
@ -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}`);
|
||||
});
|
||||
};
|
38
packages/worker/tests/apps.factory.ts
Normal file
38
packages/worker/tests/apps.factory.ts
Normal 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;
|
||||
};
|
41
packages/worker/tests/mocks/fs.ts
Normal file
41
packages/worker/tests/mocks/fs.ts
Normal 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()),
|
||||
},
|
||||
};
|
42
packages/worker/tests/vite.setup.ts
Normal file
42
packages/worker/tests/vite.setup.ts
Normal 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 });
|
||||
});
|
55
packages/worker/tsconfig.json
Normal file
55
packages/worker/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
10
packages/worker/vitest.config.ts
Normal file
10
packages/worker/vitest.config.ts
Normal 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'] },
|
||||
},
|
||||
});
|
4071
pnpm-lock.yaml
generated
4071
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
BIN
public/tipi-christmas.png
Normal file
BIN
public/tipi-christmas.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 44 KiB |
|
@ -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
|
||||
|
@ -120,20 +121,28 @@ if ! command -v docker >/dev/null; then
|
|||
install_docker "${OS}"
|
||||
docker_result=$?
|
||||
|
||||
if [[ docker_result -eq 0 ]]; then
|
||||
echo "Docker installed"
|
||||
else
|
||||
if [[ docker_result -ne 0 ]]; then
|
||||
echo "Your system ${OS} is not supported trying with sub_os ${SUB_OS}"
|
||||
install_docker "${SUB_OS}"
|
||||
docker_sub_result=$?
|
||||
|
||||
if [[ docker_sub_result -eq 0 ]]; then
|
||||
echo "Docker installed"
|
||||
else
|
||||
if [[ docker_sub_result -ne 0 ]]; then
|
||||
echo "Your system ${SUB_OS} is not supported please install docker manually"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Make sure user is in docker group
|
||||
if ! groups | grep -q '\bdocker\b'; then
|
||||
echo "Adding user to docker group"
|
||||
sudo usermod -aG docker "$USER"
|
||||
echo "✓ Docker installed. Please re-run the installation script to continue with the installation. (curl -L https://setup.runtipi.io | bash)"
|
||||
fi
|
||||
|
||||
# Reload user groups
|
||||
newgrp docker
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
function check_dependency_and_install() {
|
||||
|
@ -185,18 +194,4 @@ fi
|
|||
curl --location "$URL" -o ./runtipi-cli
|
||||
chmod +x ./runtipi-cli
|
||||
|
||||
# Check if user is in docker group
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
if ! groups | grep -q docker; then
|
||||
sudo usermod -aG docker "$USER"
|
||||
newgrp docker
|
||||
fi
|
||||
fi
|
||||
|
||||
# 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
|
||||
|
||||
./runtipi-cli start
|
||||
|
|
|
@ -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={{
|
||||
|
|
|
@ -36,8 +36,8 @@ export function LoginContainer() {
|
|||
});
|
||||
|
||||
if (totpSessionId) {
|
||||
return <TotpForm loading={verifyTotpMutation.isExecuting} onSubmit={(totpCode) => verifyTotpMutation.execute({ totpCode, totpSessionId })} />;
|
||||
return <TotpForm loading={verifyTotpMutation.status === 'executing'} onSubmit={(totpCode) => verifyTotpMutation.execute({ totpCode, totpSessionId })} />;
|
||||
}
|
||||
|
||||
return <LoginForm loading={loginMutation.isExecuting} onSubmit={({ email, password }) => loginMutation.execute({ username: email, password })} />;
|
||||
return <LoginForm loading={loginMutation.status === 'executing'} onSubmit={({ email, password }) => loginMutation.execute({ username: email, password })} />;
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue