Skip to content

Commit

Permalink
Merge branch 'release-0.2.0' into feat/hamed-prevent-startup-migratio…
Browse files Browse the repository at this point in the history
…n-conflict-1228
  • Loading branch information
dhaselhan authored Dec 5, 2024
2 parents 33ff647 + 3219a4d commit 011013f
Show file tree
Hide file tree
Showing 73 changed files with 2,039 additions and 1,023 deletions.
31 changes: 27 additions & 4 deletions .github/workflows/prod-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,31 @@ jobs:
echo "IMAGE_TAG retrieved from Test is $imagetag"
echo "IMAGE_TAG=$imagetag" >> $GITHUB_OUTPUT
get-current-time:
name: Get Current Time
runs-on: ubuntu-latest
needs: get-image-tag

outputs:
CURRENT_TIME: ${{ steps.get-current-time.outputs.CURRENT_TIME }}

steps:
- id: get-current-time
run: |
TZ="America/Vancouver"
echo "CURRENT_TIME=$(date '+%Y-%m-%d %H:%M:%S %Z')" >> $GITHUB_OUTPUT
# Deplog the image which is running on test to prod
deploy-on-prod:

name: Deploy LCFS on Prod
runs-on: ubuntu-latest
needs: get-image-tag
needs: [get-image-tag, get-current-time]
timeout-minutes: 60

env:
IMAGE_TAG: ${{ needs.get-image-tag.outputs.IMAGE_TAG }}
CURRENT_TIME: ${{ needs.get-current-time.outputs.CURRENT_TIME }}

steps:

Expand All @@ -66,9 +81,17 @@ jobs:
uses: trstringer/[email protected]
with:
secret: ${{ github.TOKEN }}
approvers: AlexZorkin,kuanfandevops,hamed-valiollahi,airinggov,areyeslo,dhaselhan,Grulin,justin-lepitzki,kevin-hashimoto
approvers: AlexZorkin,kuanfandevops,hamed-valiollahi,airinggov,areyeslo,dhaselhan,Grulin
minimum-approvals: 2
issue-title: "LCFS ${{env.IMAGE_TAG }} Prod Deployment"
issue-title: "LCFS ${{env.IMAGE_TAG }} Prod Deployment at ${{ env.CURRENT_TIME }}."

- name: Log in to Openshift
uses: redhat-actions/[email protected]
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ env.PROD_NAMESPACE }}

- name: Tag LCFS images from Test to Prod
run: |
Expand All @@ -88,6 +111,6 @@ jobs:
git config --global user.name "GitHub Actions"
git add lcfs/charts/lcfs-frontend/values-prod.yaml
git add lcfs/charts/lcfs-backend/values-prod.yaml
git commit -m "update the version with pre-release number for prod"
git commit -m "Update image tag ${{env.IMAGE_TAG }} for prod"
git push
2 changes: 1 addition & 1 deletion .github/workflows/test-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ jobs:
uses: trstringer/[email protected]
with:
secret: ${{ github.TOKEN }}
approvers: AlexZorkin,kuanfandevops,hamed-valiollahi,airinggov,areyeslo,dhaselhan,Grulin,justin-lepitzki,kevin-hashimoto
approvers: AlexZorkin,kuanfandevops,hamed-valiollahi,airinggov,areyeslo,dhaselhan,Grulin,kevin-hashimoto
minimum-approvals: 1
issue-title: "LCFS ${{ env.VERSION }}-${{ env.PRE_RELEASE }} Test Deployment"

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ __pycache__/
*.py[cod]
*$py.class
docs/
.DS_Store

# C extensions
*.so
Expand Down
10 changes: 5 additions & 5 deletions backend/Dockerfile.openshift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Base stage for common setup
FROM artifacts.developer.gov.bc.ca/docker-remote/python:3.11-slim-bullseye as base
FROM artifacts.developer.gov.bc.ca/docker-remote/python:3.11-bullseye as base

RUN apt-get update && apt-get install -y \
RUN apt-get update && apt-get install -y --no-install-recommends procps \
gcc \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -23,9 +23,9 @@ ENV POETRY_CACHE_DIR=/.cache/pypoetry
RUN poetry install --only main

# Removing gcc
RUN apt-get purge -y \
gcc \
&& rm -rf /var/lib/apt/lists/*
# RUN apt-get purge -y \
# gcc \
# && rm -rf /var/lib/apt/lists/*

# Copying the actual application, wait-for-it script, and prestart script
COPY . /app/
Expand Down
1 change: 1 addition & 0 deletions backend/lcfs/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def main() -> None:
reload=settings.reload,
log_level=settings.log_level.value.lower(),
factory=True,
timeout_keep_alive=settings.timeout_keep_alive,
)
except Exception as e:
print(e)
Expand Down
27 changes: 13 additions & 14 deletions backend/lcfs/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from lcfs.db.models.user.UserRole import UserRole
from lcfs.db.seeders.seed_database import seed_database
from lcfs.db.utils import create_test_database, drop_test_database
from lcfs.services.redis.dependency import get_redis_pool
from lcfs.services.redis.dependency import get_redis_client
from lcfs.settings import settings
from lcfs.web.application import get_app

Expand Down Expand Up @@ -118,19 +118,20 @@ async def dbsession(


@pytest.fixture
async def fake_redis_pool() -> AsyncGenerator[ConnectionPool, None]:
async def fake_redis_client() -> AsyncGenerator[aioredis.FakeRedis, None]:
"""
Get instance of a fake redis.
Get instance of a fake Redis client.
:yield: FakeRedis instance.
:yield: FakeRedis client instance.
"""
server = FakeServer()
server.connected = True
pool = ConnectionPool(connection_class=FakeConnection, server=server)
redis_client = aioredis.FakeRedis(server=server, decode_responses=True)

yield pool

await pool.disconnect()
try:
yield redis_client
finally:
await redis_client.close()


@pytest.fixture
Expand All @@ -153,26 +154,24 @@ async def dbsession_factory(
@pytest.fixture
def fastapi_app(
dbsession: AsyncSession,
fake_redis_pool: ConnectionPool,
fake_redis_client: aioredis.FakeRedis,
set_mock_user, # Fixture for setting up mock authentication
user_roles: List[RoleEnum] = [RoleEnum.ADMINISTRATOR], # Default role
) -> FastAPI:
# Create the FastAPI application instance
application = get_app()
application.dependency_overrides[get_async_db_session] = lambda: dbsession
application.dependency_overrides[get_redis_pool] = lambda: fake_redis_pool
application.dependency_overrides[get_redis_client] = lambda: fake_redis_client

# Set up application state for testing
application.state.redis_pool = fake_redis_pool
# application.state.db_session_factory = test_session_factory
application.state.redis_client = fake_redis_client
application.state.settings = settings

# Set up mock authentication backend with the specified roles
set_mock_user(application, user_roles)

# Initialize the cache with fake Redis backend
fake_redis = aioredis.FakeRedis(connection_pool=fake_redis_pool)
FastAPICache.init(RedisBackend(fake_redis), prefix="lcfs")
FastAPICache.init(RedisBackend(fake_redis_client), prefix="lcfs")

return application

Expand Down
13 changes: 1 addition & 12 deletions backend/lcfs/db/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
async_engine = create_async_engine(db_url, future=True)
logging.getLogger("sqlalchemy.engine").setLevel(logging.WARN)


async def set_user_context(session: AsyncSession, username: str):
"""
Set user_id context for the session to be used in auditing.
Expand Down Expand Up @@ -49,15 +50,3 @@ async def get_async_db_session(request: Request) -> AsyncGenerator[AsyncSession,
raise e
finally:
await session.close() # Always close the session to free up the connection


def create_redis():
return aioredis.ConnectionPool(
host=settings.redis_host,
port=settings.redis_port,
db=settings.redis_db,
decode_responses=True,
)


pool = create_redis()
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Replace 'Other' with detailed description in 'level_of_equipment' table
Revision ID: aeaa26f5cdd5
Revises: b4da565bb711
Create Date: 2024-12-02 22:52:12.302543
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "aeaa26f5cdd5"
down_revision = "b4da565bb711"
branch_labels = None
depends_on = None


def upgrade() -> None:
# Update the 'name' column in the 'level_of_equipment' table
op.execute(
"""
UPDATE level_of_equipment
SET name = 'Other - Additional information provided in notes field'
WHERE name = 'Other'
"""
)


def downgrade() -> None:
# Revert the 'name' column update in the 'level_of_equipment' table
op.execute(
"""
UPDATE level_of_equipment
SET name = 'Other'
WHERE name = 'Other - Additional information provided in notes field'
"""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Data Fixes
Revision ID: 8491890dd688
Revises: aeaa26f5cdd5
Create Date: 2024-12-04 23:00:10.708533
"""

from alembic import op
from sqlalchemy import update

from lcfs.db.models import FuelType, AllocationTransactionType
from lcfs.db.models.fuel.FuelType import QuantityUnitsEnum

# revision identifiers, used by Alembic.
revision = "8491890dd688"
down_revision = "aeaa26f5cdd5"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.execute(
update(FuelType)
.where(FuelType.fuel_type_id == 6)
.values(units=QuantityUnitsEnum.Kilograms)
)

op.execute(
update(FuelType).where(FuelType.fuel_type_id == 20).values(fossil_derived=False)
)

# Update 'type' and 'description' in allocation_transaction_type where allocation_transaction_type_id = 2
op.execute(
update(AllocationTransactionType)
.where(AllocationTransactionType.allocation_transaction_type_id == 2)
.values(
type="Allocated to",
description="Fuel allocated to another supplier under an allocation agreement",
)
)

# Update 'type' and 'description' in allocation_transaction_type where allocation_transaction_type_id = 1
op.execute(
update(AllocationTransactionType)
.where(AllocationTransactionType.allocation_transaction_type_id == 1)
.values(
type="Allocated from",
description="Fuel allocated from another supplier under an allocation agreement",
)
)
# ### end Alembic commands ###


def downgrade() -> None:
pass
9 changes: 4 additions & 5 deletions backend/lcfs/db/seeders/common/allocation_agreement_seeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ async def seed_allocation_transaction_types(session):
allocation_transaction_types_to_seed = [
{
"allocation_transaction_type_id": 1,
"type": "Purchased",
"description": "Fuel purchased under an allocation agreement",
"type": "Allocated from",
"description": "Fuel allocated from another supplier under an allocation agreement",
"display_order": 1,
"effective_date": datetime.strptime("2012-01-01", "%Y-%m-%d").date(),
},
{
"allocation_transaction_type_id": 2,
"type": "Sold",
"description": "Fuel sold under an allocation agreement",
"type": "Allocated to",
"description": "Fuel allocated to another supplier under an allocation agreement",
"display_order": 2,
"effective_date": datetime.strptime("2012-01-01", "%Y-%m-%d").date(),
},
Expand All @@ -43,7 +43,6 @@ async def seed_allocation_transaction_types(session):
transaction_type = AllocationTransactionType(**type_data)
session.add(transaction_type)

logger.info("Successfully seeded allocation transaction types.")
except Exception as e:
context = {
"function": "seed_allocation_transaction_types",
Expand Down
Loading

0 comments on commit 011013f

Please sign in to comment.