Skip to content

Commit

Permalink
Merge pull request #1 from CorreiaEduardo/feature/dockerfile
Browse files Browse the repository at this point in the history
Feature/dockerfile
  • Loading branch information
pedrovsbenevides authored Dec 10, 2024
2 parents 89b526f + 27ba27b commit abf10e9
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 8 deletions.
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM ubuntu:latest

COPY . /app

WORKDIR /app

RUN ln -snf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && echo $CONTAINER_TIMEZONE > /etc/timezone
ARG DEBIAN_FRONTEND=noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Install necessary packages
RUN apt-get update && \
apt-get install -y \
ca-certificates \
curl

# Install Python 3.11
RUN apt-get install build-essential dos2unix python3-full python3-dev libpq-dev -y

# Configure Poetry
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_CACHE_DIR='/var/cache/pypoetry' \
POETRY_HOME='/usr/local' \
POETRY_VERSION=1.5.1

# System deps:
RUN curl -sSL https://install.python-poetry.org | python3 -

# Install dependencies with poetry
RUN poetry install --no-root

# Startup
ENV FLASK_APP=plasticome_metadata.routes.app.py
CMD [ "flask", "run" , "-h", "metadata"]
6 changes: 3 additions & 3 deletions plasticome_metadata/models/metadata_enzyme_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ class EnzymePlasticTypes(BaseModel):
)


# database.connect()
# database.create_tables([PlasticTypes, EnzymeMetadata, EnzymePlasticTypes])
# database.close()
database.connect()
database.create_tables([PlasticTypes, EnzymeMetadata, EnzymePlasticTypes])
database.close()
6 changes: 3 additions & 3 deletions plasticome_metadata/models/user_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class PlasticomeUsers(BaseModel):
secret = CharField()


# database.connect()
# database.create_tables([PlasticomeUsers])
# database.close()
database.connect()
database.create_tables([PlasticomeUsers])
database.close()
4 changes: 3 additions & 1 deletion plasticome_metadata/routes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
save_plastic_enzyme,
)
from plasticome_metadata.controllers.user_controller import authenticate_user
from plasticome_metadata.services.user_service import create_user

load_dotenv(override=True)
result = create_user(os.getenv('PLASTICOME_USER'), os.getenv('PLASTICOME_PASSWORD'))
print(result)

server = Flask(__name__)

Expand Down Expand Up @@ -137,5 +140,4 @@ def get_plastic_enzymes_route(enzyme_id):
def delete_plastic_enzyme_route(registered_id):
return delete_plastic_enzyme(registered_id)


server.run()
2 changes: 1 addition & 1 deletion plasticome_metadata/services/user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create_user(username: str, secret: str):
hashed_secret = hash_secret(secret)

PlasticomeUsers.create(username=username, secret=hashed_secret)
return True, None
return True, 'User created successfully'
except IntegrityError:
return False, 'This username already exists'
except Exception as error:
Expand Down
18 changes: 18 additions & 0 deletions scripts/init_database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e

echo "Esperando o PostgreSQL iniciar..."
sleep 5

apt-get update && apt-get install -y lzop

if [ -f /dump/plasticome-psql-v1.sql.lzo ]; then
echo "Descompactando o dump..."
lzop -d /dump/plasticome-psql-v1.sql.lzo -c > /dump/plasticome-psql-v1.sql
echo "Restaurando o banco de dados a partir do dump..."
psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f /dump/plasticome-psql-v1.sql
echo "Restauração do banco de dados concluída!"

else
echo "Dump não encontrado em /dump/plasticome-psql-v1.sql.lzo"
fi

0 comments on commit abf10e9

Please sign in to comment.