Version file added dynamically (workaround as uv does not have this feature yet)
Tag container image with playbook Importable module with python -m treetrail
This commit is contained in:
parent
2d0b788728
commit
1693662e75
11 changed files with 66 additions and 29 deletions
|
@ -84,6 +84,8 @@ jobs:
|
||||||
- name: Build the container image
|
- name: Build the container image
|
||||||
if: fromJSON(steps.builder.outputs.run)
|
if: fromJSON(steps.builder.outputs.run)
|
||||||
uses: actions/buildah-build@v1
|
uses: actions/buildah-build@v1
|
||||||
|
env:
|
||||||
|
VERSION: ${{ steps.version.outputs.version }}
|
||||||
with:
|
with:
|
||||||
image: treetrail-backend
|
image: treetrail-backend
|
||||||
oci: true
|
oci: true
|
||||||
|
@ -91,6 +93,8 @@ jobs:
|
||||||
tags: ${{ steps.version.outputs.version }}
|
tags: ${{ steps.version.outputs.version }}
|
||||||
containerfiles: |
|
containerfiles: |
|
||||||
./Containerfile
|
./Containerfile
|
||||||
|
build-arg: |
|
||||||
|
"VERSION=$VERSION"
|
||||||
|
|
||||||
- name: Push the image to the registry
|
- name: Push the image to the registry
|
||||||
if: fromJSON(steps.builder.outputs.run)
|
if: fromJSON(steps.builder.outputs.run)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
FROM tiptop:5000/treetrail-backend-deps
|
FROM tiptop:5000/treetrail-backend-deps
|
||||||
|
|
||||||
ENV PYTHONPATH $UV_PROJECT_ENVIRONMENT/lib/python3.12/site-packages
|
ENV PYTHONPATH $UV_PROJECT_ENVIRONMENT/lib/python3.12/site-packages
|
||||||
|
ARG APP_VERSION=0.0.0
|
||||||
|
|
||||||
COPY . /src
|
COPY . /src
|
||||||
|
|
||||||
|
@ -15,6 +16,8 @@ RUN uv pip install \
|
||||||
--no-deps \
|
--no-deps \
|
||||||
/src
|
/src
|
||||||
|
|
||||||
|
RUN echo $APP_VERSION > /app/version.txt
|
||||||
|
|
||||||
CMD [ \
|
CMD [ \
|
||||||
"uvicorn", "treetrail.application:app", \
|
"uvicorn", "treetrail.application:app", \
|
||||||
"--port", "8081", \
|
"--port", "8081", \
|
||||||
|
|
14
build.yaml
14
build.yaml
|
@ -1,8 +1,7 @@
|
||||||
- name: Build containers
|
- name: Build containers images
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
vars:
|
vars:
|
||||||
force: false
|
|
||||||
force_rm: false
|
force_rm: false
|
||||||
cache: false
|
cache: false
|
||||||
repository: tiptop:5000
|
repository: tiptop:5000
|
||||||
|
@ -31,9 +30,15 @@
|
||||||
push_args:
|
push_args:
|
||||||
dest: "{{ repository }}/treetrail-backend-deps"
|
dest: "{{ repository }}/treetrail-backend-deps"
|
||||||
|
|
||||||
|
- name: Get the version from git
|
||||||
|
command: git describe --dirty --tags
|
||||||
|
register: version
|
||||||
|
args:
|
||||||
|
chdir: "{{ playbook_dir }}"
|
||||||
|
|
||||||
- name: Build the backend container image
|
- name: Build the backend container image
|
||||||
containers.podman.podman_image:
|
containers.podman.podman_image:
|
||||||
name: treetrail-backend
|
name: "treetrail-backend:{{ version.stdout }}"
|
||||||
state: build
|
state: build
|
||||||
force: true
|
force: true
|
||||||
path: "{{ playbook_dir }}"
|
path: "{{ playbook_dir }}"
|
||||||
|
@ -42,6 +47,7 @@
|
||||||
force_rm: "{{ force_rm }}"
|
force_rm: "{{ force_rm }}"
|
||||||
cache: "{{ cache }}"
|
cache: "{{ cache }}"
|
||||||
file: Containerfile
|
file: Containerfile
|
||||||
|
extra_args: "--build-arg APP_VERSION={{ version.stdout }}"
|
||||||
push: true
|
push: true
|
||||||
push_args:
|
push_args:
|
||||||
dest: "{{ repository }}/treetrail-backend"
|
dest: "{{ repository }}/treetrail-backend:{{ version.stdout }}"
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
[project]
|
[project]
|
||||||
name = "treetrail-backend"
|
name = "treetrail-backend"
|
||||||
version = "0.3.0"
|
version = "0.0.0"
|
||||||
#dynamic = ["version"]
|
|
||||||
#dynamic = ["version"]
|
#dynamic = ["version"]
|
||||||
description = "A fun and pedagogic tool to discover the trails and trees around"
|
description = "A fun and pedagogic tool to discover the trails and trees around"
|
||||||
authors = [
|
authors = [
|
||||||
|
|
3
src/treetrail/__init__.py
Normal file
3
src/treetrail/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from treetrail.utils import get_version
|
||||||
|
|
||||||
|
__version__ = get_version()
|
3
src/treetrail/__main__.py
Normal file
3
src/treetrail/__main__.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from .application import _main
|
||||||
|
|
||||||
|
_main()
|
|
@ -1 +0,0 @@
|
||||||
__version__ = '0.3.0'
|
|
|
@ -36,7 +36,8 @@ from treetrail.models import (BaseMapStyles, User, Role, Bootstrap,
|
||||||
MapStyle, Tree, Trail,
|
MapStyle, Tree, Trail,
|
||||||
TreeTrail, POI, UserWithRoles, Zone,
|
TreeTrail, POI, UserWithRoles, Zone,
|
||||||
VersionedComponent)
|
VersionedComponent)
|
||||||
from treetrail.config import conf, get_cache_dir, __version__
|
from treetrail.config import conf, get_cache_dir
|
||||||
|
from treetrail import __version__
|
||||||
from treetrail.plantekey import get_local_details
|
from treetrail.plantekey import get_local_details
|
||||||
from treetrail.tiles import registry as tilesRegistry
|
from treetrail.tiles import registry as tilesRegistry
|
||||||
|
|
||||||
|
|
|
@ -51,22 +51,7 @@ app.mount(
|
||||||
def _main(argv=None):
|
def _main(argv=None):
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
arg_parser = ArgumentParser(
|
arg_parser = ArgumentParser(
|
||||||
description="fastapi Application server",
|
description="Treetrail backend / server",
|
||||||
prog="fastapi"
|
|
||||||
)
|
|
||||||
arg_parser.add_argument(
|
|
||||||
'--path',
|
|
||||||
help='Path of socket file',
|
|
||||||
)
|
|
||||||
arg_parser.add_argument(
|
|
||||||
"-H", "--hostname",
|
|
||||||
help="TCP/IP hostname to serve on (default: %(default)r)",
|
|
||||||
default="localhost"
|
|
||||||
)
|
|
||||||
arg_parser.add_argument(
|
|
||||||
"-P", "--port",
|
|
||||||
help="TCP/IP port to serve on",
|
|
||||||
type=int,
|
|
||||||
)
|
)
|
||||||
arg_parser.add_argument(
|
arg_parser.add_argument(
|
||||||
"-c", "--create-db",
|
"-c", "--create-db",
|
||||||
|
@ -154,6 +139,11 @@ def _main(argv=None):
|
||||||
help="Set debug logging",
|
help="Set debug logging",
|
||||||
action="store_true"
|
action="store_true"
|
||||||
)
|
)
|
||||||
|
arg_parser.add_argument(
|
||||||
|
"--version",
|
||||||
|
help="Print version and exit",
|
||||||
|
action="store_true"
|
||||||
|
)
|
||||||
args = arg_parser.parse_args()
|
args = arg_parser.parse_args()
|
||||||
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
|
@ -161,6 +151,11 @@ def _main(argv=None):
|
||||||
## For ipdb:
|
## For ipdb:
|
||||||
logging.getLogger('parso').setLevel(logging.WARNING)
|
logging.getLogger('parso').setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
if args.version:
|
||||||
|
import treetrail
|
||||||
|
print(treetrail.__version__)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if args.create_db:
|
if args.create_db:
|
||||||
from treetrail.database import create_db
|
from treetrail.database import create_db
|
||||||
import asyncio
|
import asyncio
|
||||||
|
@ -233,7 +228,8 @@ def _main(argv=None):
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
'This application needs to be run with an asgi server like uvicorn.',
|
'No CLI option was given, try --help',
|
||||||
|
'To run the server, use an asgi server like uvicorn.',
|
||||||
'For example:',
|
'For example:',
|
||||||
'uvicorn application:app',
|
'uvicorn application:app',
|
||||||
'or:',
|
'or:',
|
||||||
|
|
|
@ -12,8 +12,6 @@ from pydantic_settings import (
|
||||||
)
|
)
|
||||||
from pydantic.v1.utils import deep_update
|
from pydantic.v1.utils import deep_update
|
||||||
|
|
||||||
from treetrail._version import __version__
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
ENV = environ.get("env", "prod")
|
ENV = environ.get("env", "prod")
|
||||||
|
@ -163,9 +161,9 @@ class Config(MyBaseSettings):
|
||||||
tiles: Tiles = Tiles()
|
tiles: Tiles = Tiles()
|
||||||
security: Security = Security()
|
security: Security = Security()
|
||||||
geo: Geo = Geo()
|
geo: Geo = Geo()
|
||||||
version: str
|
version: str = '-'
|
||||||
db: DB = DB()
|
db: DB = DB()
|
||||||
base_href: str = "/treetrail"
|
base_href: str = "/treetrail"
|
||||||
|
|
||||||
|
|
||||||
conf = Config(version=__version__) # type: ignore
|
conf = Config()
|
||||||
|
|
|
@ -84,3 +84,28 @@ def mkdir(dir: Path | str) -> Path:
|
||||||
logger.info(f'Create directory {path}')
|
logger.info(f'Create directory {path}')
|
||||||
path.mkdir(parents=True, exist_ok=True)
|
path.mkdir(parents=True, exist_ok=True)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
def get_version() -> str:
|
||||||
|
version_file_src = Path(__file__).parent / 'version.txt'
|
||||||
|
version_file_in_container = Path("/app") / 'version.txt'
|
||||||
|
if version_file_src.exists():
|
||||||
|
with open(version_file_src) as version:
|
||||||
|
return version.read().strip()
|
||||||
|
if version_file_in_container.exists():
|
||||||
|
with open(version_file_in_container) as version:
|
||||||
|
return version.read().strip()
|
||||||
|
else:
|
||||||
|
logger.debug('No version file, using git')
|
||||||
|
try:
|
||||||
|
from subprocess import run
|
||||||
|
git_version_cmd = run(['git', 'describe', '--broken', '--tags', '--always', '--dirty'],
|
||||||
|
capture_output=True)
|
||||||
|
if git_version_cmd.returncode == 0:
|
||||||
|
return git_version_cmd.stdout.strip().decode()
|
||||||
|
else:
|
||||||
|
logger.debug('git returns with the error below, version set as 0.0.0')
|
||||||
|
logger.debug(git_version_cmd.stderr.decode())
|
||||||
|
return '0.0.0'
|
||||||
|
except FileNotFoundError as err:
|
||||||
|
logger.debug('git not found: version set as 0.0.0')
|
||||||
|
return '0.0.0'
|
Loading…
Add table
Add a link
Reference in a new issue