Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #86

Merged
merged 10 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/
# COPY requirements.txt /tmp/pip-tmp/
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
# && rm -rf /tmp/pip-tmp
RUN pip install -U pip pipenv

RUN pip install -U pip poetry

# Configure poetry to install packages to the global python environment
RUN poetry config virtualenvs.create false

# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends sqlite3 libmagic1
&& apt-get -y install --no-install-recommends libmagic1

# Install minio client
RUN cd /usr/local/bin && curl https://dl.min.io/client/mc/release/linux-amd64/mc -o mc
RUN chmod +x /usr/local/bin/mc

# Configure minio client
RUN mc config host add minio http://localhost:9000 minio password
57 changes: 17 additions & 40 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,22 @@
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",
"customizations": {
"vscode": {
"settings": {
"python.pythonPath": "/usr/local/bin/python",
"python.languageServer": "Pylance"
},

// Set *default* container specific settings.json values on container create.
"settings": {
"sqltools.connections": [{
"name": "Container database",
"driver": "PostgreSQL",
"previewLimit": 50,
"server": "localhost",
"port": 5432,
"database": "postgres",
"username": "postgres",
"password": "postgres"
}],
"python.pythonPath": "/usr/local/bin/python",
"python.languageServer": "Pylance",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
"python.testing.pytestPath": "/usr/local/py-utils/bin/pytest"
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-azuretools.vscode-docker",
"ms-azuretools.vscode-docker",
"dunn.redis"
]
}
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-azuretools.vscode-docker",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg",
"ms-azuretools.vscode-docker",
"dunn.redis"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
8000, // api
Expand All @@ -54,11 +30,12 @@
1025, // mailpit
8025, // mailpit-ui
9000, // minio
9001 // minio-console
9001, // minio-console
27017 // mongodb
],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pipenv install --system --dev && mc alias set local http://localhost:9000 ${MINIO_ACCESS_KEY} ${MINIO_SECRET_KEY}",
"postCreateCommand": "poetry install && mc alias set local http://localhost:9000 ${MINIO_ACCESS_KEY} ${MINIO_SECRET_KEY}",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
Expand Down
19 changes: 9 additions & 10 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,22 @@ services:
# (Adding the "ports" property to this file will not forward from a Codespace.)

environment:
DATABASE_URL: postgres://postgres:postgres@db:5432/postgres
APP_ENV: 🛠
DATABASE_URL: mongodb://admin:password@localhost:27017
API_ENV: 🛠
MINIO_ACCESS_KEY: minio
MINIO_SECRET_KEY: password

db:
image: postgres:latest
container_name: postgres
image: mongodb/mongodb-community-server:latest
container_name: mongodb
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
- mongodb-data:/data/db
environment:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
test: echo 'db.runCommand({serverStatus:1}).ok' | mongo admin -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD --quiet | grep 1
interval: 10s
timeout: 5s
retries: 5
Expand Down Expand Up @@ -93,5 +92,5 @@ services:

volumes:
redis-data:
postgres-data:
mongodb-data:
minio-data:
10 changes: 4 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
COMPOSE_PROJECT_NAME=people
APP_ENV=🛠 # options are; 🛠, 🌍
DATABASE_URL=sqlite:///tmp/people.db
GITHUB_CLIENT_ID=abc
GITHUB_CLIENT_SECRET=def
LINKEDIN_CLIENT_ID=ghi
LINKEIN_CLIENT_SECRET=jkl
API_ENV=🛠 # options are; 🛠, 🌍
DATABASE_URL=mongodb://localhost:27017
GOOGLE_CLIENT_ID=abc
GOOGLE_CLIENT_SECRET=def
MINIO_ACCESS_KEY=mno
MINIO_SECRET_KEY=pqr
MINIO_ADDRESS=localhost:9000
56 changes: 18 additions & 38 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ on:
- main

env:
DATABASE_URL: postgres://postgres:postgres@postgres:5432/test
APP_ENV: 🛠
GITHUB_CLIENT_ID: test
GITHUB_CLIENT_SECRET: test
LINKEDIN_CLIENT_ID: test
LINKEIN_CLIENT_SECRET: test
DATABASE_URL: mongodb://localhost:27017
API_ENV: 🛠
GOOGLE_CLIENT_ID: test
GOOGLE_CLIENT_SECRET: test
MINIO_ACCESS_KEY: test
MINIO_SECRET_KEY: test
PIPENV_VENV_IN_PROJECT: 1

jobs:
checks:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -28,50 +25,33 @@ jobs:
python-version: 3.12
- uses: pre-commit/action@v3.0.0

tests:
test:
runs-on: ubuntu-latest
needs: [checks]
needs: [check]

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
mongodb:
image: mongodb/mongodb-community-server:latest
ports:
- 27017:27017

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: 3.12

- name: Install pipenv
run: |
python -m pip install --upgrade pip pipenv wheel
- id: cache-pipenv
uses: actions/cache@v3
- name: Setup poetry
uses: abatilo/actions-poetry@v2
with:
path: .venv
key: pipenv-${{ hashFiles('**/Pipfile.lock') }}

poetry-version: 1.6.1
- name: Install dependencies
if: steps.cache-pipenv.outputs.cache-hit != 'true'
run: |
pipenv install --deploy --dev

run: poetry install
- name: Run tests
run: |
pipenv run pytest --cov=src
run: cd src && poetry run pytest

build_and_publish:
package:
runs-on: ubuntu-latest
needs: [tests]
needs: [test]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ WORKDIR /usr/api
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PORT 8000
ENV DATABASE_URL sqlite:///tmp/people.db

# install system dependencies
RUN apt-get update \
&& apt-get -y install gcc sqlite3 postgresql libmagic1 \
&& apt-get -y install libmagic1 \
&& apt-get clean

# install python dependencies
RUN pip install --upgrade pip pipenv
COPY Pipfile Pipfile.lock ./
RUN pipenv install --system --deploy
RUN pip install --upgrade pip poetry
COPY pyproject.toml poetry.lock ./
RUN poetry install --no-dev

# add app
COPY src .
Expand Down
8 changes: 0 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@ MIGRATION_MESSAGE ?= "initial"

server:
@cd src && uvicorn app.main:api --host 0.0.0.0 --port 8000 --reload
migration:
@cd src && aerich migrate --name ${MIGRATION_MESSAGE}
migrate:
@cd src && aerich upgrade
checks:
@pre-commit run --all
env:
@cp .env.example .env
shell:
@cd src && ipython
db-shell:
@cd src && TORTOISE_ORM=app.settings.orm.TORTOISE_ORM tortoise-cli shell
git-hook:
@pre-commit install -t pre-commit -t pre-push
reset-migrations:
@cd src && rm -rf aerich.ini migrations && aerich init -t app.settings.orm.TORTOISE_ORM && aerich init-db
35 changes: 0 additions & 35 deletions Pipfile

This file was deleted.

Loading