From fb7f8a6334051deb1128db1aa230c0be80c795b3 Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 7 Feb 2021 20:40:59 +0000 Subject: [PATCH] adding CD to workflow --- .github/workflows/ci.yml | 52 ++++++++++++++++++++++++++++++++-------- .gitignore | 3 ++- .vscode/settings.json | 12 ++++++++++ admin.py | 47 ++++++++++++++++++------------------ pyproject.toml | 1 - requirements.txt | 33 ------------------------- 6 files changed, 80 insertions(+), 68 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 requirements.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d68ada0..0f3464a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: matrix: python-version: [3.8] poetry-version: [1.1.4] - # node: [ '10', '12' ] + # node: [ '10', '12', '14' ] os: [ubuntu-20.04, ubuntu-18.04, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: @@ -27,14 +27,6 @@ jobs: - name: Install Dependencies # PYTHON install dependencies run: poetry install - # - name: Setup node # JS setup - # uses: actions/setup-node@v2 - # with: - # node-version: ${{ matrix.node }} - - # - name: Install Node Packages # JS install - # run: npm ci - - name: Set up Cloud SDK uses: google-github-actions/setup-gcloud@master with: @@ -43,4 +35,44 @@ jobs: export_default_credentials: true - name: Run Tests # test script - run: poetry run python -m unittest discover -s tests \ No newline at end of file + run: poetry run python -m unittest discover -s tests + + # - name: Setup node # JS setup for testing + # uses: actions/setup-node@v2 + # with: + # node-version: ${{ matrix.node }} + + # - name: Install Node Packages # JS install + # run: npm ci + + deploy: + runs-on: ubuntu-20.04 + needs: build + steps: + - uses: actions/checkout@v2 # get source + + - name: Install Python 3 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Setup Node # JS setup + uses: actions/setup-node@v2 + with: + node-version: 14 + + - name: Install Node Packages # JS install + run: npm ci + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@master + with: + project_id: ${{ secrets.GCP_PROJECT_ID }} + service_account_key: ${{ secrets.GCP_SA_KEY }} + export_default_credentials: true + + - name: Deploy API to App Engine + run: python admin.py all + + - name: Deploy Cron Functions + run: python admin.py all_cron \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7fd51c9..93587b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ scratch.py service.json +requirements.txt *~* *# @@ -12,7 +13,7 @@ node_modules/ *$py.class .idea -.vscode +launch.json # C extensions *.so diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..58fed07 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + "./tests", + "-p", + "test*.py" + ], + "python.testing.pytestEnabled": false, + "python.testing.nosetestsEnabled": false, + "python.testing.unittestEnabled": true +} \ No newline at end of file diff --git a/admin.py b/admin.py index 9b1b726..969c111 100755 --- a/admin.py +++ b/admin.py @@ -23,28 +23,29 @@ class Admin(Cmd): print('>> freezing dependencies') self.export_filtered_dependencies() - print('>> backing up a directory') - os.chdir(Path(__file__).absolute().parent.parent) + # Now done via online repos, not static injection + # print('>> backing up a directory') + # os.chdir(Path(__file__).absolute().parent.parent) - print('>> deleting old deployment stage') - shutil.rmtree(stage_dir, ignore_errors=True) + # print('>> deleting old deployment stage') + # shutil.rmtree(stage_dir, ignore_errors=True) - print('>> copying main source') - shutil.copytree('playlist-manager' if Path('playlist-manager').exists() else 'Music-Tools', - stage_dir, - ignore=lambda path, contents: - contents if any(i in Path(path).parts for i in folders_to_ignore) else [] - ) + # print('>> copying main source') + # shutil.copytree('playlist-manager' if Path('playlist-manager').exists() else 'Music-Tools', + # stage_dir, + # ignore=lambda path, contents: + # contents if any(i in Path(path).parts for i in folders_to_ignore) else [] + # ) - for dependency in Admin.locals: - print(f'>> injecting {dependency}') - shutil.copytree( - Path(dependency, dependency), - Path(stage_dir, dependency) - ) + # for dependency in Admin.locals: + # print(f'>> injecting {dependency}') + # shutil.copytree( + # Path(dependency, dependency), + # Path(stage_dir, dependency) + # ) - os.chdir(stage_dir) - os.system('gcloud config set project sarsooxyz') + # os.chdir(stage_dir) + # os.system('gcloud config set project sarsooxyz') def prepare_frontend(self): print('>> building css') @@ -176,14 +177,14 @@ class Admin(Cmd): self.export_filtered_dependencies() def export_filtered_dependencies(self): - string = os.popen('poetry export -f requirements.txt').read() + string = os.popen('poetry export -f requirements.txt --without-hashes').read() depend = string.split('\n') - filtered = [i for i in depend if not any(i.startswith(local) for local in Admin.locals)] - filtered = [i for i in filtered if '==' in i] - filtered = [i[:-2] for i in filtered] # get rid of space and slash at end of line - filtered = [i.split(';')[0] for i in filtered] + # filtered = [i for i in depend if not any(i.startswith(local) for local in Admin.locals)] + # filtered = [i for i in filtered if '==' in i] + # filtered = [i[:-2] for i in filtered] # get rid of space and slash at end of line + filtered = [i.split(';')[0] for i in depend] with open('requirements.txt', 'w') as f: f.write("\n".join(filtered)) diff --git a/pyproject.toml b/pyproject.toml index e044ef2..efa4a39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,6 @@ homepage = "https://music.sarsoo.xyz/" repository = "https://github.com/Sarsoo/Music-Tools" [tool.poetry.scripts] -backend-dev = 'music.music:start' test = 'admin:test' [tool.poetry.dependencies] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index a52cbac..0000000 --- a/requirements.txt +++ /dev/null @@ -1,33 +0,0 @@ -backports-datetime-fromisoformat==1.0.0 -beautifulsoup4==4.9.3 -cachetools==4.2.1 -certifi==2020.12.5 -chardet==4.0.0 -click==7.1.2 -fireo==1.4.1 -flask==1.1.2 -google-api-core==1.25.1 -google-auth==1.24.0 -google-cloud-core==1.5.0 -google-cloud-firestore==1.9.0 -google-cloud-logging==1.15.1 -google-cloud-pubsub==1.7.0 -google-cloud-tasks==1.5.0 -googleapis-common-protos==1.52.0 -grpc-google-iam-v1==0.12.3 -grpcio==1.35.0 -idna==2.10 -itsdangerous==1.1.0 -jinja2==2.11.2 -markupsafe==1.1.1 -protobuf==3.14.0 -pyasn1-modules==0.2.8 -pyasn1==0.4.8 -pytz==2020.5 -requests==2.25.1 -rsa==4.7 -six==1.15.0 -soupsieve==2.1 -tabulate==0.8.7 -urllib3==1.26.3 -werkzeug==1.0.1 \ No newline at end of file