ARTIFACTORY: How to configure Artifactory with an external database when using Artifactory Helm Installation
When you install Artifactory, you may want to consider using an external database in order to enhance Artifactory’s capabilities by using a production grade database as well as utilize the best practices for Artifactory’s database.
In the following article, we will list the different types of supported databases you can use and how to configure Artifactory to connect with each one of them.
Please NOTE:
To use an external database with Artifactory, set the "postgresql.enabled" value to "false" and provide the necessary configuration details in the "database" section of the Artifactory installation. Failing to set "postgresql.enabled" to "false" will result in the internal database being used instead.
The following databases are supported:PostgreSQL– recommended
MySQL
Oracle
MSSQL
MariaDB is not supported on helm.
PostgreSQLArtifactory Helm Installation comes bundled with a postgresql database, however, you may want to use your own database instead. In that case, you will need to set the postgresql.enabled: false value and the database section instead for the chart to use the External database.* parameters. Without it, they will be ignored and the chart will use the internal DB, below is an example:
postgresql:
enabled: false
database:
type: postgresql
driver: org.postgresql.Driver
url: 'jdbc:postgresql://${DB_HOST}:${DB_PORT}/my-artifactory-db'
user: <DB_USER>
password: <DB_PASSWORD>
In case you are using an RDS database, the following values should be used:
postgresql: enabled: false database: type: postgresql driver: org.postgresql.Driver url: "jdbc:postgresql://test.postgres.database.azure.com:5432/artifactorydb" username: "artifactory@test" password: password actualUsername: artifactory@test
The same applies when setting up Xray with PostgreSQL database, But using a different prefix for the DB URL:
postgresql:
enabled: false
database:
type: postgresql
driver: org.postgresql.Driver
url: 'postgres://${DB_HOST}:${DB_PORT}/xraydb?sslmode=disable'
user: <DB_USER>
password: <DB_PASSWORD>
Similar settings are applied when configuring Xray with an RDS database:
postgresql: enabled: false database: type: postgresql driver: org.postgresql.Driver url: "postgres://test.postgres.database.azure.com:5432/xraydb?sslmode=disable" username: "xray@test" password: xray actualUsername: xray@test
MYSQL Database
Note: Pre-start command downloads the driver and places it in /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib/ so it can be used by the Artifactory.
The example below which can be added to the values.yaml:
postgresql:
enabled: false
waitForDatabase: true
database:
type: mysql
driver: com.mysql.jdbc.Driver
url: 'jdbc:mysql://database-ip:3306/artdb?characterEncoding=UTF-8&elideSetAutoCommits=true&useSSL=false'
user: artifactory
password: password
artifactory:
preStartCommand: "mkdir -p /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib; cd /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib && curl https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.30/mysql-connector-java-8.0.30.jar -o /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib/mysql-connector-java-8.0.30.jar; chmod 644
mysql-connector-java-8.0.30.jar"Oracle Database
To use Artifactory with an Oracle database, it is required to instant client library files, libaio must be copied to the tomcat lib (Refer to NOTE 1 below). In addition, you will need to set the LD_LIBRARY_PATH env variable (Refer to NOTE 2 below).
NOTE:
- Pre-start command downloads the driver and places it in /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib/ and copies the files to tomcat lib so it can be used by the Artifactory.
- We also use extraEnvironmentVariables to override the LD_LIBRARY_path in the system.yaml to point to the instant client.
The example below which can be added to the values.yaml:
postgresql: enabled: false waitForDatabase: true database: type: oracle driver: oracle.jdbc.OracleDriver url: 'jdbc:oracle:thin:@database-ip:1521/ORCL' user: artifactory password: password artifactory: preStartCommand: "mkdir -p /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib; cd /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib && curl -o instantclient-basic-linux.x64-21.8.0.0.0dbru.zip https://download.oracle.com/otn_software/linux/instantclient/218000/instantclient-basic-linux.x64-21.8.0.0.0dbru.zip && unzip -jn instantclient-basic-linux.x64-21.8.0.0.0dbru.zip && cp /opt/jfrog/artifactory/app/artifactory/libaio/* . && ln -s /usr/lib64/libnsl.so.2 /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib/libnsl.so.1 && ls -lah && rm /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib/instantclient-basic-linux.x64-21.8.0.0.0dbru.zip&& cp * /opt/jfrog/artifactory/app/artifactory/libaio/" extraEnvironmentVariables: - name: LD_LIBRARY_PATH value: /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib
MSSQL Database
To use Artifactory with an MSSQL database, adding a GO connection URL is required in order to connect to the metadata service.
Note:
- Pre-start command downloads the driver and places it in /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib/ so it can be used by the Artifactory.
- We also use extraEnvironmentVariables to override the metadata.URL in the system.yaml to connect to the database using GO because common error is when the database password inside of the Go connection string's metadata.database.url is not encrypted after startup.
The example below which can be added to the values.yaml:
postgresql: enabled: false waitForDatabase: false database: type: mssql driver: com.microsoft.sqlserver.jdbc.SQLServerDriver url: 'jdbc:sqlserver://<db-hostname>:1433;databaseName=artifactory;authentication=NotSpecified;encrypt=false;sendStringParametersAsUnicode=false;applicationName=Artifactory Binary Repository;' user: 'artifactory' password: 'password' artifactory: extraEnvironmentVariables: - name: JF_METADATA_DATABASE_URL value: "go:sqlserver://artifactoryuser:password@IP-ADDRESS:1433/MSSQLSERVER?database=artifactory" preStartCommand: "mkdir -p /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib; cd /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib && curl -L https://github.com/microsoft/mssql-jdbc/releases/download/v11.2.0/mssql-jdbc-11.2.0.jre17.jar -o /opt/jfrog/artifactory/var/bootstrap/artifactory/tomcat/lib/mssql-jdbc-11.2.0.jre17.jar"
Applying these changes can be done by using the below helm upgrade command (depending on the helm chart you are using – artifactory, artifactory-ha or JFrog platform):
Artifactory:
helm upgrade –install artifactory jfrog/artifactory –namespace artifactory -f values.yaml
Artifactory HA:
helm upgrade –install artifactory-ha jfrog/artifactory-ha –namespace artifactory-ha -f values.yaml
Jfrog-platform:
helm upgrade --install jfrog-platform --namespace jfrog-platform jfrog/jfrog-platform -f values.yaml