Compare commits
8 Commits
11fb3b937b
...
2357d8551b
Author | SHA1 | Date |
---|---|---|
|
2357d8551b | 11 months ago |
|
d60e039c79 | 11 months ago |
|
70df62db1b | 11 months ago |
|
1cc80312dd | 11 months ago |
|
4f3062b71c | 11 months ago |
|
4a38ce4e7b | 11 months ago |
![]() |
b5b1753d7d | 11 months ago |
|
8e9a11f08f | 11 months ago |
@ -0,0 +1,34 @@
|
||||
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
|
@ -0,0 +1,12 @@
|
||||
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
|
@ -1,35 +0,0 @@
|
||||
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)
|
@ -0,0 +1,18 @@
|
||||
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