Compare commits
No commits in common. "108a14e51d00d903b8e17d05daf9f6e64f63a0cc" and "f944e31ce05cf24b3b6292eb15c04690d36b4128" have entirely different histories.
108a14e51d
...
f944e31ce0
@ -1,19 +0,0 @@
|
|||||||
name: initialize database
|
|
||||||
description: initialize database by using database of test environment
|
|
||||||
author: BinKrassDuFass
|
|
||||||
|
|
||||||
inputs:
|
|
||||||
MONGODB_SERVICE_NAME:
|
|
||||||
description: 'Name of the MongoDB service'
|
|
||||||
required: true
|
|
||||||
default: 'mongo'
|
|
||||||
|
|
||||||
runs:
|
|
||||||
using: composite
|
|
||||||
steps:
|
|
||||||
- name: Install MongoDB tools
|
|
||||||
run: sudo apt-get install -y mongodb-database-tools
|
|
||||||
|
|
||||||
- name: Restore MongoDB Data
|
|
||||||
run: mongorestore --uri "mongodb://${{inputs.MONGODB_SERVICE_NAME}}:27017" /.gitea/
|
|
||||||
|
|
@ -1,116 +0,0 @@
|
|||||||
const axios = require("axios")
|
|
||||||
const { MongoClient } = require("mongodb")
|
|
||||||
const fs = require("fs")
|
|
||||||
const util = require("util")
|
|
||||||
|
|
||||||
// Function to log objects in a detailed manner
|
|
||||||
function logObj(o) {
|
|
||||||
console.log(util.inspect(o, false, null, true))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to preload the database with collections
|
|
||||||
async function preloadDatabase(db, collections) {
|
|
||||||
for (const { name, file } of collections) {
|
|
||||||
const content = fs.readFileSync(file, "utf8")
|
|
||||||
const data = JSON.parse(content)
|
|
||||||
|
|
||||||
const collection = db.collection(name)
|
|
||||||
await collection.insertMany(data)
|
|
||||||
|
|
||||||
const insertedData = await collection.find({}).toArray()
|
|
||||||
if (insertedData.length !== data.length) {
|
|
||||||
console.error(
|
|
||||||
`Mismatch in collection ${name}: expected ${data.length} documents, found ${insertedData.length}`
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
console.log(`Successfully verified ${insertedData.length} documents in ${name}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function initializeDatabase(config) {
|
|
||||||
try {
|
|
||||||
const dbClient = new MongoClient(config.mongodbUri)
|
|
||||||
await dbClient.connect()
|
|
||||||
let db = dbClient.db(config.tibiDbPrefix)
|
|
||||||
await db.collection("project").deleteMany({ namespace: config.projectApiNamespace })
|
|
||||||
|
|
||||||
const dbName = config.tibiDbPrefix + "_" + config.projectApiNamespace
|
|
||||||
db = dbClient.db(dbName)
|
|
||||||
await db.dropDatabase()
|
|
||||||
|
|
||||||
// Login to Tibi API
|
|
||||||
const loginResponse = await axios.post(config.tibiApiUrl + "/login", {
|
|
||||||
username: config.tibiUsername,
|
|
||||||
password: config.tibiPassword,
|
|
||||||
})
|
|
||||||
const tibiToken = loginResponse.data.token
|
|
||||||
|
|
||||||
// Create project
|
|
||||||
let project
|
|
||||||
try {
|
|
||||||
const projectResponse = await axios.post(
|
|
||||||
config.tibiApiUrl + "/project",
|
|
||||||
{
|
|
||||||
configFile: config.projectApiConfig,
|
|
||||||
name: config.projectApiNamespace,
|
|
||||||
namespace: config.projectApiNamespace,
|
|
||||||
description: config.projectApiNamespace,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
"X-Auth-Token": tibiToken,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
project = projectResponse.data
|
|
||||||
} catch (e) {
|
|
||||||
logObj(e)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if project is online
|
|
||||||
const projectStatus = await axios.get(config.tibiApiUrl + "/project/" + project.id, {
|
|
||||||
headers: {
|
|
||||||
"X-Auth-Token": tibiToken,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if (!projectStatus.data.api.isOnline) {
|
|
||||||
throw new Error(`Project ${config.projectApiNamespace} is not online.`)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Define collections to preload into the database
|
|
||||||
const collections = [
|
|
||||||
// Define your collections here as per your Cypress plugin logic
|
|
||||||
// { name: "collectionName", file: "path/to/file.json" },
|
|
||||||
// ... other collections
|
|
||||||
]
|
|
||||||
await preloadDatabase(db, collections)
|
|
||||||
|
|
||||||
await dbClient.close()
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error initializing the database:", error)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run the script if it's executed directly
|
|
||||||
if (require.main === module) {
|
|
||||||
const config = {
|
|
||||||
projectApiNamespace: process.env.PROJECT_API_NAMESPACE,
|
|
||||||
mongodbUri: process.env.MONGODB_URI,
|
|
||||||
tibiDbPrefix: process.env.TIBI_DB_PREFIX,
|
|
||||||
tibiApiUrl: process.env.TIBI_API_URL,
|
|
||||||
// Add other required environment variables here
|
|
||||||
}
|
|
||||||
|
|
||||||
initializeDatabase(config)
|
|
||||||
.then(() => console.log("Database initialized successfully"))
|
|
||||||
.catch((err) => {
|
|
||||||
console.error("Failed to initialize database:", err)
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = initializeDatabase
|
|
@ -34,29 +34,6 @@ jobs:
|
|||||||
image: gitbase.de/robin/live-server:latest
|
image: gitbase.de/robin/live-server:latest
|
||||||
ports:
|
ports:
|
||||||
- 8081:8081
|
- 8081:8081
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Set up Node.js
|
|
||||||
uses: actions/setup-node@v2
|
|
||||||
with:
|
|
||||||
node-version: "20"
|
|
||||||
|
|
||||||
- name: Load .env file
|
|
||||||
run: |
|
|
||||||
set -a
|
|
||||||
source .env
|
|
||||||
set +a
|
|
||||||
|
|
||||||
- name: Initialize database
|
|
||||||
run: node /.gitea/actions/init-db
|
|
||||||
env:
|
|
||||||
PROJECT_API_NAMESPACE: $TIBI_NAMESPACE
|
|
||||||
MONGODB_URI: mongodb://mongo #service name!
|
|
||||||
TIBI_DB_PREFIX: $TIBI_PREFIX
|
|
||||||
TIBI_API_URL: http://tibi-server:8080/api/v1
|
|
||||||
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
name: deploy
|
name: deploy
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
version: "3.8"
|
version: "3.8"
|
||||||
name: ${PROJECT_NAME}
|
name: allkids_erfurt
|
||||||
|
|
||||||
services:
|
services:
|
||||||
docpress:
|
docpress:
|
||||||
|
Loading…
Reference in New Issue
Block a user