diff --git a/.github/workflows/test-db.yml b/.github/workflows/test-db.yml deleted file mode 100644 index 515eb64620..0000000000 --- a/.github/workflows/test-db.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: '!Test Databases' - -on: - workflow_dispatch: - pull_request: - branches: ['mysql'] - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [18.x] - - steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: yarn - - run: yarn install - - run: yarn tsc - - run: yarn build:all - - run: yarn test diff --git a/.github/workflows/verify_e2e-linux-mysql.yml b/.github/workflows/verify_e2e-linux-mysql.yml index caf7c2b3ef..3ab6673c8c 100644 --- a/.github/workflows/verify_e2e-linux-mysql.yml +++ b/.github/workflows/verify_e2e-linux-mysql.yml @@ -60,7 +60,7 @@ jobs: - run: yarn backstage-cli repo build - name: run E2E test run: | - yarn e2e-test run + yarn e2e-test run --dbms=mysql env: BACKSTAGE_TEST_DISABLE_DOCKER: 1 BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING: mysql://root:root@localhost:${{ job.services.mysql8.ports[3306] }}/ignored diff --git a/packages/create-app/templates/default-app/app-config.production.mysql.yaml b/packages/create-app/templates/default-app/app-config.production.mysql.yaml deleted file mode 100644 index a2d1c2487d..0000000000 --- a/packages/create-app/templates/default-app/app-config.production.mysql.yaml +++ /dev/null @@ -1,29 +0,0 @@ -app: - # Should be the same as backend.baseUrl when using the `app-backend` plugin. - baseUrl: http://localhost:7007 - -backend: - # Note that the baseUrl should be the URL that the browser and other clients - # should use when communicating with the backend, i.e. it needs to be - # reachable not just from within the backend host, but from all of your - # callers. When its value is "http://localhost:7007", it's strictly private - # and can't be reached by others. - baseUrl: http://localhost:7007 - # The listener can also be expressed as a single : string. In this case we bind to - # all interfaces, the most permissive setting. The right value depends on your specific deployment. - listen: ':7007' - - # config options including ssl: https://github.com/mysqljs/mysql#connection-options - database: - client: mysql2 - connection: - host: ${MYSQL_HOST} - port: ${MYSQL_PORT} - user: ${MYSQL_USER} - password: ${MYSQL_PASSWORD} - -catalog: - # Overrides the default list locations from app-config.yaml as these contain example data. - # See https://backstage.io/docs/features/software-catalog/#adding-components-to-the-catalog for more details - # on how to get entities into the catalog. - locations: [] diff --git a/packages/e2e-test/package.json b/packages/e2e-test/package.json index 50d15c970d..7e6ebdd749 100644 --- a/packages/e2e-test/package.json +++ b/packages/e2e-test/package.json @@ -35,8 +35,8 @@ "cross-fetch": "^3.1.5", "fs-extra": "10.1.0", "handlebars": "^4.7.3", - "pgtools": "^1.0.0", "mysql2": "^2.2.5", + "pgtools": "^1.0.0", "puppeteer": "^17.0.0", "tree-kill": "^1.2.2" }, diff --git a/packages/e2e-test/src/commands/index.ts b/packages/e2e-test/src/commands/index.ts index 95d311427c..c5740a1d6f 100644 --- a/packages/e2e-test/src/commands/index.ts +++ b/packages/e2e-test/src/commands/index.ts @@ -18,5 +18,12 @@ import { Command } from 'commander'; import { run } from './run'; export function registerCommands(program: Command) { - program.command('run').description('Run e2e tests').action(run); + program + .command('run') + .description('Run e2e tests') + .option( + '-db, --dbms', + 'Selected database management system for e2e testing, (eg. mysql, postgres)', + ) + .action(run); } diff --git a/packages/e2e-test/src/commands/run.ts b/packages/e2e-test/src/commands/run.ts index e48665fda5..0ea542f213 100644 --- a/packages/e2e-test/src/commands/run.ts +++ b/packages/e2e-test/src/commands/run.ts @@ -46,7 +46,7 @@ const templatePackagePaths = [ 'packages/create-app/templates/default-app/packages/backend/package.json.hbs', ]; -export async function run() { +export async function run(dbms: string = 'postgres') { const rootDir = await fs.mkdtemp(resolvePath(os.tmpdir(), 'backstage-e2e-')); print(`CLI E2E test root: ${rootDir}\n`); @@ -69,17 +69,15 @@ export async function run() { print('Starting the app'); await testAppServe(pluginId, appDir); - if (Boolean(process.env.POSTGRES_USER) || Boolean(process.env.MYSQL_USER)) { + if ( + Boolean(process.env.POSTGRES_USER) || + Boolean(process.env.BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING) + ) { print('Testing the datbase backend startup'); - await preCleanDatabase(); + await dropClientDatabases(dbms); const appConfig = path.resolve(appDir, 'app-config.yaml'); - let productionConfig = path.resolve(appDir, 'app-config.production.yaml'); - if (Boolean(process.env.MYSQL_HOST)) { - productionConfig = path.resolve( - appDir, - 'app-config.production.mysql.yaml', - ); - } + const productionConfig = path.resolve(appDir, 'app-config.production.yaml'); + await testBackendStart( appDir, '--config', @@ -435,10 +433,10 @@ async function testAppServe(pluginId: string, appDir: string) { } } -/** Drops PG databases */ -async function dropDB(database: string, client: string) { +/** Drops databases */ +async function dropDB(database: string, dbms: string) { try { - if (client === 'postgres') { + if (dbms === 'postgres') { const config = { host: process.env.POSTGRES_HOST ? process.env.POSTGRES_HOST : '', port: process.env.POSTGRES_PORT ? process.env.POSTGRES_PORT : '', @@ -448,7 +446,7 @@ async function dropDB(database: string, client: string) { : '', }; await pgtools.dropdb(config, database); - } else if (client === 'mysql') { + } else if (dbms === 'mysql') { const connectionString = process.env.BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING ?? ''; const connection = await mysql.createConnection(connectionString); @@ -460,18 +458,8 @@ async function dropDB(database: string, client: string) { } /** Clean remnants from prior e2e runs */ -async function preCleanDatabase() { +async function dropClientDatabases(dbms: string) { print('Dropping old DBs'); - if (Boolean(process.env.POSTGRES_HOST)) { - await dropClientDatabases('postgres'); - } - if (Boolean(process.env.BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING)) { - await dropClientDatabases('mysql'); - } - print('Created DBs'); -} - -async function dropClientDatabases(client: string) { await Promise.all( [ 'catalog', @@ -481,8 +469,9 @@ async function dropClientDatabases(client: string) { 'proxy', 'techdocs', 'search', - ].map(name => dropDB(`backstage_plugin_${name}`, client)), + ].map(name => dropDB(`backstage_plugin_${name}`, dbms)), ); + print('Created DBs'); } /** diff --git a/plugins/app-backend/migrations/20211229105307_init.js b/plugins/app-backend/migrations/20211229105307_init.js index 859fc99a14..5f1bfdc30e 100644 --- a/plugins/app-backend/migrations/20211229105307_init.js +++ b/plugins/app-backend/migrations/20211229105307_init.js @@ -25,7 +25,7 @@ exports.up = async function up(knex) { 'A cache of static assets that where previously deployed and may still be lazy-loaded by clients', ); table - .string('path') + .text('path', 'longtext') .primary() .notNullable() .comment('The path of the file'); diff --git a/plugins/app-backend/src/lib/assets/StaticAssetsStore.ts b/plugins/app-backend/src/lib/assets/StaticAssetsStore.ts index c2cfc471fb..9f6ada717d 100644 --- a/plugins/app-backend/src/lib/assets/StaticAssetsStore.ts +++ b/plugins/app-backend/src/lib/assets/StaticAssetsStore.ts @@ -138,20 +138,20 @@ export class StaticAssetsStore implements StaticAssetProvider { */ async trimAssets(options: { maxAgeSeconds: number }) { const { maxAgeSeconds } = options; - let lastModifiedInterval = `now() + interval '${-maxAgeSeconds} seconds'`; + let lastModifiedInterval = this.#db.raw( + `now() + interval '${-maxAgeSeconds} seconds'`, + ); if (this.#db.client.config.client.includes('mysql')) { - lastModifiedInterval = `date_sub(now(), interval ${maxAgeSeconds} second)`; + lastModifiedInterval = this.#db.raw( + `date_sub(now(), interval ${maxAgeSeconds} second)`, + ); } else if (this.#db.client.config.client.includes('sqlite3')) { - lastModifiedInterval = `datetime('now', ?)`; + lastModifiedInterval = this.#db.raw(`datetime('now', ?)`, [ + `-${maxAgeSeconds} seconds`, + ]); } await this.#db('static_assets_cache') - .where( - 'last_modified_at', - '<=', - this.#db.client.config.client.includes('sqlite3') - ? this.#db.raw(lastModifiedInterval, [`-${maxAgeSeconds} seconds`]) - : this.#db.raw(lastModifiedInterval), - ) + .where('last_modified_at', '<=', lastModifiedInterval) .delete(); } } diff --git a/yarn.lock b/yarn.lock index 685ca3b540..cb8197c964 100644 --- a/yarn.lock +++ b/yarn.lock @@ -23670,9 +23670,9 @@ __metadata: cross-fetch: ^3.1.5 fs-extra: 10.1.0 handlebars: ^4.7.3 + mysql2: ^2.2.5 nodemon: ^3.0.1 pgtools: ^1.0.0 - mysql2: ^2.2.5 puppeteer: ^17.0.0 tree-kill: ^1.2.2 ts-node: ^10.0.0