Skip to content

Commit

Permalink
better versioning + hash files
Browse files Browse the repository at this point in the history
  • Loading branch information
lfkdev committed Jun 26, 2024
1 parent 65a8b2f commit 0e6588e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 8 deletions.
59 changes: 57 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Tests
name: Ansible-Link CI/CD

on:
push:
Expand Down Expand Up @@ -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
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 10 additions & 4 deletions ansible_link/ansible_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
4 changes: 4 additions & 0 deletions ansible_link/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
VERSION = "1.2.1"

def get_version():
return VERSION

0 comments on commit 0e6588e

Please sign in to comment.