Skip to content

Commit

Permalink
Merge pull request #3 from diverso-lab/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
drorganvidez authored Apr 7, 2024
2 parents dcfb764 + f866dd4 commit 07500de
Show file tree
Hide file tree
Showing 81 changed files with 1,605 additions and 310 deletions.
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FLASK_APP_NAME=UVLHUB.IO (dev)
FLASK_ENV=development
DOMAIN=localhost
MARIADB_HOSTNAME=db
MARIADB_PORT=3306
MARIADB_DATABASE=uvlhubdb
MARIADB_TEST_DATABASE=uvlhubdb_test
MARIADB_USER=uvlhubdb_user
MARIADB_PASSWORD=uvlhubdb_password
MARIADB_ROOT_PASSWORD=uvlhubdb_root_password
41 changes: 23 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,50 @@ name: Flask CI

on:
push:
branches: [ main ]
branches: [ main, develop ]
pull_request:
branches: [ main ]
branches: [ main, develop ]

jobs:
build:

pytest:
runs-on: ubuntu-latest

services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: fmlibrootpass
MYSQL_DATABASE: fmlibdb
MYSQL_USER: fmlibuser
MYSQL_PASSWORD: fmlibpass
MYSQL_ROOT_PASSWORD: uvlhub_root_password
MYSQL_DATABASE: uvlhubdb_test
MYSQL_USER: uvlhub_user
MYSQL_PASSWORD: uvlhub_password
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python 3.9
uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.12'

- name: Prepare environment
run: |
sed -i '/rosemary @ file:\/\/\/app/d' requirements.txt
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Tests
env:
FLASK_ENV: testing
BLUEPRINTS_DIR: app/blueprints
MARIADB_HOSTNAME: 127.0.0.1
MARIADB_PORT: 3306
MARIADB_TEST_DATABASE: uvlhubdb_test
MARIADB_USER: uvlhub_user
MARIADB_PASSWORD: uvlhub_password
run: |
export MYSQL_HOSTNAME=127.0.0.1
export MYSQL_PORT=3306
export MYSQL_DATABASE=fmlibdb
export MYSQL_USER=fmlibuser
export MYSQL_PASSWORD=fmlibpass
pytest app/tests/units.py
pytest app/blueprints/
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ __pycache__/
.idea
uploads/
app.log
.DS_Store
.DS_Store
rosemary.egg-info/
build/
.coverage
htmlcov/
.pytest_cache
venv/
37 changes: 27 additions & 10 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
# Use an official Python runtime as a parent image
FROM python:3.11-alpine
FROM python:3.12-alpine

# Install the MySQL client to be able to use it in the standby script.
RUN apk add --no-cache mysql-client
# Set this environment variable to suppress the "Running as root" warning from pip
ENV PIP_ROOT_USER_ACTION=ignore

# Install the MariaDB client to be able to use it in the standby script.
RUN apk add --no-cache mariadb-client \
&& apk add --no-cache --virtual .build-deps gcc musl-dev python3-dev libffi-dev

# Set the working directory in the container to /app
WORKDIR /app

# Copy the contents of the local app/ directory to the /app directory in the container
COPY app/ ./app

# Copy requirements.txt at the /app working directory
COPY requirements.txt .

# Copy the wait-for-db.sh script and set execution permissions
COPY --chmod=+x scripts/wait-for-db.sh ./scripts/

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Copy the init-db.sh script and set execution permissions
COPY --chmod=+x scripts/init-db.sh ./scripts/

# Copy files
COPY rosemary/ ./rosemary
COPY setup.py ./

# Copy the entrypoint script
COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh

# Update pip
RUN pip install --no-cache-dir --upgrade pip

# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt

# Make the entrypoint script executable
RUN chmod +x /usr/local/bin/entrypoint.sh

# Expose port 5000
EXPOSE 5000

# Sets the CMD command to correctly execute the wait-for-db.sh script
CMD sh ./scripts/wait-for-db.sh && flask db upgrade && flask run --host=0.0.0.0 --port=5000 --reload --debug
# Set the entrypoint to run the entrypoint script
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

# Sets the default command to start the Flask application
CMD sh /app/scripts/wait-for-db.sh && sh /app/scripts/init-db.sh && rosemary db:migrate && rosemary db:seed -y --reset && flask run --host=0.0.0.0 --port=5000 --reload --debug
5 changes: 5 additions & 0 deletions Dockerfile.mariadb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM mariadb:latest

RUN apt-get update && \
apt-get install -y mariadb-client && \
rm -rf /var/lib/apt/lists/*
25 changes: 14 additions & 11 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
# Use an official Python runtime as a parent image
FROM python:3.11-alpine
# Use an official Python runtime as a parent image, Alpine version for a lighter footprint
FROM python:3.12-alpine

# Install the MySQL client to be able to use it in the standby script.
RUN apk add --no-cache mysql-client
# Install MySQL client and temporary build dependencies
RUN apk add --no-cache mysql-client \
&& apk add --no-cache --virtual .build-deps gcc musl-dev python3-dev libffi-dev openssl-dev

# Set the working directory in the container to /app
WORKDIR /app

# Copy the contents of the local app/ directory to the /app directory in the container
COPY app/ ./app

# Copy requirements.txt at the /app working directory
# Copy requirements.txt into the working directory /app
COPY requirements.txt .

# Copy the wait-for-db.sh script and set execution permissions
COPY --chmod=+x scripts/wait-for-db.sh ./scripts/

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Update pip
RUN pip install --no-cache-dir --upgrade pip
# Install any needed packages specified in requirements.txt and upgrade pip
RUN pip install --no-cache-dir -r requirements.txt \
&& pip install --no-cache-dir --upgrade pip \
&& apk del .build-deps

# Copy the migration scripts to the /app directory in the container
COPY migrations/ ./migrations

# Expose port 5000
EXPOSE 5000

# Set environment variables for production
ENV FLASK_ENV=production

# Run the database migrations and then start the application with Gunicorn
CMD sh ./scripts/wait-for-db.sh && flask db upgrade && gunicorn --bind 0.0.0.0:5000 app:app --log-level debug --timeout 3600
CMD sh ./scripts/wait-for-db.sh && flask db upgrade && gunicorn --bind 0.0.0.0:5000 app:app --log-level info --timeout 3600
Loading

0 comments on commit 07500de

Please sign in to comment.