syncloud / platform

Run popular services on your device with one click
https://syncloud.org
GNU General Public License v3.0
392 stars 40 forks source link

[App request] Grocy #648

Closed zifredder closed 1 year ago

zifredder commented 2 years ago

Would it be possible to include grocy as an app? It already exists as an add-on for home assistant (https://grocy.info/addons), but Syncloud's home assistant instance is of type core, which does not allow installing add-ons (or did I miss something?).

I would love to contribute something to this task, but I don't have the slightest clue where to start. I know most words in the app porting guide, however unfortunately I cannot make sense of the sentences because I have no idea how a server even works.

grocy is technically a pretty simple PHP application

and

Any Syncloud app can be used as an example for building a new one.

indicate to me that this is probably doable, but unfortunately this is where it ends ...

In any case, thank you so much for making Syncloud!

cyberb commented 2 years ago

Hi, sure I can help. I have created an empty repo: https://github.com/syncloud/grocy I can give you permissions to push to it also add it tou our build server. First of all I would copy the whole nextcloud into it and start removing nextcloud specific things.

  1. change names everywhere.
  2. try to build locally a package
zifredder commented 1 year ago

Thanks for adding me to the repository! And sorry for the delay. It took me quite some time to build up the motivation to dive into this task and then find the time to do the dive ... right now, after about 12 hours of diving, I am still completely lost. There are too many layers, too many components and concepts that are new to me: Nginx, snap, php, Drone CI, Syncloud itself, ... Understanding them separately is OK, but figuring out which part of each technology is integrated with which parts of the other technologies is pretty hard -- for me, at least, having no experience in this field at all. What I think I understood:

  1. The build pipeline for an application is defined in .drone.jsonnet.
  2. In the build-pipeline, the necessary files (the app itself and dependencies) need to be downloaded and organized in a way that the files can be packaged as a .snap file.
  3. The .snap can then be installed as an application inside Syncloud and can be accessed via [app].[user].syncloud.it

... And that's basically it. I can't figure out the details of packaging the app as a .snap.

According to grocy/how-to-install, we need to download a release and unpack it, so this is one thing that the snap package needs to contain. The download is done in /download.sh, which would put the application files into /build/snap. I am puzzled as to what is supposed to happen in /build.sh: Does it just copy all other snap-relevant files into the build directory? /package.sh seems to do the packaging, producing the snap file.

Apropos snap-relevant files:

Grocy can also be run using Docker. Would this make it easier? I've seen that e. g. Python is built via a Docker image, so this should work for Grocy as well, shouldn't it? But again, I can't figure out how to plug a Docker image into a snap package ...

I don't know how to continue. Do any of you Syncloud-people have time to help? Should I ask the Grocy community?

Regards :v:

cyberb commented 1 year ago

download.sh is usually for downloading stage (whatever we need from outside world) build.sh depending the language used compile or some transformation needed to downloaded files package.sh puts last bits into build/snap like bin/config... and is mostly stays as is in all the repos as it creates a snap of build/snap

you are right about docker we are now taking most of the tools and sometimes even the app itself from their docker containers, the only requirement is it should be available for 3 architectures (amd64, arm64 and arm/v7) Which is not the case for https://hub.docker.com/u/grocy (not even sure which one to use (grocy/frontend/backend) probably all). But is the case for https://hub.docker.com/r/linuxserver/grocy/tags

Again depending on a language it may save or add time. PHP is a dynamic language so it does not require a compilation so you are not really saving anything by getting their docker images. Docker probably contains PHP itself which we usually take directly from PHP docker containers provided by php themselves (as you can see in our Nextcloud app https://github.com/syncloud/nextcloud/tree/master/php)

Then PHP is usually served by a tool called FPM which is part of PHP and we use it as a service: https://github.com/syncloud/nextcloud/blob/master/bin/service.php-fpm.sh

FPM and other app/tools configs are located in /config dir and copied to a writable dir during the install as system may need to modify them on domain change event for example: https://github.com/syncloud/nextcloud/blob/master/hooks/installer.py#L68

Nginx is actually serving all the requests and delegating php parsing to FPM: https://github.com/syncloud/nextcloud/blob/master/config/nginx.conf#L21

cyberb commented 1 year ago

The good thing in all this as I am trying to maintain some level of functional and UI tests which are easy to copy from app to app (https://github.com/syncloud/nextcloud/tree/master/integration)

That means all you really need to do is to copy Nextcloud contents remove/rename all occurrences of nextcloud to grocy make sure this test is there (https://github.com/syncloud/nextcloud/blob/master/integration/verify.py#L72) and push it

Then build server will actually drive you by giving many error messages, when you fix them all with my help we can move to adding a UI test with makes sure user can login and do something https://github.com/syncloud/nextcloud/blob/master/integration/test-ui.py

zifredder commented 1 year ago

Thanks! I'm trying around right now ...

That means all you really need to do is to copy Nextcloud contents remove/rename all occurrences of nextcloud to grocy

Did this while deleting stuff that I am confident is Nextcloud-specific, such as occ and nextcloud.cron-related things. I hope I didn't remove anything important. :shrug:

Should I fork and open a PR or do you give me permission to push?

cyberb commented 1 year ago

No worries we can always add it back. You should be able to push it, first version we can do on master, later we can do PRs.

zifredder commented 1 year ago

Still can't push. :thinking:

$ git push
ERROR: Permission to syncloud/grocy.git denied to zifredder.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

$ git remote -v
origin  git@github.com:syncloud/grocy.git (fetch)
origin  git@github.com:syncloud/grocy.git (push)

$ git pull
Already up to date.

$ git status
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
cyberb commented 1 year ago

Try now

zifredder commented 1 year ago

Worked. :heavy_check_mark: However, I'm having problems getting drone to work. I have 0 experience with drone and very limited knowledge of build pipelines.

$ drone --version
2023/01/10 19:51:46 proto: duplicate proto type registered: PluginSpec
2023/01/10 19:51:46 proto: duplicate proto type registered: PluginPrivilege
drone version 1.6.2

$ drone jsonnet --stream
2023/01/10 19:32:24 proto: duplicate proto type registered: PluginSpec
2023/01/10 19:32:24 proto: duplicate proto type registered: PluginPrivilege

$ head .drone.yml 
---
{
   "kind": "pipeline",
   "name": "amd64",
   "platform": {
      "arch": "amd64",
      "os": "linux"
   },
   "services": [
      {

So far so good? However, nothing happens when I try to build locally:

$ sudo drone exec --pipeline=amd64 --trusted
2023/01/10 19:56:15 proto: duplicate proto type registered: PluginSpec
2023/01/10 19:56:15 proto: duplicate proto type registered: PluginPrivilege

There's nothing happening. Do I have to have all the tools installed locally?

My drone installation seems to have some issues ... according to documentation the following should work.

$ cat .test_drone.yml 
kind: pipeline
type: docker
name: default

steps:
- name: test
  image: alpine
  commands:
  - echo hello
  - echo world

$ drone exec .test_drone.yml 
2023/01/10 20:19:49 proto: duplicate proto type registered: PluginSpec
2023/01/10 20:19:49 proto: duplicate proto type registered: PluginPrivilege
No stage specified, assuming 'default'

But there's just nothing happening. Any thoughts on this? I can't find anything helpful about that proto message.

cyberb commented 1 year ago

Just cloned the repo and did this:

cd grocy
../drone jsonnet --stream
sudo ../drone exec --pipeline=amd64 --trusted 

It started to build.

Is this drome a command line tool from https://docs.drone.io/cli/install

What version is it drone --help | head

cyberb commented 1 year ago

Ok tried downloading myself, new version 1.6.4 produces this error and does nothing, let me google

cyberb commented 1 year ago

Ok, it actually works, this message is just a warning. I guess if you do not see other logs it may be downloading docker image to rung the step on, how long did you wait?

Another thing I have enable this repo on our build server if you oush something it will build: http://ci.syncloud.org:8080/syncloud/grocy

cyberb commented 1 year ago

Hey, did some cleanup, added config with ldap. Here is the PR if you want to see the difference and merg it: https://github.com/syncloud/grocy/pull/1/files

zifredder commented 1 year ago

Wow, you changed quite a bit! Thanks! :star_struck: It is already working, isn't it? The stable build is currently running; will it automatically be available in the snap store as soon as the build is finished, or should I manually download and install the snap package and test it?

cyberb commented 1 year ago

Yeah it will be available semi automatically I will need push a promote button. I will let you know

cyberb commented 1 year ago

Ok, released, check the app store. Open new issue for any new problem.