Compare commits
No commits in common. '2357d8551b2011885a9e840b1f56028794f4673b' and '11fb3b937bdb5b5dd762ef0a01f9fb86296d18af' have entirely different histories.
2357d8551b
...
11fb3b937b
@ -1,34 +0,0 @@
|
|||||||
name: Build and publish the database Docker Image
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: ['main']
|
|
||||||
|
|
||||||
env:
|
|
||||||
REGISTRY: ghcr.io
|
|
||||||
IMAGE_NAME: ${{ github.repository }}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-and-push-image:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Check out repository code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
|
||||||
uses: docker/login-action@v1
|
|
||||||
with:
|
|
||||||
registry: ghcr.io
|
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Build and push Docker image
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
with:
|
|
||||||
context: ./database
|
|
||||||
push: true
|
|
||||||
tags: ghcr.io/${{ github.repository }}-database:latest
|
|
@ -1,12 +0,0 @@
|
|||||||
FROM postgres:latest
|
|
||||||
|
|
||||||
ENV POSTGRES_DB=big-brother
|
|
||||||
ENV POSTGRES_PASSWORD=postgres
|
|
||||||
|
|
||||||
COPY init_db.py /docker-entrypoint-initdb.d/
|
|
||||||
|
|
||||||
RUN apt-get update && \
|
|
||||||
apt-get install -y python3 && \
|
|
||||||
apt install python3-psycopg2
|
|
||||||
|
|
||||||
EXPOSE 5432
|
|
@ -0,0 +1,35 @@
|
|||||||
|
import os
|
||||||
|
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=env_database
|
||||||
|
)
|
||||||
|
conn.autocommit = True
|
||||||
|
cur = conn.cursor()
|
||||||
|
cur.execute(query)
|
||||||
|
cur.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
grant_privileges_query = '''
|
||||||
|
GRANT ALL PRIVILEGES ON {database}.* TO '{user}'@'%' IDENTIFIED BY '{password}';
|
||||||
|
FLUSH PRIVILEGES;
|
||||||
|
'''.format(database=env_database, user=env_user, password=env_password)
|
||||||
|
|
||||||
|
create_table_query = '''
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
spotifyid VARCHAR(255) NOT NULL,
|
||||||
|
accesstoken VARCHAR(255),
|
||||||
|
refreshtoken VARCHAR(255),
|
||||||
|
PRIMARY KEY (spotifyid)
|
||||||
|
);
|
||||||
|
'''
|
||||||
|
|
||||||
|
executeDBQuery(create_table_query)
|
@ -1,18 +0,0 @@
|
|||||||
import psycopg2
|
|
||||||
|
|
||||||
conn = psycopg2.connect(
|
|
||||||
database="big-brother", user='postgres', password='postgres', host='127.0.0.1', port= '5432'
|
|
||||||
)
|
|
||||||
cursor = conn.cursor()
|
|
||||||
|
|
||||||
cursor.execute("DROP TABLE IF EXISTS USERS")
|
|
||||||
|
|
||||||
sql ='''CREATE TABLE USERS(
|
|
||||||
SPOTIFY_ID VARCHAR(255) PRIMARY KEY,
|
|
||||||
ACCESS_TOKEN VARCHAR(255),
|
|
||||||
REFRESH_TOKEN VARCHAR(255)
|
|
||||||
)'''
|
|
||||||
cursor.execute(sql)
|
|
||||||
print("Table created successfully........")
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
Loading…
Reference in new issue