Changing DB config and requests in scripts
continuous-integration/drone/push Build encountered an error Details

main
Félix MIELCAREK 11 months ago
parent 0e964f11a3
commit 65bb022672

@ -4,97 +4,96 @@ name: BB_PIPELINE
steps:
- name: deploy-container-db
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
environment:
IMAGENAME: mariadb:10
CONTAINERNAME: bigbrotherdb
COMMAND: create
OVERWRITE: false
PRIVATE: true
CODEFIRST_CLIENTDRONE_ENV_MARIADB_ROOT_PASSWORD:
from_secret: db_root_password
CODEFIRST_CLIENTDRONE_ENV_MARIADB_DATABASE:
from_secret: db_database
CODEFIRST_CLIENTDRONE_ENV_MARIADB_USER:
from_secret: db_user
CODEFIRST_CLIENTDRONE_ENV_MARIADB_PASSWORD:
from_secret: db_password
- name: create-bigbrother-database
image: python:latest
commands:
- cd database/
- pip3 install mariadb
- python3 db-creation.py
environment:
MARIADB_USER:
from_secret: db_user
MARIADB_PASSWORD:
from_secret: db_password
depends_on: [ deploy-container-db ]
# - name: build-image-server
# image: plugins/docker
# settings:
# dockerfile: callback-server/Dockerfile
# context: ./
# registry: hub.codefirst.iut.uca.fr
# repo: hub.codefirst.iut.uca.fr/felix.mielcarek/big-brother-server
# username:
# from_secret: SECRET_REGISTRY_USERNAME
# password:
# from_secret: SECRET_REGISTRY_PASSWORD
# depends_on: [ create-bigbrother-database ]
#
# - name: deploy-container-server
# - name: deploy-container-db
# image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
# environment:
# IMAGENAME: hub.codefirst.iut.uca.fr/felix.mielcarek/big-brother-server:latest
# CONTAINERNAME: bigbrotherserver
# IMAGENAME: mariadb:10
# CONTAINERNAME: bigbrotherdb
# COMMAND: create
# OVERWRITE: true
# POSTGRES_USER:
# OVERWRITE: false
# PRIVATE: true
# CODEFIRST_CLIENTDRONE_ENV_MARIADB_ROOT_PASSWORD:
# from_secret: db_root_password
# CODEFIRST_CLIENTDRONE_ENV_MARIADB_DATABASE:
# from_secret: db_database
# CODEFIRST_CLIENTDRONE_ENV_MARIADB_USER:
# from_secret: db_user
# POSTGRES_PASSWORD:
# CODEFIRST_CLIENTDRONE_ENV_MARIADB_PASSWORD:
# from_secret: db_password
# POSTGRES_DATABASE:
# from_secret: db_database
# CLIENT_ID:
# from_secret: spotify_client_id
# CLIENT_SECRET:
# from_secret: spotify_client_id
# depends_on: [ build-image-server ]
#
# - name: build-image-script
# image: plugins/docker
# settings:
# dockerfile: script/Dockerfile
# context: ./
# registry: hub.codefirst.iut.uca.fr
# repo: hub.codefirst.iut.uca.fr/felix.mielcarek/big-brother
# username:
# from_secret: SECRET_REGISTRY_USERNAME
# password:
# from_secret: SECRET_REGISTRY_PASSWORD
# depends_on: [ create-bigbrother-database ]
#
# - name: deploy-container-script
# image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
# - name: create-bigbrother-database
# image: python:latest
# commands:
# - cd database/
# - pip3 install mariadb
# - python3 db-creation.py
# environment:
# IMAGENAME: hub.codefirst.iut.uca.fr/felix.mielcarek/big-brother:latest
# CONTAINERNAME: bigbrotherscript
# COMMAND: create
# OVERWRITE: true
# POSTGRES_USER:
# MARIADB_USER:
# from_secret: db_user
# POSTGRES_PASSWORD:
# MARIADB_PASSWORD:
# from_secret: db_password
# POSTGRES_DATABASE:
# from_secret: db_database
# CLIENT_ID:
# from_secret: spotify_client_id
# CLIENT_SECRET:
# from_secret: spotify_client_id
# depends_on: [ build-image-script ]
#
# depends_on: [ deploy-container-db ]
- name: build-image-server
image: plugins/docker
settings:
dockerfile: callback-server/Dockerfile
context: ./
registry: hub.codefirst.iut.uca.fr
repo: hub.codefirst.iut.uca.fr/felix.mielcarek/big-brother-server
username:
from_secret: SECRET_REGISTRY_USERNAME
password:
from_secret: SECRET_REGISTRY_PASSWORD
depends_on: [ create-bigbrother-database ]
- name: deploy-container-server
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
environment:
IMAGENAME: hub.codefirst.iut.uca.fr/felix.mielcarek/big-brother-server:latest
CONTAINERNAME: bigbrotherserver
COMMAND: create
OVERWRITE: true
POSTGRES_USER:
from_secret: db_user
POSTGRES_PASSWORD:
from_secret: db_password
POSTGRES_DATABASE:
from_secret: db_database
CLIENT_ID:
from_secret: spotify_client_id
CLIENT_SECRET:
from_secret: spotify_client_id
depends_on: [ build-image-server ]
- name: build-image-script
image: plugins/docker
settings:
dockerfile: script/Dockerfile
context: ./
registry: hub.codefirst.iut.uca.fr
repo: hub.codefirst.iut.uca.fr/felix.mielcarek/big-brother
username:
from_secret: SECRET_REGISTRY_USERNAME
password:
from_secret: SECRET_REGISTRY_PASSWORD
depends_on: [ create-bigbrother-database ]
- name: deploy-container-script
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
environment:
IMAGENAME: hub.codefirst.iut.uca.fr/felix.mielcarek/big-brother:latest
CONTAINERNAME: bigbrotherscript
COMMAND: create
OVERWRITE: true
POSTGRES_USER:
from_secret: db_user
POSTGRES_PASSWORD:
from_secret: db_password
POSTGRES_DATABASE:
from_secret: db_database
CLIENT_ID:
from_secret: spotify_client_id
CLIENT_SECRET:
from_secret: spotify_client_id
depends_on: [ build-image-script ]

@ -1,7 +1,7 @@
//#region REQUIRE
const express = require('express')
const axios = require('axios');
const { Client } = require('pg');
const mariadb = require('mariadb');
//#endregion
//#region CONSTANTS
@ -20,13 +20,12 @@ app.listen(port, () => { console.log(`Big brother is listening on port ${port}`)
//#region ACCESS TOKEN
app.get('/settings/deactivate', async (req,res) => {
const client = new Client({
const client = mariadb.createPool({
host: 'felixmielcarek-bigbrotherdb',
user: process.env.POSTGRES_USER,
database: process.env.POSTGRES_DATABASE,
password: process.env.POSTGRES_PASSWORD,
port: 5432
})
user: process.env.MARIADB_USER,
database: process.env.MARIADB_DATABASE,
password: process.env.MARIADB_PASSWORD
});
const code = req.query.code;
@ -45,14 +44,14 @@ app.get('/settings/deactivate', async (req,res) => {
try {
const response2 = await axios.get(`https://api.spotify.com/v1/me`, { headers: { 'Authorization': 'Bearer ' + accessToken, } });
await client.connect()
await client.getConnection()
const sqlQuery = `
DELETE FROM public.users
WHERE spotifyid = $1;
DELETE FROM users
WHERE spotifyid = ?;
`;
client.query(sqlQuery, [data.SpotifyId], (err, res) => {
client.query(sqlQuery, [response2.data.SpotifyId], (err, res) => {
if (err) {
console.error('Error executing query', err);
return;
@ -64,13 +63,12 @@ app.get('/settings/deactivate', async (req,res) => {
})
app.get('/', async (req, res) => {
const client = new Client({
const client = mariadb.createPool({
host: 'felixmielcarek-bigbrotherdb',
user: process.env.POSTGRES_USER,
database: process.env.POSTGRES_DATABASE,
password: process.env.POSTGRES_PASSWORD,
port: 5432
})
user: process.env.MARIADB_USER,
database: process.env.MARIADB_DATABASE,
password: process.env.MARIADB_PASSWORD
});
const code = req.query.code;
@ -96,14 +94,14 @@ app.get('/', async (req, res) => {
RefreshToken: refreshToken
};
await client.connect()
await client.getConnection()
const sqlQuery = `
INSERT INTO public.users (spotifyid,accesstoken,refreshtoken)
VALUES ($1,$2,$3)
ON CONFLICT (spotifyid) DO UPDATE SET
accesstoken = EXCLUDED.accesstoken,
refreshtoken = EXCLUDED.refreshtoken
INSERT INTO users (spotifyid, accesstoken, refreshtoken)
VALUES (?, ?, ?)
ON DUPLICATE KEY UPDATE
accesstoken = VALUES(accesstoken),
refreshtoken = VALUES(refreshtoken);
`;
client.query(sqlQuery, [data.SpotifyId, data.AccessToken, data.RefreshToken], (err, res) => {

@ -1,8 +1,8 @@
import os
with open('.env', 'w') as f:
f.write("POSTGRES_USER={}\n".format(os.getenv('POSTGRES_USER')))
f.write("POSTGRES_PASSWORD={}\n".format(os.getenv('POSTGRES_PASSWORD')))
f.write("POSTGRES_DATABASE={}\n".format(os.getenv('POSTGRES_DATABASE')))
f.write("MARIADB_USER={}\n".format(os.getenv('MARIADB_USER')))
f.write("MARIADB_PASSWORD={}\n".format(os.getenv('MARIADB_PASSWORD')))
f.write("MARIADB_DATABASE={}\n".format(os.getenv('MARIADB_DATABASE')))
f.write("CLIENT_ID={}\n".format(os.getenv('CLIENT_ID')))
f.write("CLIENT_SECRET={}\n".format(os.getenv('CLIENT_SECRET')))

@ -3,13 +3,14 @@ import mariadb
env_user = os.getenv('MARIADB_USER')
env_password = os.getenv('MARIADB_PASSWORD')
env_database = os.getenv('MARIADB_DATABASE')
def executeDBQuery(query):
conn = mariadb.connect(
user=env_user,
password=env_password,
host="felixmielcarek-bigbrotherdb",
database="bigbrother"
database=env_database
)
conn.autocommit = True
cur = conn.cursor()

@ -1,6 +1,6 @@
//#region REQUIRE
const axios = require('axios');
const { Client } = require('pg');
const mariadb = require('mariadb');
//#endregion
//#region CONSTANTS
@ -8,13 +8,12 @@ const spotifyRequestsLimit = 50;
const thresholdLove = 0.6;
const clientId = process.env.CLIENT_ID;
const clientSecret = process.env.CLIENT_SECRET;
const client = new Client({
const client = mariadb.createPool({
host: 'felixmielcarek-bigbrotherdb',
user: process.env.POSTGRES_USER,
database: process.env.POSTGRES_DATABASE,
password: process.env.POSTGRES_PASSWORD,
port: 5432
})
user: process.env.MARIADB_USER,
database: process.env.MARIADB_DATABASE,
password: process.env.MARIADB_PASSWORD
});
//#endregion
//#region STRUCTURE
@ -177,10 +176,10 @@ async function mainAlgorithm(accessToken) {
}
async function main() {
await client.connect();
await client.getConnection();
try {
const selectQuery = 'SELECT * FROM public.users';
const selectQuery = 'SELECT * FROM users';
const selectResult = await client.query(selectQuery);
for(let row of selectResult.rows) {
@ -206,9 +205,9 @@ async function main() {
const newRefreshToken = response.data.refresh_token;
const updateQuery = `
UPDATE public.users
SET accesstoken = $2, refreshtoken = $3
WHERE spotifyid = $1;
UPDATE users
SET accesstoken = ?, refreshtoken = ?
WHERE spotifyid = ?;
`;
await client.query(updateQuery, [spotifyId, newAccessToken, newRefreshToken])

Loading…
Cancel
Save