Skip to content

Commit

Permalink
fix: Add more vendored apps
Browse files Browse the repository at this point in the history
Vendored apps are apps which are not provided with the appstore
but released with the server, for the shallow server those apps
have to be cloned.

Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
  • Loading branch information
susnux committed Jul 7, 2023
1 parent 2bec455 commit 0075359
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 68 deletions.
4 changes: 2 additions & 2 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export default defineConfig({
config.baseUrl = `http://${ip}/index.php`
return ip
})
.then(waitOnNextcloud)
.then(() => configureNextcloud())
.then(waitOnNextcloud as (ip: string) => Promise<undefined>) // void !== undefined for Typescript
.then(configureNextcloud)
.then(() => {
return config
})
Expand Down
2 changes: 0 additions & 2 deletions cypress/e2e/sessions.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import { User } from '../../dist'

describe('Login and logout', function() {
before(() => cy.logout())

it('Login and see the default files list', function() {
cy.visit('/apps/files')
cy.url().should('include', '/login')
Expand Down
2 changes: 0 additions & 2 deletions cypress/e2e/users.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import { User } from '../../dist'
import { randHash } from '../utils'

beforeEach(() => cy.logout())

describe('Create user and login', function() {
it('Create random user and log in', function() {
cy.createRandomUser().then(user => {
Expand Down
65 changes: 40 additions & 25 deletions lib/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import Docker from 'dockerode'
import waitOn from 'wait-on'

import type { Stream } from 'node:stream'
import { type Stream, PassThrough } from 'stream'
import { join, resolve, sep } from 'path'
import { existsSync, readFileSync } from 'fs'
import { XMLParser } from 'fast-xml-parser'
Expand All @@ -34,7 +34,15 @@ export const docker = new Docker()
const CONTAINER_NAME = 'nextcloud-cypress-tests'
const SERVER_IMAGE = 'ghcr.io/nextcloud/continuous-integration-shallow-server'

const TEXT_APP_GIT = 'https://github.com/nextcloud/text.git'
const VENDOR_APPS = {
text: 'https://github.com/nextcloud/text.git',
viewer: 'https://github.com/nextcloud/viewer.git',
notifications: 'https://github.com/nextcloud/notifications.git',
activity: 'https://github.com/nextcloud/activity.git',
}

// Store latest server branch used, will be used for vendored apps
let _serverBranch = 'master'

/**
* Start the testing container
Expand All @@ -44,7 +52,7 @@ const TEXT_APP_GIT = 'https://github.com/nextcloud/text.git'
* @return Promise resolving to the IP address of the server
* @throws {Error} If Nextcloud container could not be started
*/
export const startNextcloud = async function(branch = 'master', mountApp: boolean|string = true): Promise<any> {
export const startNextcloud = async function(branch = 'master', mountApp: boolean|string = true): Promise<string> {
let appPath = mountApp === true ? process.cwd() : mountApp
let appId: string|undefined
let appVersion: string|undefined
Expand Down Expand Up @@ -128,8 +136,10 @@ export const startNextcloud = async function(branch = 'master', mountApp: boolea

// Get container's IP
const ip = await getContainerIP(container)

console.log(`├─ Nextcloud container's IP is ${ip} 🌏`)

_serverBranch = branch

return ip
} catch (err) {
console.log('└─ Unable to start the container 🛑')
Expand All @@ -143,8 +153,11 @@ export const startNextcloud = async function(branch = 'master', mountApp: boolea
* Configure Nextcloud
*
* @param {string[]} apps List of default apps to install (default is ['viewer'])
* @param {string|undefined} vendoredBranch The branch used for vendored apps, should match server (defaults to latest branch used for `startNextcloud` or fallsback to `master`)
*/
export const configureNextcloud = async function(apps = ['viewer']) {
export const configureNextcloud = async function(apps = ['viewer'], vendoredBranch?: string) {
vendoredBranch = vendoredBranch || _serverBranch

console.log('\nConfiguring nextcloud...')
const container = docker.getContainer(CONTAINER_NAME)
await runExec(container, ['php', 'occ', '--version'], true)
Expand All @@ -168,17 +181,13 @@ export const configureNextcloud = async function(apps = ['viewer']) {
} else if (app in applist.disabled) {
// built in
await runExec(container, ['php', 'occ', 'app:enable', '--force', app], true)
} else if (app in VENDOR_APPS) {
// some apps are vendored but not within the server package
await runExec(container, ['git', 'clone', '--depth=1', `--branch=${vendoredBranch}`, VENDOR_APPS[app], `apps/${app}`], true)
await runExec(container, ['php', 'occ', 'app:enable', '--force', app], true)
} else {
if (app === 'text') {
// text is vendored but not within the server package
await runExec(container, ['apt', 'update'], false, 'root')
await runExec(container, ['apt-get', '-y', 'install', 'git'], false, 'root')
await runExec(container, ['git', 'clone', '--depth=1', TEXT_APP_GIT, 'apps/text'], true)
await runExec(container, ['php', 'occ', 'app:enable', '--force', app], true)
} else {
// try appstore
await runExec(container, ['php', 'occ', 'app:install', '--force', app], true)
}
// try appstore
await runExec(container, ['php', 'occ', 'app:install', '--force', app], true)
}
}
// await runExec(container, ['php', 'occ', 'app:list'], true)
Expand Down Expand Up @@ -252,22 +261,28 @@ const runExec = async function(
})

return new Promise<string>((resolve, reject) => {
const dataStream = new PassThrough()

exec.start({}, (err, stream) => {
if (stream) {
const data = [] as string[]
stream.setEncoding('utf8')
stream.on('data', (str) => {
data.push(str)
const printable = str.replace(/\p{C}/gu, '').trim()
if (verbose && printable !== '') {
console.log(`├─ ${printable.replace(/\n/gi, '\n├─ ')}`)
}
})
stream.on('end', () => resolve(data.join('')))
// Pass stdout and stderr to dataStream
exec.modem.demuxStream(stream, dataStream, dataStream)
stream.on('end', () => dataStream.end())
} else {
reject(err)
}
})

const data: string[] = []
dataStream.on('data', (chunk) => {
data.push(chunk.toString('utf8'))
const printable = data.at(-1)?.trim()
if (verbose && printable) {
console.log(`├─ ${printable.replace(/\n/gi, '\n├─ ')}`)
}
})
dataStream.on('error', (err) => reject(err))
dataStream.on('end', () => resolve(data.join('')))
})
}

Expand Down
37 changes: 9 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
},
"dependencies": {
"dockerode": "^3.3.5",
"fast-xml-parser": "^4.2.5"
"fast-xml-parser": "^4.2.5",
"wait-on": "^7.0.1"
},
"devDependencies": {
"@cypress/code-coverage": "^3.10.8",
Expand All @@ -93,7 +94,6 @@
"tslib": "^2.5.3",
"typedoc": "^0.24.8",
"typescript": "^5.1.3",
"vue": "^2.7.14",
"wait-on": "^7.0.1"
"vue": "^2.7.14"
}
}
7 changes: 1 addition & 6 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import typescript from '@rollup/plugin-typescript'
import { readFile } from 'fs/promises'

const packageJSON = JSON.parse(
await readFile(
new URL('./package.json', import.meta.url)
)
)
import packageJSON from './package.json' assert { type: 'json' }

const external = [
...Object.keys(packageJSON.dependencies),
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"include": ["./lib/**/*.ts"],
"compilerOptions": {
"types": ["cypress", "node"],
"lib": ["ES2015", "DOM"],
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
// ES2015 is the latest version supported by cypress (besides CommonJS)
Expand Down

0 comments on commit 0075359

Please sign in to comment.