Skip to content

Commit

Permalink
Rebuilding project structure from scratch (#1976)
Browse files Browse the repository at this point in the history
  • Loading branch information
hnthh authored Oct 30, 2023
1 parent 6c45997 commit 8a1ade3
Show file tree
Hide file tree
Showing 836 changed files with 6,047 additions and 2,837 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ venv/
storage/
.vscode/
.env
.git
tests/
42 changes: 42 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: build

runs:
using: composite

steps:
- name: load cached poetry installation
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local
key: poetry-v1-${{ hashFiles('pyproject.toml') }}

- name: install poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
version: 1.6.1

- name: install python
id: setup-python
uses: actions/setup-python@v4
with:
cache: 'poetry'
python-version-file: 'pyproject.toml'

- name: make sure poetry lockfile is up to date
run: poetry check --lock && echo Lockfile is ok, $(poetry --version)
shell: bash

- name: save python version to the env
run: echo "python-version=${{ steps.setup-python.outputs.python-version }}" >> $GITHUB_ENV
shell: bash

- name: install deps
if: steps.setup-python.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
shell: bash

- name: restore default environment
run: cp src/core/.env.ci src/core/.env
shell: bash
121 changes: 48 additions & 73 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,35 @@
---
name: CI


on:
push:
branches:
- master
pull_request:

jobs:
build:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: checkout
uses: actions/checkout@v3

- uses: actions/setup-python@v4
id: setup-python
with:
python-version-file: '.python-version'
- name: build
uses: ./.github/actions/build

- uses: actions/cache@v3
id: cache-dependencies
- name: restore mypy cache
uses: actions/cache@v3
with:
path: |
venv
key: ${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/*requirements.txt') }}

- name: Install dependencies
if: steps.cache-dependencies.outputs.cache-hit != 'true'
run: |
python -m venv venv
. venv/bin/activate
pip install --upgrade pip pip-tools
pip-sync requirements.txt dev-requirements.txt
- name: Run the linter
run: |
. venv/bin/activate
cp src/app/.env.ci src/app/.env
make lint
path: .mypy_cache
key: mypy-cache-${{ github.ref_name }}
restore-keys: mypy-cache-master

- name: lint
run: make lint

test:
needs: build
runs-on: ubuntu-latest
needs: lint
runs-on: ubuntu-16x
services:
postgres:
image: postgres:13.9-alpine
Expand All @@ -60,32 +50,22 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
id: setup-python
with:
python-version-file: '.python-version'
- name: build
uses: ./.github/actions/build

- uses: actions/cache@v3
- name: install locale stuff
uses: awalsh128/cache-apt-pkgs-action@v1
with:
path: |
venv
key: ${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/*requirements.txt') }}
packages: locales-all gettext
version: 1

- name: Install locale stuff
run: |
sudo apt-get update
sudo apt-get --no-install-recommends install -y locales-all gettext
- name: Run the tests
- name: test
env:
DATABASE_URL: postgres://postgres:secret@localhost:5432/postgres
REDISCLOUD_URL: redis://localhost:6379/5
run: |
. venv/bin/activate
cp src/app/.env.ci src/app/.env
make test
run: make test -e SIMULTANEOUS_TEST_JOBS=16

- name: Upload code coverage to codeclimate
- name: upload code coverage to codeclimate
uses: paambaati/codeclimate-action@v3.2.0
env:
CC_TEST_REPORTER_ID: dd4cac59d43b52ee4c29cfed9d5162098a49ff65d9e72003abc1fa65cd608f1d
Expand All @@ -97,38 +77,33 @@ jobs:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: checkout
uses: actions/checkout@v3

- uses: actions/setup-python@v4
id: setup-python
with:
python-version-file: '.python-version'
- name: build
uses: ./.github/actions/build

- name: Set up QEMU
- name: set up qemu
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
- name: set up buildx
uses: docker/setup-buildx-action@v2

- name: Store default envfironment file to be runnable at the developer machine
run: cp src/app/.env.ci src/app/.env

- name: Generate image identifier
- name: generate image identifier
id: image
uses: ASzc/change-string-case-action@v5
with:
string: ${{ github.repository_owner }}

- name: Login to GitHub Container Registry
- name: login to ghcr
uses: docker/login-action@v2
if: ${{ github.ref == 'refs/heads/master' }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build web image
- name: build web image
uses: docker/build-push-action@v3
with:
context: .
Expand All @@ -139,12 +114,12 @@ jobs:
ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-web:${{ github.sha }}
build-args: |
PYTHON_VERSION=${{ steps.setup-python.outputs.python-version }}
PYTHON_VERSION=${{ env.python-version }}
RELEASE=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build worker image
- name: build worker image
uses: docker/build-push-action@v3
with:
context: .
Expand All @@ -154,12 +129,12 @@ jobs:
ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-worker:latest
ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-worker:${{ github.sha }}
build-args: |
PYTHON_VERSION=${{ steps.setup-python.outputs.python-version }}
PYTHON_VERSION=${{ env.python-version }}
RELEASE=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build scheduler image
- name: build scheduler image
uses: docker/build-push-action@v3
with:
context: .
Expand All @@ -169,7 +144,7 @@ jobs:
ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-scheduler:latest
ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-scheduler:${{ github.sha }}
build-args: |
PYTHON_VERSION=${{ steps.setup-python.outputs.python-version }}
PYTHON_VERSION=${{ env.python-version }}
RELEASE=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
Expand All @@ -179,10 +154,10 @@ jobs:
if: github.ref == 'refs/heads/master' && github.repository_owner == 'tough-dev-school'
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: checkout
uses: actions/checkout@v3

- name: Draft Sentry release
- name: draft sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
Expand All @@ -192,37 +167,37 @@ jobs:
environment: production
finalize: false

- name: Read image identifiers
- name: read image identifiers
id: image
uses: ASzc/change-string-case-action@v5
with:
string: ${{ github.repository_owner }}

- name: Update backend image
- name: update backend image
uses: appleboy/ssh-action@v0.1.7
with:
host: ${{ secrets.DEPLOY_HOST }}
username: circle
key: ${{ secrets.DEPLOY_KEY }}
script: docker service update app_backend --image ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-web:${{ github.sha }} --with-registry-auth

- name: Update celery worker image
- name: update celery worker image
uses: appleboy/ssh-action@v0.1.7
with:
host: ${{ secrets.DEPLOY_HOST }}
username: circle
key: ${{ secrets.DEPLOY_KEY }}
script: docker service update app_worker --image ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-worker:${{ github.sha }} --with-registry-auth

- name: Update celery amocrm worker image
- name: update celery amocrm worker image
uses: appleboy/ssh-action@v0.1.7
with:
host: ${{ secrets.DEPLOY_HOST }}
username: circle
key: ${{ secrets.DEPLOY_KEY }}
script: docker service update app_amocrm-worker --image ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-worker:${{ github.sha }} --with-registry-auth

- name: Update celery scheduler image
- name: update celery scheduler image
uses: appleboy/ssh-action@v0.1.7
with:
host: ${{ secrets.DEPLOY_HOST }}
Expand All @@ -231,7 +206,7 @@ jobs:
script: |
docker service update app_scheduler --detach --image ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-scheduler:${{ github.sha }} --with-registry-auth
- name: Finalize Sentry release
- name: finalize sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
Expand Down
Loading

0 comments on commit 8a1ade3

Please sign in to comment.