Skip to content

Commit ccfd53f

Browse files
committed
Add documetation on how you can install db client on code-server
1 parent 0df7031 commit ccfd53f

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Incorporate standard database clients on code server (vs code)
2+
3+
## Introduction
4+
5+
In the field of Database Management Systems effective interaction is crucial for developers. Incorporating standard database clients directly into your VS Code environment can streamline your workflow, offering a seamless interface for managing databases. This tutorial will walk you through the process of incorporating different Database Management System clients into Code Server, whether through built-in extensions within VS Code or by creating your own custom image.
6+
7+
## 1. Through Extensions
8+
9+
### Installation Guide
10+
11+
1. Open the code server workbench and navigate to the Extensions view.
12+
13+
2. Search for the desired extension using the provided recommended links.
14+
15+
3. Click "Install" to add the extension to your VS Code environment.
16+
17+
### Recommended extensions list
18+
19+
**MongoDB for VS Code**
20+
21+
MongoDB for VS Code empowers you to connect to MongoDB and Atlas directly from your VS Code environment. Explore databases and collections, inspect schemas, and prototype queries and aggregations effortlessly using the integrated playgrounds.
22+
23+
[Link to Extension](https://marketplace.visualstudio.com/items?itemName=mongodb.mongodb-vscode)
24+
25+
**MySQL Shell for VS Code**
26+
27+
This extension provides a robust MySQL Shell for VS Code, enhancing your capability to manage MySQL databases seamlessly within the VS Code environment.
28+
29+
[Link to Extension](https://marketplace.visualstudio.com/items?itemName=Oracle.mysql-shell-for-vs-code)
30+
31+
**SQL Server (MSSQL)**
32+
33+
Connect to SQL Server effortlessly with this extension, enabling you to perform database tasks directly from your VS Code workspace.
34+
35+
[Link to Extension](https://marketplace.visualstudio.com/items?itemName=ms-mssql.mssql)
36+
37+
**PostgreSQL**
38+
39+
This extension facilitates direct interaction with PostgreSQL databases, allowing you to navigate, query, and manage your PostgreSQL instances efficiently.
40+
41+
[Link to Extension](https://marketplace.visualstudio.com/items?itemName=ms-ossdata.vscode-postgresql)
42+
43+
**SQLTools**
44+
45+
SQLTools simplifies database connections, supporting a wide array of commonly used databases. This extension enhances data management and query execution, making it an invaluable tool for developers.
46+
47+
[Link to Extension](https://marketplace.visualstudio.com/items?itemName=mtxr.sqltools)
48+
49+
**Database Client**
50+
51+
This versatile extension serves as a database manager for MySQL/MariaDB, PostgreSQL, SQLite, Redis, and ElasticSearch. It provides a unified interface for managing diverse databases within the VS Code environment.
52+
53+
[Link to Extension](https://marketplace.visualstudio.com/items?itemName=cweijan.vscode-database-client2)
54+
55+
# 2. Through Custom Image
56+
57+
Custom notebook images are a powerful tool when working with containerized environments, especially in scenarios where you need specific libraries, OS packages, or applications that are not readily available in base images. This tutorial will guide you through the process of creating a custom notebook image with Database Management System (DBMS) clients using Dockerfile.
58+
59+
## Prerequisites
60+
61+
Before you begin, make sure you have Docker installed on your system.
62+
63+
**Step 1: Clone the Repository**
64+
65+
Start by cloning the Open Data Hub notebooks repository:
66+
67+
```git clone [email protected]:opendatahub-io/notebooks.git```
68+
69+
**Step 2: Create a New Dockerfile**
70+
71+
Navigate to the codeserver folder and create a new folder for your custom image. For example, let's name it ubi9-python-3.9-db-clients. Inside this folder, create a Dockerfile with the following instructions:
72+
73+
```
74+
# The base image auto assigned by the make recipe from the next step, in this case is the code-server notebook.
75+
ARG BASE_IMAGE
76+
FROM ${BASE_IMAGE}
77+
78+
WORKDIR /opt/app-root/bin
79+
80+
# Install OS packages as root
81+
USER root
82+
83+
# Install necessary OS packages
84+
RUN dnf install -y unixODBC postgresql
85+
86+
# Install MongoDB Client
87+
COPY mongodb-org-6.0.repo-x86_64 /etc/yum.repos.d/mongodb-org-6.0.repo
88+
89+
RUN dnf install -y mongocli
90+
91+
# Install MSSQL Client
92+
COPY mssql-2022.repo-x86_64 /etc/yum.repos.d/mssql-2022.repo
93+
94+
RUN ACCEPT_EULA=Y dnf install -y mssql-tools18 unixODBC-devel
95+
96+
ENV PATH="$PATH:/opt/mssql-tools18/bin"
97+
98+
# Switch back to default user
99+
USER 1001
100+
101+
WORKDIR /opt/app-root/src
102+
```
103+
104+
**Step 3: Add RPM Files**
105+
106+
Create two RPM files, mongodb-org-6.0.repo-x86_64 and mssql-2022.repo-x86_64, in the folder you created earlier. The content for these files is provided in the tutorial.
107+
108+
Filename: mongodb-org-6.0.repo-x86_64
109+
110+
```
111+
[mongodb-org-6.0]
112+
name=MongoDB Repository
113+
baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/6.0/x86_64/
114+
gpgcheck=1
115+
enabled=1
116+
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
117+
```
118+
119+
Filename: mssql-2022.repo-x86_64
120+
121+
```
122+
[packages-microsoft-com-prod]
123+
name=packages-microsoft-com-prod
124+
baseurl=https://packages.microsoft.com/rhel/9.0/prod/
125+
enabled=1
126+
gpgcheck=1
127+
gpgkey=https://packages.microsoft.com/keys/microsoft.asc
128+
```
129+
130+
**Step 4: Build and Push the Image**
131+
132+
To streamline the build and push process, update the Makefile with a new recipe:
133+
134+
```
135+
.PHONY: codeserver-ubi9-python-3.9-db-clients
136+
codeserver-ubi9-python-3.9-db-clients: codeserver-ubi9-python-3.9
137+
$(call image,$@,codeserver/ubi9-python-3.9-db-clients,$<)
138+
```
139+
140+
Run the following command to build and push the image:
141+
142+
```
143+
$ make codeserver-ubi9-python-3.9-db-clients -e IMAGE_REGISTRY=quay.io/${YOUR_USERNAME}/workbench-images
144+
```
145+
146+
Note: Replace `${YOUR_USERNAME}` with your actual username, and the registry can be any valid registry, not just quay.io.
147+
148+
**Step 5: Import Custom Image into ODH/RHOAI**
149+
150+
After pushing the custom image, import it into Red Hat OpenAI through the admin panel:
151+
152+
Navigate to `Settings -> Notebooks Image Settings -> Import New Image`.
153+
154+
**Step 6: Use Custom Image in a Data Science Project**
155+
156+
Create or open a Data Science Project, create a new workbench, and select the custom image from the Image Selection dropdown.
157+
158+
**Step 7: Verify Database Clients Installation**
159+
160+
Open a new terminal inside the code server and run the following command to ensure successful installation of database clients:
161+
162+
`$ yum list installed | grep -E 'mssql|mongo|postgresql'`
163+
164+
If everything is set up correctly, you should see a list of installed packages related to MongoDB, MSSQL, and PostgreSQL.
165+
166+
Here you may find an example: [https://github.com/atheo89/notebooks/tree/add-db-clients-example/codeserver/ubi9-python-3.9-plus](https://github.com/atheo89/notebooks/tree/add-db-clients-example/codeserver/ubi9-python-3.9-plus)

0 commit comments

Comments
 (0)