Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy logic adjustments. Refactoring. Manual install #13

Merged
merged 18 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 98 additions & 12 deletions .github/workflows/tests-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ jobs:
run: |
php -S 127.0.0.1:8080 &
./occ app_ecosystem_v2:daemon:register docker_local_sock Docker docker-install unix-socket /var/run/docker.sock http://127.0.0.1:8080/index.php
./occ app_ecosystem_v2:app:register \
"$(./occ app_ecosystem_v2:app:deploy app_python_skeleton docker_local_sock --info-xml https://raw.githubusercontent.com/cloud-py-api/py_app_v2-skeleton/main/appinfo/info.xml)"
./occ app_ecosystem_v2:app:deploy app_python_skeleton docker_local_sock \
--info-xml https://raw.githubusercontent.com/cloud-py-api/py_app_v2-skeleton/main/appinfo/info.xml
./occ app_ecosystem_v2:app:register app_python_skeleton docker_local_sock
./occ app_ecosystem_v2:app:enable app_python_skeleton
./occ app_ecosystem_v2:app:disable app_python_skeleton
./occ app_ecosystem_v2:app:unregister app_python_skeleton --silent
./occ app_ecosystem_v2:daemon:unregister docker_local_sock

- name: Check logs
run: |
Expand Down Expand Up @@ -158,10 +161,13 @@ jobs:
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:daemon:register \
docker_local_sock Docker docker-install unix-socket /var/run/docker.sock http://nextcloud/index.php \
--net=master_bridge
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:register \
"$(docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:deploy app_python_skeleton docker_local_sock --info-xml https://raw.githubusercontent.com/cloud-py-api/py_app_v2-skeleton/main/appinfo/info.xml)"
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:deploy app_python_skeleton docker_local_sock \
--info-xml https://raw.githubusercontent.com/cloud-py-api/py_app_v2-skeleton/main/appinfo/info.xml
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:register app_python_skeleton docker_local_sock
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:enable app_python_skeleton
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:disable app_python_skeleton
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:unregister app_python_skeleton --silent
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:daemon:unregister docker_local_sock

- name: Copy NC log to host
run: docker cp nextcloud:/var/www/html/data/nextcloud.log nextcloud.log
Expand Down Expand Up @@ -215,11 +221,11 @@ jobs:
run: |
docker network create master_bridge
docker run --net master_bridge --name nextcloud --rm -d ${{ env.docker-image }}
git clone https:/kekru/docker-remote-api-tls.git
cd docker-remote-api-tls
sed -i "s/abc.127.0.0.1.nip.io/host.docker.internal/g" docker-compose.yml
docker-compose up -d
sleep 120s
docker pull kekru/docker-remote-api-tls:master
docker run -d -p 8443:443 -v /var/run/docker.sock:/var/run/docker.sock:ro \
--env CREATE_CERTS_WITH_PW=supersecret --env CERT_HOSTNAME=host.docker.internal \
-v `pwd`/certs:/data/certs kekru/docker-remote-api-tls:master
sleep 25s

- name: Install AppEcosystemV2
run: |
Expand All @@ -228,15 +234,18 @@ jobs:
docker exec -w /var/www/html/apps/${{ env.APP_NAME }} nextcloud git checkout FETCH_HEAD
docker exec nextcloud patch -p 1 -i apps/${{ env.APP_NAME }}/base_php.patch
docker exec nextcloud sudo -u www-data php occ app:enable app_ecosystem_v2
docker cp docker-remote-api-tls/certs/client/ nextcloud:/
docker cp ./certs/client/ nextcloud:/
docker exec nextcloud sudo -u www-data php occ security:certificates:import /client/ca.pem
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:daemon:register \
docker_by_port Docker docker-install https host.docker.internal:8443 http://nextcloud/index.php \
--net=master_bridge --ssl_cert /client/cert.pem --ssl_key /client/key.pem
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:register \
"$(docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:deploy app_python_skeleton docker_by_port --info-xml https://raw.githubusercontent.com/cloud-py-api/py_app_v2-skeleton/main/appinfo/info.xml)"
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:deploy app_python_skeleton docker_by_port \
--info-xml https://raw.githubusercontent.com/cloud-py-api/py_app_v2-skeleton/main/appinfo/info.xml
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:register app_python_skeleton docker_by_port
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:enable app_python_skeleton
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:disable app_python_skeleton
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:unregister app_python_skeleton --silent
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:daemon:unregister docker_by_port

- name: Copy NC log to host
run: docker cp nextcloud:/var/www/html/data/nextcloud.log nextcloud.log
Expand Down Expand Up @@ -275,3 +284,80 @@ jobs:
name: nc_docker_app_docker_by_port_nextcloud.log
path: nextcloud.log
if-no-files-found: warn

nc-docker-app-host-by-hostname:
runs-on: ubuntu-22.04
name: NC In Julius Docker(APP by hostname) • 🐘8.1
env:
docker-image: ghcr.io/juliushaertl/nextcloud-dev-php81:latest

steps:
- name: Set app env
run: echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV

- name: Create containers
run: |
docker run --net=bridge --name=nextcloud -p 8080:80 --rm -d ${{ env.docker-image }}
docker pull kekru/docker-remote-api-tls:master
docker run -d -p 8443:443 -v /var/run/docker.sock:/var/run/docker.sock:ro \
--env CREATE_CERTS_WITH_PW=supersecret --env CERT_HOSTNAME=host.docker.internal \
-v `pwd`/certs:/data/certs kekru/docker-remote-api-tls:master
sleep 25s

- name: Install AppEcosystemV2
run: |
docker exec -w /var/www/html/apps nextcloud git clone https:/cloud-py-api/${{ env.APP_NAME }}.git
docker exec -w /var/www/html/apps/${{ env.APP_NAME }} nextcloud git fetch origin $GITHUB_REF
docker exec -w /var/www/html/apps/${{ env.APP_NAME }} nextcloud git checkout FETCH_HEAD
docker exec nextcloud patch -p 1 -i apps/${{ env.APP_NAME }}/base_php.patch
docker exec nextcloud sudo -u www-data php occ app:enable app_ecosystem_v2
docker cp ./certs/client/ nextcloud:/
docker exec nextcloud sudo -u www-data php occ security:certificates:import /client/ca.pem
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:daemon:register \
docker_by_port Docker docker-install https host.docker.internal:8443 http://localhost:8080/index.php \
--net=host --hostname=host.docker.internal --ssl_cert /client/cert.pem --ssl_key /client/key.pem
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:deploy app_python_skeleton docker_by_port \
--info-xml https://raw.githubusercontent.com/cloud-py-api/py_app_v2-skeleton/main/appinfo/info.xml
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:register app_python_skeleton docker_by_port
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:enable app_python_skeleton
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:disable app_python_skeleton
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:app:unregister app_python_skeleton --silent
docker exec nextcloud sudo -u www-data php occ app_ecosystem_v2:daemon:unregister docker_by_port

- name: Copy NC log to host
run: docker cp nextcloud:/var/www/html/data/nextcloud.log nextcloud.log

- name: Check logs
run: |
grep -q 'Hello from app_python_skeleton :)' nextcloud.log || error
grep -q 'Bye bye from app_python_skeleton :(' nextcloud.log || error

- name: Save container ingo & logs
if: always()
run: |
docker inspect app_python_skeleton | json_pp > container.json
docker logs app_python_skeleton > container.log 2>&1

- name: Upload Container info
if: always()
uses: actions/upload-artifact@v3
with:
name: nc_docker_app_host_by_hostname_container.json
path: container.json
if-no-files-found: warn

- name: Upload Container logs
if: always()
uses: actions/upload-artifact@v3
with:
name: nc_docker_app_host_by_hostname_container.log
path: container.log
if-no-files-found: warn

- name: Upload NC logs
if: always()
uses: actions/upload-artifact@v3
with:
name: nc_docker_app_host_by_hostname_nextcloud.log
path: nextcloud.log
if-no-files-found: warn
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- server-version: "master"
php-version: "8.2"
env:
NEXTCLOUD_URL: "http://localhost:8080/index.php"
NEXTCLOUD_URL: "http://localhost:8080/"
APP_ID: "nc_py_api"
APP_PORT: 9009
APP_VERSION: "1.0.0"
Expand Down Expand Up @@ -116,10 +116,10 @@ jobs:
echo $! > /tmp/_install.pid
cd ..
sleep 5s
php occ app_ecosystem_v2:daemon:register simulate_docker Docker docker-install unix-socket 0 0
php occ app_ecosystem_v2:app:register \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"simulate_docker\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"port\":$APP_PORT,\"system_app\":1}" \
-e --force-scopes
php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0
php occ app_ecosystem_v2:app:register nc_py_api manual_install --json-info \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
-e --force-scopes
kill -15 $(cat /tmp/_install.pid)
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null

Expand Down
29 changes: 13 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ help:
@echo " dock-port26 create docker daemon for Nextcloud 26 (host.docker.internal:8443)"
@echo " "
@echo " "
@echo " example-deploy pull Example App to docker"
@echo " example28 register Example App to Nextcloud 28"
@echo " example27 register Example App to Nextcloud 27"
@echo " example26 register Example App to Nextcloud 26"
@echo " example-deploy deploy Example App to docker"
@echo " example28 register & enable Example App in Nextcloud 28"
@echo " example27 register & enable Example App in Nextcloud 27"
@echo " example26 register & enable Example App in Nextcloud 26"

.PHONY: dock-sock
dock-sock:
Expand Down Expand Up @@ -61,23 +61,22 @@ dock-sock26:
.PHONY: dock2port
dock2port:
@echo "deploying kekru/docker-remote-api-tls..."
docker pull kekru/docker-remote-api-tls:master
docker run --name dock_api2port -d -p 6443:443 -v /var/run/docker.sock:/var/run/docker.sock:ro \
--env CREATE_CERTS_WITH_PW=supersecret --env CERT_HOSTNAME=host.docker.internal \
-v ./certs:/data/certs kekru/docker-remote-api-tls:master
-v `pwd`/certs:/data/certs kekru/docker-remote-api-tls:master
@echo "waiting 20 seconds to finish generating certificates..."
sleep 20

.PHONE: dock-certs
dock-certs:
@echo "copying certs to Nextcloud Master"
docker cp certs/client/ master-nextcloud-1:/ || echo "Failed copying certs to Nextcloud 'master'"
docker cp ./certs/client/ master-nextcloud-1:/ || echo "Failed copying certs to Nextcloud 'master'"
docker exec master-nextcloud-1 sudo -u www-data php occ security:certificates:import /client/ca.pem || true
@echo "copying certs to Nextcloud 27"
docker cp certs/client/ master-stable27-1:/ || echo "Failed copying certs to Nextcloud 27"
docker cp ./certs/client/ master-stable27-1:/ || echo "Failed copying certs to Nextcloud 27"
docker exec master-stable27-1 sudo -u www-data php occ security:certificates:import /client/ca.pem || true
@echo "copying certs to Nextcloud 26"
docker cp certs/client/ master-stable26-1:/ || echo "Failed copying certs to Nextcloud 26"
docker cp ./certs/client/ master-stable26-1:/ || echo "Failed copying certs to Nextcloud 26"
docker exec master-stable26-1 sudo -u www-data php occ security:certificates:import /client/ca.pem || true

.PHONY: dock-port
Expand Down Expand Up @@ -110,25 +109,23 @@ dock-port26:

.PHONY: example-deploy
example-deploy:
$(MAKE) example28 example27 example26
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:deploy app_python_skeleton docker_dev \
--info-xml https://raw.githubusercontent.com/cloud-py-api/py_app_v2-skeleton/main/appinfo/info.xml

.PHONY: example28
example28:
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:unregister app_python_skeleton --silent || true
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:register \
"`docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:deploy app_python_skeleton docker_dev --info-xml https://raw.githubusercontent.com/cloud-py-api/py_app_v2-skeleton/main/appinfo/info.xml`"
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:register app_python_skeleton docker_dev
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:enable app_python_skeleton

.PHONY: example27
example27:
docker exec master-stable27-1 sudo -u www-data php occ app_ecosystem_v2:app:unregister app_python_skeleton --silent || true
docker exec master-stable27-1 sudo -u www-data php occ app_ecosystem_v2:app:register \
"`docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:deploy app_python_skeleton docker_dev --info-xml https://raw.githubusercontent.com/cloud-py-api/py_app_v2-skeleton/main/appinfo/info.xml`"
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:register app_python_skeleton docker_dev
docker exec master-stable27-1 sudo -u www-data php occ app_ecosystem_v2:app:enable app_python_skeleton

.PHONY: example26
example26:
docker exec master-stable26-1 sudo -u www-data php occ app_ecosystem_v2:app:unregister app_python_skeleton --silent || true
docker exec master-stable26-1 sudo -u www-data php occ app_ecosystem_v2:app:register \
"`docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:deploy app_python_skeleton docker_dev --info-xml https://raw.githubusercontent.com/cloud-py-api/py_app_v2-skeleton/main/appinfo/info.xml`"
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:register app_python_skeleton docker_dev
docker exec master-stable26-1 sudo -u www-data php occ app_ecosystem_v2:app:enable app_python_skeleton
2 changes: 1 addition & 1 deletion docs/deploy.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AppEcosystemV2 - Deployment process

> Draft
> Outdated: Kept for reference, new version in [docs](https://cloud-py-api.github.io/app_ecosystem_v2/)


## Overview
Expand Down
30 changes: 18 additions & 12 deletions docs/deploy/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,16 @@ Example of deploy result JSON output:
"system_app": true
}

This JSON output is used in ExApp registration step.
This JSON structure is used in ExApp registration step for development.


Manual install for development
******************************

For development purposes, you can install ExApp manually.
There is a `manual-install` Deploy config type, which can be used in case of development.
For ExApp registration with it you need to provide JSON file with structure described before
using **app_ecosystem_v2:app:register** `--json-info` option.

Deploy env variables
********************
Expand All @@ -147,13 +156,16 @@ The following env variables are required and built automatically:
* `AE_VERSION` - AppEcosystemV2 version
* `APP_SECRET` - generated shared secret used for AppEcosystemV2 authentication
* `APP_ID` - ExApp appid
* `APP_DISPLAY_NAME` - ExApp display name
* `APP_VERSION` - ExApp version
* `APP_PROTOCOL` - protocol ExApp is listening on (http|https)
* `APP_HOST` - host ExApp is listening on
* `APP_PORT` - port ExApp is listening on (randomly selected by AppEcosystemV2)
* `IS_SYSTEM_APP` - ExApp system app flag (true|false)
* `NEXTCLOUD_URL` - Nextcloud URL to connect to

.. note::
additional envs can be passed using multiple `--env ENV_NAME=ENV_VAL` options)
Additional envs can be passed using multiple `--env ENV_NAME=ENV_VAL` options

Docker daemon remote
********************
Expand All @@ -176,26 +188,20 @@ This can be done by `occ` CLI command **app_ecosystem_v2:app:register**:

.. code-block:: bash

app_ecosystem_v2:app:register <deploy-json-output> [-e|--enabled] [--force-scopes] [--]
app_ecosystem_v2:app:register <appid> <daemon-config-name> [-e|--enabled] [--force-scopes] [--]

Arguments
*********

* `deploy-json-output` - `[required]` JSON output from deploy step
* `appid` - `[required]` unique name of the ExApp (e.g. `app_python_skeleton`, must be the same as in deployed container)
* `daemon-config-name` - `[required]` unique name of the daemon (e.g. `docker_local_sock`)

Options
*******

* `-e|--enabled` - `[optional]` enable ExApp after registration
* `--force-scopes` - `[optional]` force scopes approval


This step can be combined with deployment step into one command:

.. code-block:: bash

sudo -u www-data php occ app_ecosystem_v2:app:register "$(sudo -u www-data php occ app_ecosystem_v2:app:deploy app_python_skeleton docker_local_sock --info-xml https://raw.githubusercontent.com/cloud-py-api/py_app_v2-skeleton/main/appinfo/info.xml)" --enabled --force-scopes

* `--json-info JSON-INFO` - `[required]` path to JSON file with deploy result (url or local absolute path)

ExApp info.xml schema
---------------------
Expand Down
1 change: 1 addition & 0 deletions docs/development/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ This section will contain all the information required to develop the project.
Requirements
------------


4 changes: 2 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
use OCA\AppEcosystemV2\DavPlugin;
use OCA\AppEcosystemV2\Listener\LoadFilesPluginListener;
use OCA\AppEcosystemV2\Listener\SabrePluginAuthInitListener;
use OCA\AppEcosystemV2\Middleware\AEAuthMiddleware;
use OCA\AppEcosystemV2\Middleware\AppEcosystemAuthMiddleware;
use OCA\DAV\Events\SabrePluginAuthInitEvent;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
Expand All @@ -67,7 +67,7 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadFilesPluginListener::class);
$context->registerCapability(Capabilities::class);
$context->registerCapability(PublicCapabilities::class);
$context->registerMiddleware(AEAuthMiddleware::class);
$context->registerMiddleware(AppEcosystemAuthMiddleware::class);
$context->registerEventListener(SabrePluginAuthInitEvent::class, SabrePluginAuthInitListener::class);
}

Expand Down
Loading