From 0e6588e18e3e00529f751090cb5c182b9b9c7e01 Mon Sep 17 00:00:00 2001 From: Leon Felix Klostermann Date: Wed, 26 Jun 2024 23:29:47 +0200 Subject: [PATCH] better versioning + hash files --- .github/workflows/ci.yml | 59 ++++++++++++++++++++++++++++++++++-- README.md | 4 +-- ansible_link/ansible_link.py | 14 ++++++--- ansible_link/version.py | 4 +++ 4 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 ansible_link/version.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eca42be..4b4c1e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Run Tests +name: Ansible-Link CI/CD on: push: @@ -54,4 +54,59 @@ jobs: sed -i 's/from webhook import WebhookSender/from ansible_link.webhook import WebhookSender/' ansible_link/ansible_link.py - name: Run tests run: | - python -m unittest discover tests \ No newline at end of file + python -m unittest discover tests + + build-artifact: + needs: ansible-link-ci + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.8' + - name: Get version + id: get_version + run: | + echo "VERSION=$(python -c "from ansible_link.version import VERSION; print(VERSION)")" >> $GITHUB_ENV + - name: Create zip artifact + run: | + zip -r ansible-link-${{ env.VERSION }}.zip ansible_link + - name: Create hash file + run: | + sha256sum ansible-link-${{ env.VERSION }}.zip > ansible-link-${{ env.VERSION }}.sha256 + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: ansible-link-${{ env.VERSION }} + path: | + ansible-link-${{ env.VERSION }}.zip + ansible-link-${{ env.VERSION }}.sha256 + - name: Create GitHub Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ env.VERSION }} + release_name: Release ${{ env.VERSION }} + draft: false + prerelease: false + - name: Upload Release Asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./ansible-link-${{ env.VERSION }}.zip + asset_name: ansible-link-${{ env.VERSION }}.zip + asset_content_type: application/zip + - name: Upload Hash File + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./ansible-link-${{ env.VERSION }}.sha256 + asset_name: ansible-link-${{ env.VERSION }}.sha256 + asset_content_type: text/plain \ No newline at end of file diff --git a/README.md b/README.md index 7ea338e..d7e728a 100644 --- a/README.md +++ b/README.md @@ -72,9 +72,9 @@ The API documentation is available via the Swagger UI. ## Configuration The API configuration is stored in the `config.yml` file. -If you move your config to a different location you can use `ANSIBLE_API_CONFIG` +If you move your config to a different location you can use `ANSIBLE_LINK_CONFIG_PATH` ```shell -$ export ANSIBLE_API_CONFIG='/etc/ansible-link/config.yml' +$ export ANSIBLE_LINK_CONFIG_PATH='/etc/ansible-link/config.yml' ``` You can customize the following settings: diff --git a/ansible_link/ansible_link.py b/ansible_link/ansible_link.py index 15be700..142dc51 100644 --- a/ansible_link/ansible_link.py +++ b/ansible_link/ansible_link.py @@ -7,6 +7,7 @@ from flask_restx import Api, Resource, fields from flask import Flask, request, jsonify +from .version import VERSION from webhook import WebhookSender from ansible_runner.config.runner import RunnerConfig @@ -38,12 +39,12 @@ def load_config(): current_dir = Path(__file__).parent.absolute() default_config_path = current_dir / 'config.yml' - config_path = os.environ.get('ANSIBLE_API_CONFIG', default_config_path) + config_path = os.environ.get('ANSIBLE_LINK_CONFIG_PATH', default_config_path) try: with open(config_path, 'r') as f: return yaml.safe_load(f) except Exception as e: - print(f"Failed to load configuration: {e} - is ANSIBLE_API_CONFIG set correctly?") + print(f"Failed to load configuration: {e} - is ANSIBLE_LINK_CONFIG_PATH set correctly?") raise config = load_config() @@ -268,10 +269,15 @@ def get(self, job_id): def health_check(): return jsonify({"status": "healthy"}), 200 +@app.route('/version') +def version_check(): + return jsonify({"version": VERSION}), 200 + if __name__ == '__main__': metrics_port = config.get('metrics_port', 8000) start_http_server(metrics_port) - logger.info(f"Metrics server started ({metrics_port})") + logger.info(f"Metrics server started, port {metrics_port}") + logger.info(f"Initializing Ansible-Link, version {VERSION}") - app.run(debug=config.get('debug', False), host=config.get('host', '0.0.0.0'), port=config.get('port', 5000)) + app.run(debug=config.get('debug', False), host=config.get('host', '127.0.0.1'), port=config.get('port', 5000)) diff --git a/ansible_link/version.py b/ansible_link/version.py new file mode 100644 index 0000000..3f296f1 --- /dev/null +++ b/ansible_link/version.py @@ -0,0 +1,4 @@ +VERSION = "1.2.1" + +def get_version(): + return VERSION \ No newline at end of file