Skip to content
Snippets Groups Projects
Commit 2831425b authored by Aymeric Chaumont's avatar Aymeric Chaumont
Browse files

Merge branch 'ci' into 'main'

Ci

See merge request !6
parents 150ca275 ecd78a7a
Branches
No related tags found
1 merge request!6Ci
Pipeline #43678 failed
image: python:3.9
variables:
MYSQL_DATABASE: $MYSQL_DATABASE
MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
MYSQL_USER: $MYSQL_USER
MYSQL_PASSWORD: $MYSQL_PASSWORD
MYSQL_DATABASE: $MYSQL_DATABASE
services:
- name: mysql:latest
command: ["mysqld", "--authentication-policy=mysql_native_password"]
alias: mysql
# services:
# - name: mysql:latest
# command: ["mysqld", "--authentication-policy=mysql_native_password"]
# alias: mysql
# variables:
# MYSQL_DATABASE: $MYSQL_DATABASE
# MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
# Host: mysql
# User: $MYSQL_USER
# Password: $MYSQL_PASSWORD
# Database: $MYSQL_DATABASE
# cache:
# paths:
# - .cache/pip
# - venv/
# - env/
# before_script:
# - python --version # For debugging
# - pip install venv
# - python3 -m venv /venv
# - source /venv/bin/activate
stages:
- build
- test
- deploy
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: $CI_COMMIT_BRANCH
# include:
# - template: 'Code-Quality.gitlab-ci.yml'
#######################################################################################################################################
#### ####
#### Install dependencies ####
#### ####
#######################################################################################################################################
install:
stage: build
script:
- python3 -m venv ./venv
- source ./venv/bin/activate
- pip install --upgrade pip && pip install pip-tools
- pip install -r ./backend/requirements.txt
artifacts:
paths:
- ./venv/
expire_in: 30 mins
#######################################################################################################################################
#### ####
#### Testing code integration ####
#### ####
#######################################################################################################################################
lint:
stage: test
before_script:
- source ./venv/bin/activate
- pip install pycodestyle
script:
- pycodestyle --config=./backend/setup.cnf ./backend
# test:
# stage: test
# variables:
# MYSQL_DATABASE: $MYSQL_DATABASE
# MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
# MYSQL_DATABASE: $MYSQL_DATABASE
# MYSQL_USER: $MYSQL_USER
# MYSQL_PASSWORD: $MYSQL_PASSWORD
# DB_HOST: mysql
# DB_PORT: 3306
# WEB_ROOT: http://localhost:3000
# before_script:
# - source ./venv/bin/activate
# script:
# - cd ./backend
# - docker build -t app ./backend
# - docker run --detach -p 8000:80 app --env-file ./backend/.env
# - curl "http://localhost:8000/api/health"
#######################################################################################################################################
#### ####
#### Deploy ####
#### ####
#######################################################################################################################################
.deploy:
stage: deploy
script:
# Install ssh-agent if not already installed, it is required by Docker.
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
# Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
# Add the SSH key stored in PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$PRIVATE_KEY")
# For Docker builds disable host key checking. Be aware that by adding that
# you are suspectible to man-in-the-middle attacks.
# WARNING: Use this only with the Docker executor, if you use it with shell
# you will overwrite your user's SSH config.
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
# In order to properly check the server's host key, assuming you created the
# SSH_SERVER_HOSTKEYS variable previously, uncomment the following two lines
# instead.
# - mkdir -p ~/.ssh
# - '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'
# Get build job ID from file in artifact
# - job_id=$(cat job_id)
- >
ssh "eatfast@$DOMAIN"
"cd /var/www/backend &&
git stash &&
git checkout "$CI_COMMIT_BRANCH" &&
git stash &&
git pull &&
docker-compose build &&
docker-compose up -d &&
exit"
# deploy-staging:
# extends: .deploy
# rules:
# - if: $CI_COMMIT_BRANCH == $STAGING_BRANCH
# when: always
# variables:
# DOMAIN: nofist.test.viarezo.fr
# PRIVATE_KEY: "$SSH_PRIVATE_KEY_STAGING"
deploy-prod:
extends: .deploy
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
variables:
DOMAIN: morbiustvplus.cs-campus.fr
PRIVATE_KEY: "$SSH_PRIVATE_KEY"
...@@ -18,6 +18,14 @@ Navigate to [http://localhost:3001](http://localhost:3001) ...@@ -18,6 +18,14 @@ Navigate to [http://localhost:3001](http://localhost:3001)
<br/> <br/>
### *Le linter*
So the new commits can be deployed, you'll need to use the linter from backend :
`pycodestyle --config=./setup.cnf --exclude=./env ./`
You can use autoformat with autopep8 running :
`autopep8 --in-place --global-config=./setup.cnf --recursive --exclude=./env --aggressive ./`
<br/>
## In production mode ## In production mode
Build the docker image : `docker-compose build` Build the docker image : `docker-compose build`
Run the server, `docker-compose up -d` Run the server, `docker-compose up -d`
......
...@@ -9,10 +9,15 @@ import os ...@@ -9,10 +9,15 @@ import os
# load environment variables # load environment variables
load_dotenv() load_dotenv()
SQLALCHEMY_DATABASE_URL = f"mysql+pymysql://{os.getenv('MYSQL_USER')}:{os.getenv('MYSQL_PASSWORD')}@{os.getenv('DB_HOST')}:{os.getenv('DB_PORT')}/{os.getenv('MYSQL_DATABASE')}?charset=utf8" user = os.getenv('MYSQL_USER')
password = os.getenv('MYSQL_PASSWORD')
host = os.getenv('DB_HOST')
port = os.getenv('DB_PORT')
database = os.getenv('MYSQL_DATABASE')
SQLALCHEMY_DATABASE_URL = f"mysql+pymysql://{user}:{password}@{host}:{port}/{database}?charset=utf8"
engine = create_engine(SQLALCHEMY_DATABASE_URL) engine = create_engine(SQLALCHEMY_DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base() Base = declarative_base()
...@@ -8,10 +8,13 @@ from pydantic import BaseModel, Field ...@@ -8,10 +8,13 @@ from pydantic import BaseModel, Field
class RecordBase(BaseModel): class RecordBase(BaseModel):
"""Records base schema""" """Records base schema"""
place: str = Field(..., title="Name of the RU corresponding the given record") place: str = Field(...,
title="Name of the RU corresponding the given record")
date: datetime = Field(..., title="Date of the record") date: datetime = Field(..., title="Date of the record")
density: float = Field(..., title="Estimated density of people") density: float = Field(..., title="Estimated density of people")
waiting_time: Optional[timedelta] = Field(title="Estimated waiting time for people coming at this date") waiting_time: Optional[timedelta] = Field(
title="Estimated waiting time for people coming at this date")
class Record(RecordBase): class Record(RecordBase):
"""Database records schema""" """Database records schema"""
......
...@@ -2,7 +2,7 @@ version: "3.3" ...@@ -2,7 +2,7 @@ version: "3.3"
services: services:
db: db:
image: mysql image: mysql:latest
container_name: "db" container_name: "db"
restart: always restart: always
env_file: .env env_file: .env
......
...@@ -26,6 +26,7 @@ app.add_middleware( ...@@ -26,6 +26,7 @@ app.add_middleware(
allow_headers=["*"] allow_headers=["*"]
) )
def get_db(): def get_db():
"""Create a database session.""" """Create a database session."""
db = database.SessionLocal() db = database.SessionLocal()
......
[pycodestyle]
max-line-length = 160
\ No newline at end of file
...@@ -23,6 +23,7 @@ def norm_by_imagenet(img): ...@@ -23,6 +23,7 @@ def norm_by_imagenet(img):
print('Wrong shape of the input.') print('Wrong shape of the input.')
return None return None
def fix_singular_shape(img, unit_len=16): def fix_singular_shape(img, unit_len=16):
""" """
Some network like w-net has both N maxpooling layers and concatenate layers, Some network like w-net has both N maxpooling layers and concatenate layers,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment