@adpt/cloud
Version:
AdaptJS cloud component library
60 lines • 2.32 kB
JavaScript
;
/*
* Copyright 2019 Unbounded Systems, LLC
*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = tslib_1.__importStar(require("@adpt/core"));
const fs = tslib_1.__importStar(require("fs-extra"));
const docker_1 = require("../docker");
/**
* Creates a throw-away {@link https://www.postgresql.org | Postgres} database with preloaded data.
*
* @remarks
* Implements {@link docker.DockerImageInstance}.
*
* See {@link postgres.PreloadedPostgresImageProps}
*
* @public
*/
function PreloadedPostgresImage(props) {
const [imgProps, setImgProps] = core_1.useState(undefined);
setImgProps(async () => {
const rawMockData = await fs.readFile(props.mockDataPath);
const prefix = `CREATE DATABASE ${props.mockDbName};\n\\c ${props.mockDbName}\n`;
const mockData = Buffer.concat([Buffer.from(prefix), rawMockData]);
return {
dockerfile: `
FROM postgres:11
COPY --from=files mockdata.sql /docker-entrypoint-initdb.d/mockdata.sql
`,
options: {
imageName: "preloaded-postgres",
uniqueTag: true
},
files: [{
path: "mockdata.sql",
contents: mockData
}]
};
});
const img = core_1.handle();
core_1.useMethodFrom(img, "image");
core_1.useMethodFrom(img, "latestImage");
core_1.useMethodFrom(img, "pushTo");
return imgProps ? core_1.default.createElement(docker_1.LocalDockerImage, Object.assign({ handle: img }, imgProps)) : null;
}
exports.PreloadedPostgresImage = PreloadedPostgresImage;
//# sourceMappingURL=PreloadedPostgresImage.js.map