Skip to content
Snippets Groups Projects
Commit 94f4d94d authored by Tim Repke's avatar Tim Repke
Browse files

Merge branch 'server-deployment' into 'master'

Server deployment

See merge request !14
parents a4b89fb3 96894f09
No related branches found
No related tags found
2 merge requests!15Master,!14Server deployment
Pipeline #1014 passed
.idea
config/
venv/
p.py
__pycache__
/hypercorn.access
/hypercorn.error
.pyc
server.md
\ No newline at end of file
# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Python.gitlab-ci.yml
# Official language image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/python/tags/
image: python:latest
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
......@@ -23,8 +13,14 @@ cache:
- .cache/pip
- venv/
stages:
- build
- test
- deploy
build-job:
stage: build
image: python:latest
script:
- python -V
- pip install virtualenv
......@@ -38,24 +34,65 @@ build-job:
test-job1:
stage: test
image: python:latest
script:
- source venv/bin/activate
- flake8 --config .flake8
test-job2:
stage: test
image: python:latest
script:
- source venv/bin/activate
- mypy --config-file=pyproject.toml server
#pages:
# script:
# - pip install sphinx sphinx-rtd-theme
# - cd doc ; make html
# - mv build/html/ ../public/
# artifacts:
# paths:
# - public
# rules:
# - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
deploy-to-production:
stage: deploy
tags:
- bare-metal
script:
- echo "Current working directory and user"
- pwd
- whoami
- groups
- echo $HOME
- echo "Reset git config"
- rm /home/gitlab-runner/.gitconfig
- git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.pik-potsdam.de/".insteadOf "ssh://git@gitlab.pik-potsdam.de/"
- git config --global user.name gitlab-runner
- git config --global user.email gitlab-runner@gitlab.pik-potsdam.de
- git config --global -l --show-origin
- echo "Go to deployment location"
- cd /home/nacsos/nacsos-core
- ls -lisah
- sudo chown -R gitlab-runner /home/nacsos/nacsos-core
- sudo chgrp -R gitlab-runner /home/nacsos/nacsos-core
- ls -lisah
- echo "Stopping NACSOS-core service"
- sudo systemctl stop nacsos-core.service
- echo "Dropping virtual environment"
- rm -rf venv
- echo "Fetching updated source"
- git stash # "reset" softly by stashing (in case files changed)
- git pull origin production # pull from origin (production branch)
- echo "Creating new virtual environment"
- python3.10 -m venv venv
- source venv/bin/activate
- echo "Installing requirements"
- pip install -r requirements.txt
- echo "Handling migrations"
- pip install alembic
- cd /home/nacsos/nacsos-core/venv/src/nacsos-data/
- alembic upgrade head
- sudo chown -R nacsos /home/nacsos/nacsos-core
- sudo chgrp -R nacsos /home/nacsos/nacsos-core
- echo "Starting NACSOS-core service"
- sudo systemctl start nacsos-core.service
# DEPRECATED
# - echo "Run as nacsos user"
# - sudo -u nacsos bash ./deploy.sh $CI_JOB_TOKEN
# - echo "Becoming 'nacsos' user"
# - sudo -u nacsos -s
when: manual
only:
- production
......@@ -3,6 +3,10 @@ This repository contains the core data management platform of NACSOS.
It accesses the database via the `nacsos-data` package and exposes the functionality via an API.
It also serves the web frontend.
```
pg_dump -d nacsos_core -h localhost -U root -W -p 5432 > dump.sql
```
## Installation
- Requires Python 3.10+, tested with Python 3.10.2
......
......@@ -9,4 +9,4 @@ httpx[http2]==0.23.1
pymitter==0.4.0
uvicorn==0.20.0
python-multipart==0.0.5
-e git+ssh://git@gitlab.pik-potsdam.de/mcc-apsis/nacsos/nacsos-data.git@d98b527cada27517332d195028d9bacea93844f5#egg=nacsos_data
-e git+ssh://git@gitlab.pik-potsdam.de/mcc-apsis/nacsos/nacsos-data.git@e9713a94c7a50484c9a204c5514cfdea7d962694#egg=nacsos_data
......@@ -17,7 +17,7 @@ mimetypes.init()
logger = get_logger('nacsos.server')
app = FastAPI()
app = FastAPI(openapi_url=settings.SERVER.OPENAPI_FILE)
logger.debug('Setting up server and middlewares')
mimetypes.add_type('application/javascript', '.js')
......@@ -43,5 +43,5 @@ app.mount('/', StaticFiles(directory=settings.SERVER.STATIC_FILES, html=True), n
@app.on_event("startup")
def on_startup():
db_engine.startup()
async def on_startup():
await db_engine.startup()
from pydantic import BaseModel
from sqlalchemy import select
from sqlalchemy.orm import load_only
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.ext.asyncio import AsyncSession # noqa: F401
from fastapi import APIRouter, Depends, HTTPException, status as http_status, Query
from nacsos_data.db.schemas import \
......
......@@ -20,6 +20,7 @@ class ServerConfig(BaseModel):
DEBUG_MODE: bool = False # set this to true in order to get more detailed logs
WORKERS: int = 2 # number of worker processes
STATIC_FILES: str = '../nacsos-web/dist/' # path to the static files to be served
OPENAPI_FILE: str = '/openapi.json' # absolute URL path to openapi.json file
HASH_ALGORITHM: str = 'HS256'
SECRET_KEY: str = secrets.token_urlsafe(32)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment