feat: allow specifying custom Docker registry for tests
this allows to utilize private Docker registries for the tests that are pulling images for the database tests. Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-test-utils': patch
|
||||
---
|
||||
|
||||
Allow specifying custom Docker registry for database tests
|
||||
@@ -12,6 +12,26 @@ cd plugins/my-plugin-backend
|
||||
yarn add --dev @backstage/backend-test-utils
|
||||
```
|
||||
|
||||
## Environment variables
|
||||
|
||||
- `BACKSTAGE_TEST_DISABLE_DOCKER`
|
||||
- Setting the value to `1` disables Docker for tests
|
||||
- `CI`
|
||||
- Setting the value to `1` enables long-running tests, including the ones utilizing Docker
|
||||
- `BACKSTAGE_TEST_DOCKER_REGISTRY`
|
||||
- Docker registry mirror address where to pull images for tests, for example `mycompany.docker.io/mirror`
|
||||
- See [documentation](https://node.testcontainers.org/configuration/) for information
|
||||
about authentication (`DOCKER_AUTH_CONFIG`)
|
||||
|
||||
Connection strings for different databases that are used for testing. The value of the
|
||||
string should point to the running instance of the database.
|
||||
|
||||
- `BACKSTAGE_TEST_DATABASE_POSTGRES13_CONNECTION_STRING`
|
||||
- `BACKSTAGE_TEST_DATABASE_POSTGRES12_CONNECTION_STRING`
|
||||
- `BACKSTAGE_TEST_DATABASE_POSTGRES11_CONNECTION_STRING`
|
||||
- `BACKSTAGE_TEST_DATABASE_POSTGRES9_CONNECTION_STRING`
|
||||
- `BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING`
|
||||
|
||||
## Documentation
|
||||
|
||||
- [Backstage Readme](https://github.com/backstage/backstage/blob/master/README.md)
|
||||
|
||||
@@ -25,6 +25,9 @@ import { ServiceRef } from '@backstage/backend-plugin-api';
|
||||
import { TokenManagerService } from '@backstage/backend-plugin-api';
|
||||
import { UrlReaderService } from '@backstage/backend-plugin-api';
|
||||
|
||||
// @public (undocumented)
|
||||
export const getDockerImageForName: (name: string) => string;
|
||||
|
||||
// @public (undocumented)
|
||||
export function isDockerDisabledForTests(): boolean;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
import { DatabaseManager } from '@backstage/backend-common';
|
||||
import { Knex } from 'knex';
|
||||
import { getDockerImageForName } from '../util';
|
||||
|
||||
/**
|
||||
* The possible databases to test against.
|
||||
@@ -48,35 +49,35 @@ export const allDatabases: Record<TestDatabaseId, TestDatabaseProperties> =
|
||||
POSTGRES_13: {
|
||||
name: 'Postgres 13.x',
|
||||
driver: 'pg',
|
||||
dockerImageName: 'postgres:13',
|
||||
dockerImageName: getDockerImageForName('postgres:13'),
|
||||
connectionStringEnvironmentVariableName:
|
||||
'BACKSTAGE_TEST_DATABASE_POSTGRES13_CONNECTION_STRING',
|
||||
},
|
||||
POSTGRES_12: {
|
||||
name: 'Postgres 12.x',
|
||||
driver: 'pg',
|
||||
dockerImageName: 'postgres:12',
|
||||
dockerImageName: getDockerImageForName('postgres:12'),
|
||||
connectionStringEnvironmentVariableName:
|
||||
'BACKSTAGE_TEST_DATABASE_POSTGRES12_CONNECTION_STRING',
|
||||
},
|
||||
POSTGRES_11: {
|
||||
name: 'Postgres 11.x',
|
||||
driver: 'pg',
|
||||
dockerImageName: 'postgres:11',
|
||||
dockerImageName: getDockerImageForName('postgres:11'),
|
||||
connectionStringEnvironmentVariableName:
|
||||
'BACKSTAGE_TEST_DATABASE_POSTGRES11_CONNECTION_STRING',
|
||||
},
|
||||
POSTGRES_9: {
|
||||
name: 'Postgres 9.x',
|
||||
driver: 'pg',
|
||||
dockerImageName: 'postgres:9',
|
||||
dockerImageName: getDockerImageForName('postgres:9'),
|
||||
connectionStringEnvironmentVariableName:
|
||||
'BACKSTAGE_TEST_DATABASE_POSTGRES9_CONNECTION_STRING',
|
||||
},
|
||||
MYSQL_8: {
|
||||
name: 'MySQL 8.x',
|
||||
driver: 'mysql2',
|
||||
dockerImageName: 'mysql:8',
|
||||
dockerImageName: getDockerImageForName('mysql:8'),
|
||||
connectionStringEnvironmentVariableName:
|
||||
'BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING',
|
||||
},
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/** @public */
|
||||
export const getDockerImageForName = (name: string) => {
|
||||
return process.env.BACKSTAGE_TEST_DOCKER_REGISTRY
|
||||
? `${process.env.BACKSTAGE_TEST_DOCKER_REGISTRY}/${name}`
|
||||
: name;
|
||||
};
|
||||
@@ -15,3 +15,4 @@
|
||||
*/
|
||||
|
||||
export { isDockerDisabledForTests } from './isDockerDisabledForTests';
|
||||
export { getDockerImageForName } from './getDockerImageForName';
|
||||
|
||||
Reference in New Issue
Block a user