我正在尝试为我的Nodejs应用设置Jenkins管道。我有一个带Mariadb的Ubuntu Docker映像,运行良好,数据库启动,我可以从Jenkinsfile连接和执行SQL脚本。Jenkins以root用户身份启动Docker映像。节点应用使用Mariadb连接器(包mariadb)
在Jenkins之外,节点应用程序能够连接到本地MariaDB(用于测试)或远程MariaDB(已部署应用程序)...连接没有问题。在本地集成测试期间也是正常的。
当我尝试通过Jenkins运行测试时,当节点应用程序尝试创建到数据库的连接时,我收到此错误:SequelizeAccessDeniedError: (conn=14, no: 1045, SQLState: 28000) Access denied for user ''@'127.0.0.1' (using password: NO)
在Jenkinsfile中,我正在检查Docker的MariaDB数据库中testuser的创建,用户在其中成功创建。
我在连接之前将连接详细信息打印到控制台,一切正常...那么为什么MariaDB连接器要尝试与默认用户连接呢?
编辑:我还尝试在数据库类构造函数中设置socketPath,但它得到了相同的错误。
停靠文件:
from mariadb:10.7.7-focal
# Install additional packages
RUN set -eux; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
curl \
wget \
npm \
unzip \
iceweasel \
vim \
&& wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
&& apt-get install -y --no-install-recommends ./google-chrome-stable_current_amd64.deb
# Install NodeJs 18.x
RUN curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh \
&& bash nodesource_setup.sh \
&& apt-get install -y --no-install-recommends nodejs
Jenkins:
stage ('Setup test data in database')
{
steps
{
echo "*** Setting up test data in database ***"
sh "set"
sh "service mariadb start -v --skip-name-resolve"
sh "echo password | mariadb -u root -p -e \"CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'password';\""
sh "echo password | mariadb -u root -p -e \"CREATE USER 'testuser'@'127.0.0.1' IDENTIFIED BY 'password';\""
sh "echo password | mariadb -u root -p -e \"GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'127.0.0.1';\""
sh "echo password | mariadb -u root -p -e \"GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'localhost';\""
sh "echo password | mariadb -u root -p -e \"FLUSH PRIVILEGES;\""
sh "echo password | mariadb -u root -p -e \"SELECT user,authentication_string,plugin,host,password FROM mysql.user;\""
sh "echo password | mariadb -u root -p -e \"SOURCE database/create.sql\""
}
}
// End SETUP DATABASE
stage ('Fetch integration test drivers')
{
steps
{
echo "*** Fetching integration test drivers ***"
sh "google-chrome --version"
sh script:'''
mkdir ./tests/integration/drivers
wget https://github.com/mozilla/geckodriver/releases/download/v0.32.0/geckodriver-v0.32.0-linux64.tar.gz
tar -x geckodriver -zf geckodriver-v0.32.0-linux64.tar.gz -O > tests/integration/drivers/geckodriver && chmod +x ./tests/integration/drivers/geckodriver
wget https://chromedriver.storage.googleapis.com/108.0.5359.71/chromedriver_linux64.zip
unzip chromedriver_linux64.zip && chmod +x chromedriver && mv chromedriver ./tests/integration/drivers
rm geckodriver-v0.32.0-linux64.tar.gz && rm chromedriver_linux64.zip
'''
}
}
// End CLONING
stage ('Run NPM install')
{
steps
{
echo "*** Running npm install ***"
sh "npm install"
}
}
// End NPM INSTALL
stage ('Running Integration Tests')
{
steps
{
echo "*** Starting Integration Tests ***"
sh '(npm run dev-api & npm run dev-frontend-instance1 & npm run dev-frontend-instance2) && npm run test-integration'
}
}
节点应用数据库类构造函数:
class Database {
private static _instances: { instance1: Database | undefined, instance2: Database | undefined } = {
instance1: undefined,
instance2: undefined
};
private _connectionDetails = {
host: process.env.API_IP ? process.env.API_IP : "localhost",
user: process.env.DATABASE_USER ? process.env.DATABASE_USER : "testuser",
password: process.env.DATABASE_PASSWORD ? process.env.DATABASE_PASSWORD : "password",
port: 3306,
database: ""
};
private _connection: Promise<mariadb.Connection>;
private _frontendHostname: string;
constructor(databaseName: string) {
this._connectionDetails.database = databaseName;
console.log("CONNECTION DETAILS: ", this._connectionDetails);
this._connection = mariadb.createConnection(this._connectionDetails);
this._frontendHostname = databaseName == "instance1" ? "https://url1" : "https://url2";
if (process.env.API_IP == "localhost") {
this._frontendHostname = "https://localhost:8080";
}
}
Jenkins中的输出:
CONNECTION DETAILS: {
host: 'localhost',
user: 'testuser',
password: 'password',
port: 3306,
database: 'instance1'
}
SequelizeAccessDeniedError: (conn=14, no: 1045, SQLState: 28000) Access denied for user ''@'127.0.0.1' (using password: NO)
1条答案
按热度按时间von4xj4u1#
我最终创建了它要找的用户,现在它可以工作了。