Skip to content

Commit 270a871

Browse files
authored
Merge pull request #858 from oracle-devrel/atp-operator-nodejs-repo-create
repo create
2 parents b300ea7 + bcb8801 commit 270a871

File tree

7 files changed

+294
-0
lines changed

7 files changed

+294
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node:16.16.0
2+
3+
WORKDIR /
4+
5+
RUN apt-get update && apt-get install -y libaio1
6+
7+
ENV LD_LIBRARY_PATH=/instantclient_21_7
8+
9+
COPY ["package.json", "package-lock.json*", "./"]
10+
11+
RUN npm install
12+
13+
COPY . .
14+
15+
RUN unzip instantclient-basic-linux.x64-21.7.0.0.0dbru.zip
16+
17+
RUN rm -f instantclient-basic-linux.x64-21.7.0.0.0dbru.zip
18+
19+
CMD [ "node", "server.js" ]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!--
2+
Copyright (c) 2024 Oracle and/or its affiliates.
3+
4+
The Universal Permissive License (UPL), Version 1.0
5+
6+
Subject to the condition set forth below, permission is hereby granted to any
7+
person obtaining a copy of this software, associated documentation and/or data
8+
(collectively the "Software"), free of charge and under any and all copyright
9+
rights in the Software, and any and all patent rights owned or freely
10+
licensable by each licensor hereunder covering either (i) the unmodified
11+
Software as contributed to or provided by such licensor, or (ii) the Larger
12+
Works (as defined below), to deal in both
13+
14+
(a) the Software, and
15+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16+
one is included with the Software (each a "Larger Work" to which the Software
17+
is contributed by such licensors),
18+
19+
without restriction, including without limitation the rights to copy, create
20+
derivative works of, display, perform, and distribute the Software and make,
21+
use, sell, offer for sale, import, export, have made, and have sold the
22+
Software and the Larger Work(s), and to sublicense the foregoing rights on
23+
either these or other terms.
24+
25+
This license is subject to the following condition:
26+
The above copyright notice and either this complete permission notice or at
27+
a minimum a reference to the UPL must be included in all copies or
28+
substantial portions of the Software.
29+
30+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
SOFTWARE.
37+
-->
38+
39+
### Blog on Medium
40+
41+
Please see the <a href="https://medium.com/@mika.rinne/easy-oracle-autonomous-db-access-for-nodejs-with-kubernetes-operator-cf02ea7fc59a">blog on Medium</a>.
42+
43+
### License
44+
45+
Copyright (c) 2024 Oracle and/or its affiliates.
46+
47+
Licensed under the Universal Permissive License (UPL), Version 1.0.
48+
49+
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE) for more details.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Copyright (c) 2022, Oracle and/or its affiliates.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
4+
#
5+
apiVersion: database.oracle.com/v1alpha1
6+
kind: AutonomousDatabase
7+
metadata:
8+
name: atp
9+
spec:
10+
details:
11+
# Update compartmentOCID with your compartment OCID.
12+
compartmentOCID: ocid1.compartment.oc1..aaaaaaaawccfkl...u5ripl2whnznhmvgiqdatqgq
13+
# The dbName must begin with an alphabetic character and can contain a maximum of 14 alphanumeric characters. Special characters are not permitted. The database name must be unique in the tenancy.
14+
dbName: atp
15+
displayName: atp
16+
cpuCoreCount: 1
17+
adminPassword:
18+
# Comment out k8sSecret and uncomment ociSecret if you pass the admin password using OCI Secret.
19+
k8sSecret:
20+
# The Name of the K8s secret where you want to hold the password of the ADMIN account.
21+
name: admin-password
22+
wallet:
23+
name: instance-wallet
24+
password:
25+
k8sSecret:
26+
name: instance-wallet-password
27+
dataStorageSizeInTBs: 1
28+
networkAccess:
29+
accessType: PUBLIC
30+
31+
# Authorize the operator with API signing key pair. Comment out the ociConfig fields if your nodes are already authorized with instance principal.
32+
#ociConfig:
33+
#configMapName: oci-cred
34+
#secretName: oci-privatekey
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#
2+
# Copyright (c) 2022, Oracle and/or its affiliates.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
4+
#
5+
apiVersion: apps/v1
6+
kind: Deployment
7+
metadata:
8+
name: atp-nodejs
9+
labels:
10+
app: atp-nodejs
11+
spec:
12+
replicas: 1
13+
selector:
14+
matchLabels:
15+
app: atp-nodejs
16+
template:
17+
metadata:
18+
labels:
19+
app: atp-nodejs
20+
spec:
21+
containers:
22+
- name: atp-nodejs
23+
image: fra.ocir.io/<YOUR TENANCY NAMESPACE>/atp-nodejs:1.0
24+
imagePullPolicy: Always
25+
ports:
26+
- containerPort: 3000
27+
volumeMounts:
28+
- name: secret-volume
29+
mountPath: /instantclient_21_7/network/admin
30+
env:
31+
- name: ATP_PWD
32+
valueFrom:
33+
secretKeyRef:
34+
name: admin-password
35+
key: admin-password
36+
imagePullSecrets:
37+
- name: ocirsecret
38+
volumes:
39+
- name: secret-volume
40+
secret:
41+
secretName: instance-wallet
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "atp-nodejs",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "server.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "",
11+
"url": ""
12+
},
13+
"author": "[email protected]",
14+
"license": "ISC",
15+
"bugs": {
16+
"url": ""
17+
},
18+
"homepage": "",
19+
"dependencies": {
20+
"express": "^4.18.1",
21+
"oracledb": "^5.4.0"
22+
}
23+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
Copyright (c) 2024 Oracle and/or its affiliates.
3+
4+
The Universal Permissive License (UPL), Version 1.0
5+
6+
Subject to the condition set forth below, permission is hereby granted to any
7+
person obtaining a copy of this software, associated documentation and/or data
8+
(collectively the "Software"), free of charge and under any and all copyright
9+
rights in the Software, and any and all patent rights owned or freely
10+
licensable by each licensor hereunder covering either (i) the unmodified
11+
Software as contributed to or provided by such licensor, or (ii) the Larger
12+
Works (as defined below), to deal in both
13+
14+
(a) the Software, and
15+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16+
one is included with the Software (each a "Larger Work" to which the Software
17+
is contributed by such licensors),
18+
19+
without restriction, including without limitation the rights to copy, create
20+
derivative works of, display, perform, and distribute the Software and make,
21+
use, sell, offer for sale, import, export, have made, and have sold the
22+
Software and the Larger Work(s), and to sublicense the foregoing rights on
23+
either these or other terms.
24+
25+
This license is subject to the following condition:
26+
The above copyright notice and either this complete permission notice or at
27+
a minimum a reference to the UPL must be included in all copies or
28+
substantial portions of the Software.
29+
30+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
SOFTWARE.
37+
*/
38+
39+
const fs = require('fs');
40+
const oracledb = require('oracledb');
41+
const http = require("http");
42+
const express = require('express');
43+
const app = express();
44+
const path = require('path');
45+
46+
const password = process.env.ATP_PWD;
47+
48+
oracledb.initOracleClient({ libDir: '/instantclient_21_7', configDir: '/instantclient_21_7/network/admin/' });
49+
50+
async function init() {
51+
try {
52+
// Create a connection pool which will later be accessed via the
53+
// pool cache as the 'default' pool.
54+
await oracledb.createPool({
55+
user: 'admin',
56+
password: password,
57+
connectString: 'atp_tp'
58+
});
59+
console.log('Connection pool started succesfully.');
60+
} catch (err) {
61+
console.error('init() error: ' + err.message);
62+
}
63+
}
64+
65+
app.get('/', (req, res) => {
66+
getDate().then((date) => {
67+
console.log(date);
68+
res.send(date);
69+
});
70+
});
71+
72+
async function getDate() {
73+
let connection;
74+
try {
75+
// Get a connection from the default pool
76+
connection = await oracledb.getConnection();
77+
const sql = `SELECT SYSDATE FROM DUAL`;
78+
const result = await connection.execute(sql);
79+
const date = result.rows[0];
80+
return date;
81+
} catch (err) {
82+
console.error(err);
83+
} finally {
84+
if (connection) {
85+
try {
86+
// Put the connection back in the pool
87+
await connection.close();
88+
} catch (err) {
89+
console.error(err);
90+
}
91+
}
92+
}
93+
}
94+
95+
async function closePoolAndExit() {
96+
console.log('\nTerminating');
97+
try {
98+
await oracledb.getPool().close(10);
99+
console.log('Pool closed');
100+
process.exit(0);
101+
} catch (err) {
102+
console.error(err.message);
103+
process.exit(1);
104+
}
105+
}
106+
107+
process
108+
.once('SIGTERM', closePoolAndExit)
109+
.once('SIGINT', closePoolAndExit);
110+
111+
init();
112+
app.listen(3000);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (c) 2022, Oracle and/or its affiliates.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
4+
#
5+
apiVersion: v1
6+
kind: Service
7+
metadata:
8+
name: atp-nodejs
9+
spec:
10+
selector:
11+
app: atp-nodejs
12+
ports:
13+
- protocol: TCP
14+
port: 80
15+
targetPort: 3000
16+
type: LoadBalancer

0 commit comments

Comments
 (0)