Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unzip ibsolution file #3

Merged
merged 15 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ The pipeline sets environment variables from GitHub secrets and variables and ru

## Setup

### Running locally

If you're not using CI tooling and running the script locally you will need to set the below environment variables. There is an option to store these variables in a `.env` file which will get loaded in using `load_dotenv()` at the beginning of the script

### Configure Repo

1. Set the following git secrets in Settings > Secrets and Variables > Actions:
Expand Down
18 changes: 14 additions & 4 deletions cicd/migration_helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import requests
import logging
import json
import os
import time

import requests
import zipfile

hannahflroiter marked this conversation as resolved.
Show resolved Hide resolved
from ib_helpers import upload_chunks, read_file_through_api, package_solution, unzip_files, compile_solution, \
copy_file_within_ib, read_file_content_from_ib, get_file_metadata, create_folder_if_it_does_not_exists, \
wait_until_job_finishes
Expand Down Expand Up @@ -98,7 +100,7 @@ def compile_and_package_ib_solution(ib_host, api_token, solution_directory_path,
return compile_resp, solution_resp


def download_ibsolution(ib_host, api_token, solution_path, write_to_local=True):
def download_ibsolution(ib_host, api_token, solution_path, write_to_local=False, unzip_solution=False):
"""
Get the bytes content of an .ibsolution file

Expand All @@ -110,13 +112,21 @@ def download_ibsolution(ib_host, api_token, solution_path, write_to_local=True):
"""

# TODO: Check if file exists first
# Read in .ibsolution file
resp = read_file_through_api(ib_host, api_token, solution_path)

if write_to_local:
with open(solution_path.split('/')[-1], 'wb') as fd:
solution_name = solution_path.split('/')[-1]
with open(solution_name, 'wb') as fd:
hannahflroiter marked this conversation as resolved.
Show resolved Hide resolved
fd.write(resp.content)

if unzip_solution:
zip_path = solution_name.replace('ibsolution', 'zip')
with open(zip_path, 'wb') as fd:
hannahflroiter marked this conversation as resolved.
Show resolved Hide resolved
fd.write(resp.content)
with zipfile.ZipFile(zip_path, "r") as zip_ref:
zip_ref.extractall(zip_path[:-4])
os.remove(zip_path)
hannahflroiter marked this conversation as resolved.
Show resolved Hide resolved

return resp


Expand Down
8 changes: 6 additions & 2 deletions cicd/promote_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
from migration_helpers import download_ibsolution, compile_and_package_ib_solution, \
download_dependencies_from_dev_and_upload_to_prod

from dotenv import load_dotenv
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does load_dotenv do here?

Copy link
Collaborator Author

@hannahflroiter hannahflroiter May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will load in any environment variables stored in a .env file and if it doesn't exist does nothing, I've added a bit to the readme to explain


load_dotenv()

TARGET_IB_API_TOKEN = os.environ.get('TARGET_IB_API_TOKEN')
SOURCE_IB_API_TOKEN = os.environ.get('SOURCE_IB_API_TOKEN')

Expand Down Expand Up @@ -166,7 +170,7 @@ def copy_solution_to_working_dir(new_solution_dir):
else:
ib_solution_path = get_latest_ibsolution_path(SOURCE_IB_API_TOKEN, SOURCE_FILES_API,
SOURCE_COMPILED_SOLUTIONS_PATH)
resp = download_ibsolution(SOURCE_IB_HOST, SOURCE_IB_API_TOKEN, ib_solution_path, True)
resp = download_ibsolution(SOURCE_IB_HOST, SOURCE_IB_API_TOKEN, ib_solution_path)
target_path = os.path.join(TARGET_IB_PATH, ib_solution_path.split('/')[-1])
upload_file(TARGET_IB_HOST, TARGET_IB_API_TOKEN, target_path, resp.content)

Expand Down Expand Up @@ -198,7 +202,7 @@ def copy_solution_to_working_dir(new_solution_dir):

if args.download_ibsolution or args.local_flow or args.remote_flow:
ib_solution_path = get_latest_ibsolution_path(TARGET_IB_API_TOKEN, TARGET_FILES_API, TARGET_IB_PATH)
download_ibsolution(TARGET_IB_HOST, TARGET_IB_API_TOKEN, ib_solution_path)
download_ibsolution(TARGET_IB_HOST, TARGET_IB_API_TOKEN, ib_solution_path, write_to_local=True, unzip_solution=True)

if args.set_github_actions_env_var:
if args.local:
Expand Down
2 changes: 1 addition & 1 deletion cicd/solution_migration_udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def migrate_solution(source_ib_host, target_ib_host, source_api_token, target_ap
file_path = os.path.join(solution_build_dir_path, f'{package["name"]}-{package["version"]}.ibsolution')

# Download ibsolution from dev environment
resp = download_ibsolution(source_ib_host, source_api_token, file_path, False)
resp = download_ibsolution(source_ib_host, source_api_token, file_path)

# Upload IB Solution to Prod
solution_name = f'{package["name"]}-{package["version"]}.ibsolution'
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
requests
python-dotenv
hannahflroiter marked this conversation as resolved.
Show resolved Hide resolved
Loading