version v2
This commit is contained in:
Binary file not shown.
@@ -761,48 +761,6 @@ def download_docker_compose():
|
||||
else:
|
||||
content = response.text
|
||||
|
||||
# Add version.txt creation to the docker-compose content
|
||||
if commit_hash:
|
||||
# Create version information with both tag and commit hash
|
||||
version_info = {
|
||||
'tag': latest_tag or 'unknown',
|
||||
'commit': commit_hash,
|
||||
'branch': data['branch'],
|
||||
'deployed_at': datetime.utcnow().isoformat()
|
||||
}
|
||||
version_json = json.dumps(version_info, indent=2)
|
||||
|
||||
# Add a command to create version.txt with the version information
|
||||
version_command = f'echo \'{version_json}\' > /app/version.txt'
|
||||
|
||||
# Find the web service and add the command
|
||||
if 'web:' in content:
|
||||
# Add the command to create version.txt before the main command
|
||||
lines = content.split('\n')
|
||||
new_lines = []
|
||||
in_web_service = False
|
||||
command_added = False
|
||||
|
||||
for line in lines:
|
||||
new_lines.append(line)
|
||||
|
||||
if line.strip() == 'web:':
|
||||
in_web_service = True
|
||||
elif in_web_service and line.strip().startswith('command:'):
|
||||
# Add the version.txt creation command before the main command
|
||||
new_lines.append(f' - sh -c "{version_command} && {line.split("command:")[1].strip()}"')
|
||||
command_added = True
|
||||
continue
|
||||
elif in_web_service and line.strip() and not line.startswith(' ') and not line.startswith('#'):
|
||||
# We've left the web service section
|
||||
if not command_added:
|
||||
# If no command was found, add a new command section
|
||||
new_lines.append(f' command: sh -c "{version_command} && python app.py"')
|
||||
command_added = True
|
||||
in_web_service = False
|
||||
|
||||
content = '\n'.join(new_lines)
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'content': content,
|
||||
|
||||
@@ -1983,32 +1983,16 @@ def init_routes(main_bp):
|
||||
|
||||
@main_bp.route('/api/version')
|
||||
def api_version():
|
||||
version_file = os.path.join(current_app.root_path, 'version.txt')
|
||||
version = 'unknown'
|
||||
version_data = {}
|
||||
|
||||
if os.path.exists(version_file):
|
||||
with open(version_file, 'r') as f:
|
||||
content = f.read().strip()
|
||||
|
||||
# Try to parse as JSON first (new format)
|
||||
try:
|
||||
version_data = json.loads(content)
|
||||
version = version_data.get('tag', 'unknown')
|
||||
except json.JSONDecodeError:
|
||||
# Fallback to old format (just commit hash)
|
||||
version = content
|
||||
version_data = {
|
||||
'tag': 'unknown',
|
||||
'commit': content,
|
||||
'branch': 'unknown',
|
||||
'deployed_at': 'unknown'
|
||||
}
|
||||
# Get version information from environment variables
|
||||
version = os.getenv('APP_VERSION', 'unknown')
|
||||
commit = os.getenv('GIT_COMMIT', 'unknown')
|
||||
branch = os.getenv('GIT_BRANCH', 'unknown')
|
||||
deployed_at = os.getenv('DEPLOYED_AT', 'unknown')
|
||||
|
||||
return jsonify({
|
||||
'version': version,
|
||||
'tag': version_data.get('tag', 'unknown'),
|
||||
'commit': version_data.get('commit', 'unknown'),
|
||||
'branch': version_data.get('branch', 'unknown'),
|
||||
'deployed_at': version_data.get('deployed_at', 'unknown')
|
||||
'tag': version,
|
||||
'commit': commit,
|
||||
'branch': branch,
|
||||
'deployed_at': deployed_at
|
||||
})
|
||||
Reference in New Issue
Block a user