Skip to content

Commit d2829ae

Browse files
committed
(feat): Allow any docker network for HTTPS(remote) install type
Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
1 parent 349d9df commit d2829ae

File tree

2 files changed

+131
-2
lines changed

2 files changed

+131
-2
lines changed

.github/workflows/tests-deploy.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,118 @@ jobs:
295295
path: nextcloud.log
296296
if-no-files-found: warn
297297

298+
nc-docker-dsp-https-bridge:
299+
runs-on: ubuntu-22.04
300+
name: NC In Julius Docker(DSP-HTTPS-BRIDGE) • 🐘8.3
301+
env:
302+
docker-image: ghcr.io/juliusknorr/nextcloud-dev-php83:master
303+
304+
steps:
305+
- name: Set app env
306+
run: echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
307+
308+
- name: Create certificates
309+
run: |
310+
mkdir certs
311+
openssl req -nodes -new -x509 -subj '/CN=host.docker.internal' -sha256 -keyout certs/privkey.pem -out certs/fullchain.pem -days 365000 > /dev/null 2>&1
312+
cat certs/fullchain.pem certs/privkey.pem | tee certs/cert.pem > /dev/null 2>&1
313+
314+
- name: Create containers
315+
run: |
316+
docker network create master_bridge
317+
docker run -v /var/run/docker.sock:/var/run/docker.sock \
318+
-v `pwd`/certs/cert.pem:/certs/cert.pem \
319+
-e NC_HAPROXY_PASSWORD="some_secure_password" \
320+
-e EX_APPS_NET="ipv4@localhost" \
321+
--net host --name nextcloud-appapi-dsp -h nextcloud-appapi-dsp \
322+
--privileged -d ghcr.io/nextcloud/nextcloud-appapi-dsp:latest
323+
docker run --net=master_bridge --name=nextcloud --rm -d ${{ env.docker-image }}
324+
sleep 60s
325+
hostname -I
326+
docker exec nextcloud-appapi-dsp ip addr show | grep inet | awk '{print $2}' | cut -d/ -f1
327+
328+
- name: Install AppAPI
329+
run: |
330+
docker exec -w /var/www/html/apps nextcloud git clone https://github.com/cloud-py-api/${{ env.APP_NAME }}.git
331+
docker exec -w /var/www/html/apps/${{ env.APP_NAME }} nextcloud git fetch origin $GITHUB_REF
332+
docker exec -w /var/www/html/apps/${{ env.APP_NAME }} nextcloud git checkout FETCH_HEAD
333+
docker exec nextcloud sudo -u www-data php occ app:enable app_api
334+
docker cp ./certs/cert.pem nextcloud:/
335+
docker exec nextcloud sudo -u www-data php occ security:certificates:import /cert.pem
336+
docker exec nextcloud sudo -u www-data php occ app_api:daemon:register \
337+
docker_by_port Docker docker-install https host.docker.internal:2375 http://nextcloud.local/index.php \
338+
--net=master_bridge --haproxy_password=some_secure_password
339+
docker exec nextcloud sudo -u www-data php occ app_api:daemon:list
340+
docker exec nextcloud sudo -u www-data php occ app_api:app:register app-skeleton-python docker_by_port \
341+
--info-xml https://raw.githubusercontent.com/nextcloud/app-skeleton-python/main/appinfo/info.xml
342+
docker exec nextcloud sudo -u www-data php occ app_api:app:enable app-skeleton-python
343+
344+
- name: Checking if ExApp container can access HTTPS DSP
345+
run: |
346+
docker exec nc_app_app-skeleton-python apt update
347+
docker exec nc_app_app-skeleton-python apt install curl -y
348+
docker exec nc_app_app-skeleton-python curl https://host.docker.internal:2375
349+
350+
- name: Disable ExApp
351+
run: |
352+
docker exec nextcloud sudo -u www-data php occ app_api:app:disable app-skeleton-python
353+
354+
- name: Copy NC log to host
355+
if: always()
356+
run: docker cp nextcloud:/var/www/html/data/nextcloud.log nextcloud.log
357+
358+
- name: Check logs
359+
run: |
360+
grep -q 'Hello from app-skeleton-python :)' nextcloud.log || error
361+
grep -q 'Bye bye from app-skeleton-python :(' nextcloud.log || error
362+
363+
- name: Save HaProxy logs
364+
if: always()
365+
run: docker logs nextcloud-appapi-dsp > haproxy.log 2>&1
366+
367+
- name: Save container info & logs
368+
if: always()
369+
run: |
370+
docker inspect nc_app_app-skeleton-python | json_pp > container.json
371+
docker logs nc_app_app-skeleton-python > container.log 2>&1
372+
373+
- name: Unregister Skeleton & Daemon
374+
run: |
375+
docker exec nextcloud sudo -u www-data php occ app_api:app:unregister app-skeleton-python
376+
docker exec nextcloud sudo -u www-data php occ app_api:daemon:unregister docker_by_port
377+
378+
- name: Upload HaProxy logs
379+
if: always()
380+
uses: actions/upload-artifact@v4
381+
with:
382+
name: dsp_https_bridge_haproxy.log
383+
path: haproxy.log
384+
if-no-files-found: warn
385+
386+
- name: Upload Container info
387+
if: always()
388+
uses: actions/upload-artifact@v4
389+
with:
390+
name: dsp_https_bridge_container.json
391+
path: container.json
392+
if-no-files-found: warn
393+
394+
- name: Upload Container logs
395+
if: always()
396+
uses: actions/upload-artifact@v4
397+
with:
398+
name: dsp_https_bridge_container.log
399+
path: container.log
400+
if-no-files-found: warn
401+
402+
- name: Upload NC logs
403+
if: always()
404+
uses: actions/upload-artifact@v4
405+
with:
406+
name: dsp_https_bridge_nextcloud.log
407+
path: nextcloud.log
408+
if-no-files-found: warn
409+
298410
nc-docker-dsp-https:
299411
runs-on: ubuntu-22.04
300412
name: NC In Julius Docker(DSP-HTTPS) • 🐘8.3

lib/DeployActions/DockerActions.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function deployExApp(ExApp $exApp, DaemonConfig $daemonConfig, array $par
8282
}
8383
}
8484
$this->exAppService->setAppDeployProgress($exApp, 96);
85-
$result = $this->createContainer($dockerUrl, $imageId, $params['container_params']);
85+
$result = $this->createContainer($dockerUrl, $imageId, $daemonConfig, $params['container_params']);
8686
if (isset($result['error'])) {
8787
return $result['error'];
8888
}
@@ -282,7 +282,7 @@ private function buildExtendedImageName2(array $imageParams, DaemonConfig $daemo
282282
$imageParams['image_name'] . ':' . $imageParams['image_tag'] . '-' . $daemonConfig->getDeployConfig()['computeDevice']['id'];
283283
}
284284

285-
public function createContainer(string $dockerUrl, string $imageId, array $params = []): array {
285+
public function createContainer(string $dockerUrl, string $imageId, DaemonConfig $daemonConfig, array $params = []): array {
286286
$createVolumeResult = $this->createVolume($dockerUrl, $this->buildExAppVolumeName($params['name']));
287287
if (isset($createVolumeResult['error'])) {
288288
return $createVolumeResult;
@@ -301,6 +301,23 @@ public function createContainer(string $dockerUrl, string $imageId, array $param
301301
'Env' => $params['env'],
302302
];
303303

304+
// Exposing the ExApp's primary port when the installation type is remote and the network is not a "host"
305+
if (($params['net'] !== 'host') && ($daemonConfig->getProtocol() === 'https')) {
306+
$exAppMainPort = $params['port'];
307+
$containerParams['ExposedPorts'] = [
308+
sprintf('%d/tcp', $exAppMainPort) => (object) [],
309+
sprintf('%d/udp', $exAppMainPort) => (object) [],
310+
];
311+
$containerParams['HostConfig']['PortBindings'] = [
312+
sprintf('%d/tcp', $exAppMainPort) => [
313+
['HostPort' => (string)$exAppMainPort, 'HostIp' => '127.0.0.1']
314+
],
315+
sprintf('%d/udp', $exAppMainPort) => [
316+
['HostPort' => (string)$exAppMainPort, 'HostIp' => '127.0.0.1']
317+
],
318+
];
319+
}
320+
304321
if (!in_array($params['net'], ['host', 'bridge'])) {
305322
$networkingConfig = [
306323
'EndpointsConfig' => [

0 commit comments

Comments
 (0)