Skip to content

Commit

Permalink
[2022-11-02 13:19] Fixed image issues created by package updates (#81)
Browse files Browse the repository at this point in the history
CHANGES:
 - Version increment to 2.30.0

FIXES:
 - Fixed version fetching which broke image functionality
 - Fixed the main execution function which didn't properly work due to the 'app' object no longer being properly accessible.
Signed-off-by: Raoul Linnenbank <[email protected]>
  • Loading branch information
rflinnenbank authored Nov 2, 2022
1 parent 5706092 commit 5ab0eb1
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 48 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/release-candidate-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,7 @@ jobs:
ECR_REGISTRY: 325973380531.dkr.ecr.eu-central-1.amazonaws.com
ECR_REPOSITORY: dnb-inno-image-repository
run: |
docker build -t ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }}:${{ env.package_version }} .
docker push ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }}:${{ env.package_version }}
docker build -t ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_RC }}:${{ env.package_version }} .
docker push ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_RC }}:${{ env.package_version }}
docker build -t ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_RC }} .
docker push ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_RC }}
47 changes: 35 additions & 12 deletions .github/workflows/version-update-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,28 +149,51 @@ jobs:
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
# Create the image and upload it to Amazon ECR
- name: Build, tag, and push image to Amazon ECR
# Create the image and upload it to Amazon ECR (Uvicorn edition)
- name: Build, tag, and push image to Amazon ECR - Uvicorn
run: |
docker build -t ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }}:${{ env.package_version }} .
docker push ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }}:${{ env.package_version }}
docker build -t ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }} .
docker push ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }}
docker build --target uvicorn-image -t ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_UVICORN }}:${{ env.package_version }} .
docker push ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_UVICORN }}:${{ env.package_version }}
docker build --target uvicorn-image -t ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_UVICORN }} .
docker push ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_UVICORN }}
# Create the image and upload it to Amazon ECR (Uvicorn edition)
- name: Build, tag, and push image to Amazon ECR - Gunicorn
run: |
docker build --target gunicorn-image -t ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_GUNICORN }}:${{ env.package_version }} .
docker push ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_GUNICORN }}:${{ env.package_version }}
docker build --target gunicorn-image -t ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_GUNICORN }} .
docker push ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_GUNICORN }}
# Login to DockerHub
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Create the image and upload it to DockerHub as "latest"
- name: Build and push as latest
# Create Gunicorn image and upload as latest
- name: Gunicorn - Build and Upload to Docker (latest)
uses: docker/build-push-action@v3
with:
push: true
tags: weatherproviderapi/weather-provider-api-gunicorn:latest
target: gunicorn-image
# Create Gunicorn image and upload as version
- name: Gunicorn - Build and Upload to Docker (versioned)
uses: docker/build-push-action@v3
with:
push: true
tags: weatherproviderapi/weather-provider-api-gunicorn:${{ env.package_version }}
target: gunicorn-image
# Create Uvicorn image and upload as latest
- name: Uvicorn - Build and Upload to Docker (latest)
uses: docker/build-push-action@v3
with:
push: true
tags: weatherproviderapi/weather-provider-api:latest
# Create the image and upload it to DockerHub as version
- name: Build and push as latest
tags: weatherproviderapi/weather-provider-api-uvicorn:latest
target: uvicorn-image
# Create Uvicorn image and upload as version
- name: Uvicorn - Build and Upload to Docker (versioned)
uses: docker/build-push-action@v3
with:
push: true
tags: weatherproviderapi/weather-provider-api:${{ env.package_version }}
tags: weatherproviderapi/weather-provider-api-uvicorn:${{ env.package_version }}
target: uvicorn-image
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RUN poetry install --without dev
WORKDIR /
COPY ./weather_provider_api ./weather_provider_api
COPY ./var_maps ./var_maps
COPY ./pyproject.toml ./pyproject.toml

# *** DEV IMAGE ***
# The purpose of this image is to supply the project as an interpreter / testing ground
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "weather_provider_api"
version = "2.29.0"
version = "2.30.0"
description = "Weather Provider Libraries and API"
authors = ["Verbindingsteam", "Raoul Linnenbank <[email protected]>"]
license = "MPL-2.0"
Expand Down Expand Up @@ -29,6 +29,7 @@ gunicorn = "^20.1.0"
eccodes = "^1.5.0"
ecmwflibs = "^0.4.17"
cfgrib = "^0.9.10.2"
tomli = "^2.0.1"

[tool.poetry.group.dev.dependencies]
pytest = "^7.1.3"
Expand Down
19 changes: 16 additions & 3 deletions weather_provider_api/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import tempfile
from importlib import metadata as importlib_metadata

import tomli


class BaseConfig(object):
""" Base configuration class
Expand All @@ -23,9 +25,20 @@ class BaseConfig(object):
"APP_MAINTAINER_EMAIL", "[email protected]"
)
SHOW_MAINTAINER = os.environ.get("SHOW_MAINTAINER", False)
APP_VERSION = os.environ.get("APP_VERSION", importlib_metadata.version(__package__))
APP_V1_VERSION = os.environ.get("APP_V1_VERSION", "2.0.3")
APP_V2_VERSION = os.environ.get("APP_V1_VERSION", "2.0.3")

default_version = None
try:
default_version = importlib_metadata.version(__package__)
except importlib_metadata.PackageNotFoundError:
with open('/pyproject.toml', mode='rb') as pyproject_file:
default_version = tomli.load(pyproject_file)['tool']['poetry']['version']
finally:
if not default_version:
default_version = 'Version Unidentified'
APP_VERSION = os.environ.get("APP_VERSION", default_version)

APP_V1_VERSION = os.environ.get("APP_V1_VERSION", f"{APP_VERSION} - v1 API (1.0.3)")
APP_V2_VERSION = os.environ.get("APP_V1_VERSION", f"{APP_VERSION} - v2 API (2.0.3)")
APP_VALID_DATE = os.environ.get("APP_VALID_DATE", "2024-12-31")
NETWORK_INTERFACE = os.environ.get("NETWORK_INTERFACE", "127.0.0.1")
NETWORK_PORT = os.environ.get("NETWORK_PORT", 8080)
Expand Down
56 changes: 28 additions & 28 deletions weather_provider_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,36 @@
from weather_provider_api.versions.v1 import app as v1
from weather_provider_api.versions.v2 import app as v2

app = FastAPI(version=get_setting("APP_VERSION"), title=get_setting("APP_NAME"))

# Enable logging
initialize_logging()
logger = structlog.get_logger(__name__)
logger.info(f'--------------------------------------', datetime=datetime.utcnow())
logger.info(f'Booting Weather Provider API Systems..', datetime=datetime.utcnow())
logger.info(f'--------------------------------------', datetime=datetime.utcnow())

# Create and configure new application instance
initialize_error_handling(app)
initialize_metadata_header_middleware(app)
initialize_validation_middleware(app)
initialize_prometheus_middleware(app)

# Activate enabled API versions
mount_api_version(app, v1)
mount_api_version(app, v2)

# Redirect users to the docs
@app.get("/")
def redirect_to_docs():
redirect_url = "/api/v2/docs" # replace with docs URL or use weather_provider_api.url_path_for()
return RedirectResponse(url=redirect_url)

logger.info(f'--------------------------------------', datetime=datetime.utcnow())
logger.info(f'Finished booting; starting uvicorn...', datetime=datetime.utcnow())
logger.info(f'--------------------------------------', datetime=datetime.utcnow())

def main():
# Enable logging
initialize_logging()
logger = structlog.get_logger(__name__)
logger.info(f'--------------------------------------', datetime=datetime.utcnow())
logger.info(f'Booting Weather Provider API Systems..', datetime=datetime.utcnow())
logger.info(f'--------------------------------------', datetime=datetime.utcnow())

# Create and configure new application instance
app = FastAPI(version=get_setting("APP_VERSION"), title=get_setting("APP_NAME"))
initialize_error_handling(app)
initialize_metadata_header_middleware(app)
initialize_validation_middleware(app)
initialize_prometheus_middleware(app)

# Activate enabled API versions
mount_api_version(app, v1)
mount_api_version(app, v2)

# Redirect users to the docs
@app.get("/")
def redirect_to_docs():
redirect_url = "/api/v2/docs" # replace with docs URL or use weather_provider_api.url_path_for()
return RedirectResponse(url=redirect_url)

logger.info(f'--------------------------------------', datetime=datetime.utcnow())
logger.info(f'Finished booting; starting uvicorn...', datetime=datetime.utcnow())
logger.info(f'--------------------------------------', datetime=datetime.utcnow())

uvicorn.run(app, host="127.0.0.1", port=8080)


Expand Down
3 changes: 1 addition & 2 deletions weather_provider_api/routers/weather/utils/file_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_var_map_file_location(filename: str) -> Path:
possible_main_folders = [
Path(os.getcwd()), # Running from main folder
Path(os.getcwd()).parent, # Running from weather_provider_api folder or scripts
Path(site.getsitepackages()[-1]), # Running as package
Path(site.getsitepackages()[-1]), # Running as package
]

for folder in possible_main_folders:
Expand All @@ -42,5 +42,4 @@ def get_var_map_file_location(filename: str) -> Path:
logger.info(f'"var_maps" folder was found at: {possible_var_map_folder}')
return possible_var_map_folder.joinpath(filename)


raise FileNotFoundError

0 comments on commit 5ab0eb1

Please sign in to comment.