diff --git a/docker/Dockerfile b/docker/Dockerfile index fab29bb..03f26bf 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -13,7 +13,7 @@ RUN apt-get update && apt-get install -y \ && apt-get clean RUN git clone --branch develop ${TIRAMISU_REPO_URL} /srv/src/tiramisu -RUN git clone --branch develop ${RISOTTO_REPO_URL} /srv/src/risotto +RUN git clone --branch docker ${RISOTTO_REPO_URL} /srv/src/risotto RUN git clone --branch master ${ROUGAIL_REPO_URL} /srv/src/rougail RUN ln -s /srv/src/tiramisu/tiramisu /usr/local/lib/python3.7 @@ -21,9 +21,9 @@ RUN ln -s /srv/src/rougail/src/rougail /usr/local/lib/python3.7 RUN ln -s /srv/src/risotto/src/risotto /usr/local/lib/python3.7 RUN pip install Cheetah3 -RUN cd /srv/src/risotto && pip install -r requirements.txt +RUN cd /srv/src/risotto && pip install -r requirements.txt # Installation -RUN cp -r /srv/src/risotto/messages/ /usr/local/lib/ +RUN cp -r /srv/src/risotto/messages/ /usr/local/lib/ RUN mkdir -p /var/cache/risotto/servermodel -RUN mkdir /srv/src/risotto/database \ No newline at end of file +RUN mkdir -p /var/cache/risotto/database diff --git a/docker/README.md b/docker/README.md index fdc2e25..97e0c16 100644 --- a/docker/README.md +++ b/docker/README.md @@ -11,5 +11,4 @@ Docker-Compose ``` cd docker docker-compose up -docker-compose exec postgres /srv/src/postgres/postgres.init.sh ``` \ No newline at end of file diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 9730ee7..17a6083 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -5,18 +5,24 @@ services: context: ../ dockerfile: docker/Dockerfile volumes: - - .:/srv/src/risotto + - ../.:/srv/src/risotto ports: - "8080:8080" + depends_on: + - postgres + links: + - postgres + #command: tail -F /var/log + command: python /srv/src/risotto/script/server.py restart: unless-stopped postgres: image: postgres:11-alpine environment: POSTGRES_USER: ${POSTGRES_USER:-postgres} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres} PGDATA: /data/postgres volumes: - - ./postgres-init:/srv/src/postgres + - ./postgres-init/:/docker-entrypoint-initdb.d/ ports: - "5432:5432" restart: unless-stopped \ No newline at end of file diff --git a/docker/postgres-init/10-postgres.init.sh b/docker/postgres-init/10-postgres.init.sh new file mode 100755 index 0000000..3cdc3bb --- /dev/null +++ b/docker/postgres-init/10-postgres.init.sh @@ -0,0 +1,103 @@ +#!/bin/bash +set -e + +psql --username "$POSTGRES_USER" <<-EOSQL + CREATE ROLE risotto WITH LOGIN PASSWORD 'risotto'; + CREATE DATABASE risotto; + GRANT ALL ON DATABASE risotto TO risotto; + \c risotto + CREATE EXTENSION hstore; +EOSQL + +psql --username "risotto" --password "risotto" <<-EOSQL + -- Création de la table Source + CREATE TABLE Source ( + SourceId SERIAL PRIMARY KEY, + SourceName VARCHAR(255) NOT NULL UNIQUE, + SourceURL TEXT + ); + + -- Création de la table Release + CREATE TABLE Release ( + ReleaseId SERIAL PRIMARY KEY, + ReleaseName VARCHAR(255) NOT NULL, + ReleaseSourceId INTEGER NOT NULL, + ReleaseDistribution VARCHAR(20) CONSTRAINT releasedistribution_choice CHECK (ReleaseDistribution IN ('last', 'n-1', 'n-2')), + UNIQUE (ReleaseName, ReleaseSourceId), + UNIQUE (ReleaseDistribution, ReleaseSourceId), + FOREIGN KEY (ReleaseSourceId) REFERENCES Source(SourceId) + ); + + + -- Création de la table Servermodel + CREATE TABLE Servermodel ( + ServermodelId SERIAL PRIMARY KEY, + ServermodelName VARCHAR(255) NOT NULL, + ServermodelDescription VARCHAR(255) NOT NULL, + ServermodelParentsId INTEGER [] DEFAULT '{}', + ServermodelReleaseId INTEGER NOT NULL, + ServermodelApplicationServiceId INTEGER NOT NULL, + ServermodelUsers hstore, + UNIQUE (ServermodelName, ServermodelReleaseId) + ); + + -- Création de la table ApplicationService + CREATE TABLE ApplicationService ( + ApplicationServiceId SERIAL PRIMARY KEY, + ApplicationServiceName VARCHAR(255) NOT NULL, + ApplicationServiceDescription VARCHAR(255) NOT NULL, + ApplicationServiceReleaseId INTEGER NOT NULL, + ApplicationServiceDependencies JSON, + UNIQUE (ApplicationServiceName, ApplicationServiceReleaseId) + ); + + -- Server table creation + CREATE TABLE Server ( + ServerId SERIAL PRIMARY KEY, + ServerName VARCHAR(255) NOT NULL UNIQUE, + ServerDescription VARCHAR(255) NOT NULL, + ServerServermodelId INTEGER NOT NULL + ); + + -- User, Role and ACL table creation + + CREATE TABLE RisottoUser ( + UserId SERIAL PRIMARY KEY, + UserLogin VARCHAR(100) NOT NULL UNIQUE, + UserName VARCHAR(100) NOT NULL, + UserSurname VARCHAR(100) NOT NULL + ); + + CREATE TABLE UserRole ( + RoleId SERIAL PRIMARY KEY, + RoleUserId INTEGER NOT NULL, + RoleName VARCHAR(255) NOT NULL, + RoleAttribute VARCHAR(255), + RoleAttributeValue VARCHAR(255), + FOREIGN KEY (RoleUserId) REFERENCES RisottoUser(UserId) + ); + + CREATE TABLE URI ( + URIId SERIAL PRIMARY KEY, + URIName VARCHAR(255) NOT NULL UNIQUE + ); + + CREATE TABLE RoleURI ( + RoleName VARCHAR(255) NOT NULL, + URIId INTEGER NOT NULL, + FOREIGN KEY (URIId) REFERENCES URI(URIId), + PRIMARY KEY (RoleName, URIId) + ); + + -- Log table creation + + CREATE TABLE log( + Msg VARCHAR(255) NOT NULL, + Level VARCHAR(10) NOT NULL, + Path VARCHAR(255), + Username VARCHAR(100) NOT NULL, + Data JSON, + Date timestamp DEFAULT current_timestamp + ); + +EOSQL \ No newline at end of file diff --git a/docker/postgres-init/postgres.init.sh b/docker/postgres-init/postgres.init.sh deleted file mode 100755 index ed68bf3..0000000 --- a/docker/postgres-init/postgres.init.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -e - -psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" -h localhost <<-EOSQL - CREATE ROLE risotto WITH LOGIN PASSWORD 'risotto'; - CREATE DATABASE risotto; - GRANT ALL ON DATABASE risotto TO risotto; - CREATE EXTENSION hstore; -EOSQL diff --git a/src/risotto/config.py b/src/risotto/config.py index fc10ffa..bcff151 100644 --- a/src/risotto/config.py +++ b/src/risotto/config.py @@ -1,5 +1,5 @@ MESSAGE_ROOT_PATH = 'messages' -DATABASE_DIR = 'database' +DATABASE_DIR = '/var/cache/risotto/database' INTERNAL_USER = 'internal' CONFIGURATION_DIR = 'configurations' TEMPLATE_DIR = 'templates' diff --git a/src/risotto/register.py b/src/risotto/register.py index 4d89e99..fd6d3cf 100644 --- a/src/risotto/register.py +++ b/src/risotto/register.py @@ -249,7 +249,6 @@ class RegisterDispatcher: # valid function's arguments db_conf = get_config().get('database') - #postgres://user:pass@host:port/database?option=value. engine = db_conf.get('engine') host = db_conf.get('host') dbname = db_conf.get('dbname') @@ -257,7 +256,6 @@ class RegisterDispatcher: dbpassword = db_conf.get('password') dbport = db_conf.get('port') cfg = "{}://{}:{}@{}:{}/{}".format(engine, dbuser, dbpassword, host, dbport, dbname) - print(cfg) self.pool = await asyncpg.create_pool(cfg) async with self.pool.acquire() as connection: async with connection.transaction():