Skip to content

Commit

Permalink
feat: switch to pipenv (#1591)
Browse files Browse the repository at this point in the history
* add devcontainer config

Signed-off-by: Aakash Singh <mail@singhaakash.dev>

* add devcontainer config

Signed-off-by: Aakash Singh <mail@singhaakash.dev>

* switch to pipenv

* fix tests

* remove test workflow restriction

* fix concurrency issue

* update deploy workflow

* revert removed step

---------

Signed-off-by: Aakash Singh <mail@singhaakash.dev>
  • Loading branch information
sainak authored Sep 12, 2023
1 parent 40a3e66 commit b5e482c
Show file tree
Hide file tree
Showing 41 changed files with 3,002 additions and 544 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.venv
.git
htmlcov
staticfiles
.coverage
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source .venv/bin/activate; unset PS1
layout pipenv
dotenv
16 changes: 13 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@

version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "Weekly"
interval: "weekly"

- package-ecosystem: "docker"
directory: "/docker"
schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
145 changes: 18 additions & 127 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
paths-ignore:
- "docs/**"

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

env:
IMAGE_NAME: care
AWS_DEFAULT_REGION: ap-south-1
Expand All @@ -24,105 +28,18 @@ env:
CONTAINER_NAME_BACKEND: "care-backend"
CONTAINER_NAME_WORKER: "care-celery-worker"
CONTAINER_NAME_CRON: "care-celery-beat"

jobs:
test:
if: github.repository == 'coronasafe/care' && (github.ref == 'refs/heads/production' || github.ref == 'refs/heads/master')
runs-on: ubuntu-latest
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/care
name: Test
services:
db:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: care
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
image: redis:alpine
ports:
- 6379:6379
localstack:
image: localstack/localstack:latest
env:
AWS_DEFAULT_REGION: ap-south-1
EDGE_PORT: 4566
SERVICES: s3
ports:
- 4566:4566
steps:
- uses: actions/checkout@v3

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

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('r*/base.txt', 'r*/production.txt', 'Dockerfile') }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Test build
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
push: false
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new

- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements/*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install binutils libproj-dev libjpeg-dev zlib1g-dev -y
pip install --upgrade pip
pip install -r requirements/local.txt
- name: Configure environment
run: |
echo "JWKS_BASE64=$(python manage.py generate_jwks)" >> $GITHUB_ENV
- name: Run celery worker for tests
run: celery -A config.celery_app worker -B --loglevel=INFO --detach

- name: Run Tests with coverage
run: coverage run manage.py test --settings=config.settings.test

- name: Generate coverage report
run: |
coverage combine || true
coverage xml
coverage report -m
- name: Upload coverage report
uses: codecov/codecov-action@v2

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
uses: ./.github/workflows/test-base.yml

build-staging:
needs: test
name: Build & Push Staging to container registries
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Docker meta
id: meta
Expand All @@ -141,14 +58,6 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('r*/base.txt', 'r*/production.txt', 'Dockerfile') }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v2
with:
Expand All @@ -166,24 +75,22 @@ jobs:
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
file: docker/prod.Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
cache-from: type=gha,scope=cached-stage
cache-to: type=gha,scope=cached-stage,mode=max

build-production:
needs: test
name: Build & Push Production to container registries
if: github.ref == 'refs/heads/production'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

- name: Docker meta
id: meta
Expand All @@ -200,17 +107,6 @@ jobs:
flavor: |
latest=false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('r*/base.txt', 'r*/production.txt', 'Dockerfile') }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v2
with:
Expand All @@ -228,16 +124,11 @@ jobs:
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
file: docker/prod.Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
cache-from: type=gha,scope=cached-stage
cache-to: type=gha,scope=cached-stage,mode=max

deploy-staging-egov:
needs: build-staging
Expand All @@ -248,7 +139,7 @@ jobs:
url: https://careapi.ohc.network
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ jobs:
- uses: actions/setup-python@v3
with:
python-version: "3.11"
cache: 'pipenv'
cache-dependency-path: |
Pipfile.lock
- name: Install pipenv
run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python

- name: Install dependencies
run: |
pip install -r requirements/docs.txt
run: pipenv sync --categories "docs"

- name: Build docs
run: |
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/test-base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test

on:
workflow_call:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

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

- name: Bake docker images
uses: docker/bake-action@v3.1.0
with:
load: true
builder: ${{ steps.buildx.outputs.name }}
set: |
*.cache-from=type=gha,scope=cached-stage
*.cache-to=type=gha,scope=cached-stage,mode=max
files: docker-compose.yaml,docker-compose.local.yaml

- name: Start services
run: docker compose -f docker-compose.yaml -f docker-compose.local.yaml up -d --no-build

- name: Check migrations
run: make checkmigration

- name: Run tests
run: make test-coverage

- name: Upload coverage report
uses: codecov/codecov-action@v3
77 changes: 6 additions & 71 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,77 +1,12 @@
name: Test
name: Test Pull Request

on:
pull_request:

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
test:
if: github.repository == 'coronasafe/care'
runs-on: ubuntu-latest
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/care
services:
db:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: care
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
image: redis:alpine
ports:
- 6379:6379
localstack:
image: localstack/localstack:latest
env:
AWS_DEFAULT_REGION: ap-south-1
EDGE_PORT: 4566
SERVICES: s3
ports:
- 4566:4566
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.x
uses: actions/setup-python@v3
with:
python-version: "3.11"
cache: "pip"

- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements/*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install system packages
run: |
sudo apt-get update
sudo apt-get install binutils libproj-dev libjpeg-dev zlib1g-dev -y
- name: Install CI dependencies
run: |
pip install --upgrade pip
pip install -r requirements/local.txt
- name: Check for missing migrations
run: |
python manage.py makemigrations --check --dry-run --noinput
- name: Configure environment
run: |
echo "JWKS_BASE64=$(python manage.py generate_jwks)" >> $GITHUB_ENV
- name: Run Tests with coverage
run: coverage run manage.py test --settings=config.settings.test --parallel=$(nproc)

- name: Generate coverage report
run: |
coverage combine || true
coverage xml
coverage report -m
uses: ./.github/workflows/test-base.yml
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ tags
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ss]cripts
pyvenv.cfg
pip-selfcheck.json
.env
Expand Down
Loading

0 comments on commit b5e482c

Please sign in to comment.