Skip to content

Commit

Permalink
feat(core): add release_asset_name to customize asset to download on …
Browse files Browse the repository at this point in the history
…update

This can be used to make ddb self-update in Ubuntu 16.04.

Use should add `core.release_asset_name: ddb-linux-older-glibc` in global
ddb configuration for this asset to be downloaded on self update.
  • Loading branch information
Toilal committed Feb 24, 2021
1 parent ed4f22a commit e2b3324
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
23 changes: 23 additions & 0 deletions ddb/feature/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
import os
import platform
from argparse import ArgumentParser
from typing import Iterable, ClassVar

import distro
from dotty_dict import Dotty

from .actions import FeaturesAction, ConfigAction, ReloadConfigAction, EjectAction, SelfUpdateAction, \
Expand Down Expand Up @@ -207,6 +209,27 @@ def _configure_defaults(self, feature_config: Dotty):
if not feature_config.get('path.ddb_home') and config.paths.ddb_home:
feature_config['path.ddb_home'] = config.paths.ddb_home

self._configure_release_asset_name_defaults(feature_config)

config.path = ConfigPaths(ddb_home=feature_config.get('path.ddb_home'),
home=feature_config.get('path.home'),
project_home=feature_config.get('path.project_home'))

def _configure_release_asset_name_defaults(self, feature_config: Dotty):
if not feature_config.get('release_asset_name'):
feature_config['release_asset_name'] = self._get_default_binary_remote_name()

@staticmethod
def _get_default_binary_remote_name():
"""
Get default binary remote name, based on current platform.
"""
if platform.system() == 'Windows':
return 'ddb-windows.exe'
if platform.system() == 'Darwin':
return 'ddb-macos'
if platform.system() == 'Linux':
if distro.id() == 'alpine':
return 'ddb-alpine'
return 'ddb-linux'
return None
26 changes: 4 additions & 22 deletions ddb/feature/core/actions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import os
import platform
import re
import shutil
import sys
Expand All @@ -10,7 +9,6 @@
from typing import Optional
from urllib.error import HTTPError

import distro
import requests
import yaml
from dotty_dict import Dotty
Expand Down Expand Up @@ -207,7 +205,7 @@ def get_binary_path():
"""
if config.cwd:
return os.path.join(config.cwd, sys.argv[0])
return sys.argv[0]
return os.path.abspath(sys.argv[0])


def get_binary_destination_path(binary_path: str):
Expand All @@ -226,22 +224,6 @@ def get_binary_destination_path(binary_path: str):
return binary_path


def get_binary_remote_name():
"""
Get binary remote name
:return:
"""
if platform.system() == 'Windows':
return 'ddb-windows.exe'
if platform.system() == 'Darwin':
return 'ddb-macos'
if platform.system() == 'Linux':
if distro.id() == 'alpine':
return 'ddb-alpine'
return 'ddb-linux'
return None


class FeaturesAction(Action):
"""
Display all features
Expand Down Expand Up @@ -654,12 +636,12 @@ def self_update_binary(github_repository, version):
if not os.access(binary_path, os.W_OK):
raise PermissionError(f"You don't have permission to write on ddb binary file. ({binary_path})")

remote_filename = get_binary_remote_name()
if not remote_filename:
release_asset_name = config.data.get('core.release_asset_name')
if not release_asset_name:
print('ddb is running from a platform that doesn\'t support binary package mode.')
return

url = 'https://github.com/{}/releases/download/v{}/{}'.format(github_repository, version, remote_filename)
url = 'https://github.com/{}/releases/download/v{}/{}'.format(github_repository, version, release_asset_name)

progress_bar = None
with requests.get(url, stream=True) as response:
Expand Down
2 changes: 2 additions & 0 deletions ddb/feature/core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ class CoreFeatureSchema(FeatureSchema):
github_repository = fields.String(required=True, default="inetum-orleans/docker-devbox-ddb")
check_updates = fields.Boolean(required=True, default=True)
required_version = fields.String(required=False, allow_none=True, default=None)
release_asset_name = fields.String(required=False, allow_none=True,
default=None) # default is set in feature _configure_defaults
1 change: 1 addition & 0 deletions docs/features/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ It also handle the two following basic commands : `ddb features` and `ddb config
| `env.available` | string[]<br>`['prod', 'stage', 'ci', 'dev']` | List of available environments. You should any new custom environment to support here before trying to set `env.current` to this custom environment.|
| `required_version` | string | Minimal required `ddb` version for the project to work properly. If `required_version` is greater than the currently running one, ddb will refuse to run until it's updated. |
| `check_updates` | boolean<br>`true` | Should check for ddb updates be enabled ? |
| `release_asset_name` | string<br>`<plaform dependent>` | [Github release](https://github.com/inetum-orleans/docker-devbox-ddb/releases) asset name to use to download ddb on `self-update` command. |
| `path.ddb_home` | string<br>`${env:HOME}/.docker-devbox/ddb` | The path where ddb is installed. |
| `path.home` | string<br>`${env:HOME}/.docker-devbox` | The path where docker devbox is installed. |
| `path.project_home` | string | The project directory. |
Expand Down

0 comments on commit e2b3324

Please sign in to comment.