Skip to content

Commit

Permalink
add anyway CI
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch committed Jan 25, 2024
1 parent 882ca30 commit 1836dcf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/anyway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ jobs:
pip install -r requirements.txt &&\
export VAULT_TOKEN="$(uci vault approle-login $VAULT_ROLE_ID $VAULT_SECRET_ID)" &&\
bin/apps.py deploy_app anyway
15 changes: 9 additions & 6 deletions bin/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from tempfile import TemporaryDirectory


ETC_DFC_DOCKER = '/etc/dfc/docker' if os.environ.get("CI") != "true" else '/tmp/dfc/docker'


@lru_cache()
def get_vault_kv_path(path):
return json.loads(subprocess.check_output([
Expand All @@ -16,17 +19,17 @@ def get_vault_kv_path(path):


def ssh_init():
if not os.path.exists('/etc/dfc/docker/id_ed25519') or not os.path.exists('/etc/dfc/docker/hostname'):
if not os.path.exists(f'{ETC_DFC_DOCKER}/id_ed25519') or not os.path.exists(f'{ETC_DFC_DOCKER}/hostname'):
data = get_vault_kv_path('projects/iac/docker-server')
hostname = data['hostname']
id_ed25519 = data['id_ed25519']
os.makedirs('/etc/dfc/docker', exist_ok=True)
with open('/etc/dfc/docker/hostname', 'w') as f:
with open(f'{ETC_DFC_DOCKER}/hostname', 'w') as f:
f.write(hostname)
with open('/etc/dfc/docker/id_ed25519', 'w') as f:
with open(f'{ETC_DFC_DOCKER}/id_ed25519', 'w') as f:
f.write(id_ed25519)
else:
with open('/etc/dfc/docker/hostname') as f:
with open(f'{ETC_DFC_DOCKER}/hostname') as f:
hostname = f.read().strip()
return hostname

Expand All @@ -35,7 +38,7 @@ def ssh(*args, check_output=False):
hostname = ssh_init()
cmd = [
'ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'LogLevel=ERROR',
'-i', '/etc/dfc/docker/id_ed25519', f'ubuntu@{hostname}', *args
'-i', f'{ETC_DFC_DOCKER}/id_ed25519', f'ubuntu@{hostname}', *args
]
if check_output:
return subprocess.check_output(cmd).decode('utf-8')
Expand Down Expand Up @@ -84,7 +87,7 @@ def scp(src, dst, stats=None):
hostname = ssh_init()
subprocess.check_call([
'scp', '-o', 'StrictHostKeyChecking=no', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'LogLevel=ERROR',
'-i', '/etc/dfc/docker/id_ed25519', src, f'ubuntu@{hostname}:{dst}'
'-i', f'{ETC_DFC_DOCKER}/id_ed25519', src, f'ubuntu@{hostname}:{dst}'
])


Expand Down

0 comments on commit 1836dcf

Please sign in to comment.