prepush hooks
This commit is contained in:
parent
f944e31ce0
commit
7e6c91ef5d
19
.gitea/actions/init-db/action.yml
Normal file
19
.gitea/actions/init-db/action.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
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/
|
||||||
|
|
116
.gitea/actions/init-db/index.js
Normal file
116
.gitea/actions/init-db/index.js
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
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
|
@ -0,0 +1 @@
|
|||||||
|
{"options":{},"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_","ns":"tibi_allkids_erfurt.backups"},{"v":{"$numberInt":"2"},"key":{"insertTime":{"$numberInt":"1"}},"name":"insertTime_1","ns":"tibi_allkids_erfurt.backups"},{"v":{"$numberInt":"2"},"key":{"updateTime":{"$numberInt":"1"}},"name":"updateTime_1","ns":"tibi_allkids_erfurt.backups"}],"uuid":"4993cf280e844b5b80fe208350713002"}
|
BIN
.gitea/actions/init-db/tibi_allkids_erfurt/banner.bson
Normal file
BIN
.gitea/actions/init-db/tibi_allkids_erfurt/banner.bson
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
{"options":{},"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_","ns":"tibi_allkids_erfurt.banner"},{"v":{"$numberInt":"2"},"key":{"insertTime":{"$numberInt":"1"}},"name":"insertTime_1","ns":"tibi_allkids_erfurt.banner"},{"v":{"$numberInt":"2"},"key":{"updateTime":{"$numberInt":"1"}},"name":"updateTime_1","ns":"tibi_allkids_erfurt.banner"}],"uuid":"7346de51448b4a27b289a0e32336d0b6"}
|
BIN
.gitea/actions/init-db/tibi_allkids_erfurt/content.bson
Normal file
BIN
.gitea/actions/init-db/tibi_allkids_erfurt/content.bson
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
{"options":{},"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_","ns":"tibi_allkids_erfurt.content"},{"v":{"$numberInt":"2"},"key":{"insertTime":{"$numberInt":"1"}},"name":"insertTime_1","ns":"tibi_allkids_erfurt.content"},{"v":{"$numberInt":"2"},"key":{"updateTime":{"$numberInt":"1"}},"name":"updateTime_1","ns":"tibi_allkids_erfurt.content"},{"v":{"$numberInt":"2"},"key":{"meta.datum":{"$numberInt":"1"}},"name":"meta.datum_1","ns":"tibi_allkids_erfurt.content"}],"uuid":"df9951d7cf964e5e8a22360c09aa27c7"}
|
BIN
.gitea/actions/init-db/tibi_allkids_erfurt/forms.bson
Normal file
BIN
.gitea/actions/init-db/tibi_allkids_erfurt/forms.bson
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
{"options":{},"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_","ns":"tibi_allkids_erfurt.forms"},{"v":{"$numberInt":"2"},"key":{"insertTime":{"$numberInt":"1"}},"name":"insertTime_1","ns":"tibi_allkids_erfurt.forms"},{"v":{"$numberInt":"2"},"key":{"updateTime":{"$numberInt":"1"}},"name":"updateTime_1","ns":"tibi_allkids_erfurt.forms"}],"uuid":"7815c4dfc9d9460c8aac8cf94cc67ea6"}
|
BIN
.gitea/actions/init-db/tibi_allkids_erfurt/navigation.bson
Normal file
BIN
.gitea/actions/init-db/tibi_allkids_erfurt/navigation.bson
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
{"options":{},"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_","ns":"tibi_allkids_erfurt.navigation"},{"v":{"$numberInt":"2"},"key":{"insertTime":{"$numberInt":"1"}},"name":"insertTime_1","ns":"tibi_allkids_erfurt.navigation"},{"v":{"$numberInt":"2"},"key":{"updateTime":{"$numberInt":"1"}},"name":"updateTime_1","ns":"tibi_allkids_erfurt.navigation"}],"uuid":"d989bd0ea7ba4ea4ae728b8a6baa62ba"}
|
BIN
.gitea/actions/init-db/tibi_allkids_erfurt/ssr.bson
Normal file
BIN
.gitea/actions/init-db/tibi_allkids_erfurt/ssr.bson
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
{"options":{},"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_","ns":"tibi_allkids_erfurt.ssr"},{"v":{"$numberInt":"2"},"key":{"insertTime":{"$numberInt":"1"}},"name":"insertTime_1","ns":"tibi_allkids_erfurt.ssr"},{"v":{"$numberInt":"2"},"key":{"updateTime":{"$numberInt":"1"}},"name":"updateTime_1","ns":"tibi_allkids_erfurt.ssr"},{"v":{"$numberInt":"2"},"unique":true,"key":{"path":{"$numberInt":"1"}},"name":"path_1","ns":"tibi_allkids_erfurt.ssr"}],"uuid":"75869e19f8164beabe53366265b10208"}
|
@ -0,0 +1 @@
|
|||||||
|
{"options":{},"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_","ns":"tibi_allkids_erfurt.temperature"},{"v":{"$numberInt":"2"},"key":{"insertTime":{"$numberInt":"1"}},"name":"insertTime_1","ns":"tibi_allkids_erfurt.temperature"},{"v":{"$numberInt":"2"},"key":{"updateTime":{"$numberInt":"1"}},"name":"updateTime_1","ns":"tibi_allkids_erfurt.temperature"}],"uuid":"eb60c1bc334c4fa2a473fdb6c99b3e6a"}
|
@ -34,6 +34,29 @@ 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: allkids_erfurt
|
name: ${PROJECT_NAME}
|
||||||
|
|
||||||
services:
|
services:
|
||||||
docpress:
|
docpress:
|
||||||
|
Loading…
Reference in New Issue
Block a user