From 68f454853c071587695a74024761c34698962eb3 Mon Sep 17 00:00:00 2001 From: saul Date: Mon, 7 Aug 2023 16:34:20 -0500 Subject: [PATCH 01/24] Adding first draft of the workflow, checking if estela-web folder changed --- .github/workflows/pr-preview-estela-web.yaml | 33 ++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/pr-preview-estela-web.yaml diff --git a/.github/workflows/pr-preview-estela-web.yaml b/.github/workflows/pr-preview-estela-web.yaml new file mode 100644 index 00000000..bc7cb3f6 --- /dev/null +++ b/.github/workflows/pr-preview-estela-web.yaml @@ -0,0 +1,33 @@ +name: Build and Deploy estela-web +on: + pull_request: + +env: + WEB_DIRECTORY: estela-web + +jobs: + pre_processing: + runs-on: ubuntu-latest + name: Test changed files + outputs: + web_changed: ${{ steps.changed-estela-web-files.outputs.any_changed }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Check if estela-web directory changed + id: changed-estela-web-files + uses: tj-actions/changed-files@v37 + with: + files: estela-web + + build_web: + needs: pre_processing + runs-on: ubuntu-latest + name: Build web + steps: + - name: Web changed + env: + web_changed: ${{ needs.pre_processing.outputs.web_changed }} + if: ${{ env.web_changed }} == 'true' + run: echo "estela-web changed!" From a7d69177cdac8771d1407fd196d6edcf23b3649e Mon Sep 17 00:00:00 2001 From: saul Date: Mon, 7 Aug 2023 16:45:00 -0500 Subject: [PATCH 02/24] Stop build_web job whenever estela-web/** files doesn't change --- .github/workflows/pr-preview-estela-web.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-preview-estela-web.yaml b/.github/workflows/pr-preview-estela-web.yaml index bc7cb3f6..93ea46e1 100644 --- a/.github/workflows/pr-preview-estela-web.yaml +++ b/.github/workflows/pr-preview-estela-web.yaml @@ -23,11 +23,12 @@ jobs: build_web: needs: pre_processing + if: ${{ needs.pre_processing.outputs.web_changed }} == 'true' runs-on: ubuntu-latest name: Build web + env: + web_changed: ${{ needs.pre_processing.outputs.web_changed }} steps: - name: Web changed - env: - web_changed: ${{ needs.pre_processing.outputs.web_changed }} - if: ${{ env.web_changed }} == 'true' - run: echo "estela-web changed!" + run: | + echo "estela-web changed status: ${{ env.web_changed }}!" From 7a5f127c005a2bad75a77e1959abd083d18e681a Mon Sep 17 00:00:00 2001 From: saul Date: Mon, 7 Aug 2023 16:52:41 -0500 Subject: [PATCH 03/24] Update build_web job execution if statement --- .github/workflows/pr-preview-estela-web.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-preview-estela-web.yaml b/.github/workflows/pr-preview-estela-web.yaml index 93ea46e1..753b330f 100644 --- a/.github/workflows/pr-preview-estela-web.yaml +++ b/.github/workflows/pr-preview-estela-web.yaml @@ -22,10 +22,10 @@ jobs: files: estela-web build_web: + if: needs.pre_processing.outputs.web_changed == 'true' + name: Build web needs: pre_processing - if: ${{ needs.pre_processing.outputs.web_changed }} == 'true' runs-on: ubuntu-latest - name: Build web env: web_changed: ${{ needs.pre_processing.outputs.web_changed }} steps: From 734c34694db3ca13be6f17f16043a42103102db1 Mon Sep 17 00:00:00 2001 From: saul Date: Mon, 7 Aug 2023 16:54:16 -0500 Subject: [PATCH 04/24] Testing estela-web changed build_web job --- estela-web/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/estela-web/README.md b/estela-web/README.md index c704239a..d4deefe2 100644 --- a/estela-web/README.md +++ b/estela-web/README.md @@ -16,3 +16,4 @@ This module introduces users with a friendly interface that interacts with the [ This module allows users to **manage** their scraping projects and data collected from their spiders. This is a graphical alternative to [estela-cli](https://github.com/bitmakerla/estela-cli). For more information on this module and how to set it up, please refer to our [official documentation 📂](https://estela.bitmaker.la/docs/estela/web/web.html). +Testing preview From 4db4c2cda0dd649ef3a2f3c7c58c9c4c21c41e57 Mon Sep 17 00:00:00 2001 From: saul Date: Tue, 8 Aug 2023 10:54:32 -0500 Subject: [PATCH 05/24] Adding debugging for changed files in estela-web and estela-api --- .github/workflows/pr-preview-estela-web.yaml | 28 ++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr-preview-estela-web.yaml b/.github/workflows/pr-preview-estela-web.yaml index 753b330f..c040e460 100644 --- a/.github/workflows/pr-preview-estela-web.yaml +++ b/.github/workflows/pr-preview-estela-web.yaml @@ -6,9 +6,9 @@ env: WEB_DIRECTORY: estela-web jobs: - pre_processing: + check-web: runs-on: ubuntu-latest - name: Test changed files + name: Test if web files changed outputs: web_changed: ${{ steps.changed-estela-web-files.outputs.any_changed }} steps: @@ -21,14 +21,32 @@ jobs: with: files: estela-web + check-api: + runs-on: ubuntu-latest + name: Test if api files changed + outputs: + api_changed: ${{ steps.changed-estela-api-files.outputs.any_changed }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Check if estela-api directory changed + id: changed-estela-api-files + uses: tj-actions/changed-files@v37 + with: + files: estela-api + build_web: - if: needs.pre_processing.outputs.web_changed == 'true' + if: needs.check-web.outputs.web_changed == 'true' name: Build web - needs: pre_processing + needs: [check-web, check-api] runs-on: ubuntu-latest env: - web_changed: ${{ needs.pre_processing.outputs.web_changed }} + web_changed: ${{ needs.check-web.outputs.web_changed }} + api_changed: ${{ needs.check-api.outputs.api_changed }} steps: - name: Web changed run: | + echo "estela-api changed status: ${{ env.api_changed }}" echo "estela-web changed status: ${{ env.web_changed }}!" + echo "API URL: ${{ secrets.STAGING_BMC_API_URL }}" From db47a7e225a75ae1110d13478e07d0edff20b354 Mon Sep 17 00:00:00 2001 From: saul Date: Tue, 8 Aug 2023 11:04:41 -0500 Subject: [PATCH 06/24] Testing changes on estela-web folder --- estela-web/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/estela-web/README.md b/estela-web/README.md index d4deefe2..c704239a 100644 --- a/estela-web/README.md +++ b/estela-web/README.md @@ -16,4 +16,3 @@ This module introduces users with a friendly interface that interacts with the [ This module allows users to **manage** their scraping projects and data collected from their spiders. This is a graphical alternative to [estela-cli](https://github.com/bitmakerla/estela-cli). For more information on this module and how to set it up, please refer to our [official documentation 📂](https://estela.bitmaker.la/docs/estela/web/web.html). -Testing preview From f2674726cad006609ebfffca2f12b5b23b5ecffa Mon Sep 17 00:00:00 2001 From: saul Date: Tue, 8 Aug 2023 11:06:32 -0500 Subject: [PATCH 07/24] Testing --- estela-web/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/estela-web/README.md b/estela-web/README.md index c704239a..56d96326 100644 --- a/estela-web/README.md +++ b/estela-web/README.md @@ -16,3 +16,4 @@ This module introduces users with a friendly interface that interacts with the [ This module allows users to **manage** their scraping projects and data collected from their spiders. This is a graphical alternative to [estela-cli](https://github.com/bitmakerla/estela-cli). For more information on this module and how to set it up, please refer to our [official documentation 📂](https://estela.bitmaker.la/docs/estela/web/web.html). +PR preview From fa0ff5542c01152a1e47958678d240b363f06f46 Mon Sep 17 00:00:00 2001 From: saul Date: Wed, 9 Aug 2023 13:16:23 -0500 Subject: [PATCH 08/24] Adding initial draft for building and deploying only web and connecting it to estela staging --- .github/workflows/pr-preview-estela-web.yaml | 74 +++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-preview-estela-web.yaml b/.github/workflows/pr-preview-estela-web.yaml index c040e460..b28911ec 100644 --- a/.github/workflows/pr-preview-estela-web.yaml +++ b/.github/workflows/pr-preview-estela-web.yaml @@ -1,4 +1,4 @@ -name: Build and Deploy estela-web +name: Build and Deploy estela-web preview on: pull_request: @@ -37,7 +37,7 @@ jobs: files: estela-api build_web: - if: needs.check-web.outputs.web_changed == 'true' + if: needs.check-web.outputs.web_changed == 'true' && needs.check-api.outputs.api_changed == 'false' name: Build web needs: [check-web, check-api] runs-on: ubuntu-latest @@ -45,8 +45,78 @@ jobs: web_changed: ${{ needs.check-web.outputs.web_changed }} api_changed: ${{ needs.check-api.outputs.api_changed }} steps: + - name: Check out code + uses: actions/checkout@v2 + + - uses: actions/cache@v2 + id: cache + with: + path: $WEB_DIRECTORY/node_modules + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + + - name: Build Web + run: | + cd $WEB_DIRECTORY + echo "REACT_APP_API_BASE_URL=${{ secrets.STAGING_BMC_API_URL }}" > .env.production + yarn install + yarn build --env publicPath=${{ secrets.STAGING_BMC_PUBLIC_PATH }} + - name: Web changed run: | echo "estela-api changed status: ${{ env.api_changed }}" echo "estela-web changed status: ${{ env.web_changed }}!" echo "API URL: ${{ secrets.STAGING_BMC_API_URL }}" + + - name: "Upload Artifact" + uses: actions/upload-artifact@v3 + with: + name: build-web + path: estela-web/dist/ + retention-days: 1 + + deploy_to_s3: + name: Deploy web to s3 + needs: build_web + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Download built Web + uses: actions/download-artifact@v3 + with: + name: build-web + path: estela-web/dist/ + + # - name: Configure AWS credentials + # uses: aws-actions/configure-aws-credentials@v1 + # with: + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + + # - name: Defining bucket name and policies + # run: | + # export _BUCKET_NAME=$(echo estela-web-${{ github.head_ref }} | tr '[:upper:]' '[:lower:]') + # echo "BUCKET_NAME=$_BUCKET_NAME" + # echo "{ + # \"Version\": \"2012-10-17\", + # \"Statement\": [ + # { + # \"Sid\": \"PublicReadGetObject\", + # \"Effect\": \"Allow\", + # \"Principal\": \"*\", + # \"Action\": \"s3:GetObject\", + # \"Resource\": \"arn:aws:s3:::$_BUCKET_NAME/*\" + # } + # ] + # }" > bucket_policy.json + + - name: Creating new S3 Bucket + run: | + ls + + # - name: Deploy web to s3 + # run: | + # cd $WEB_DIRECTORY + # aws s3 sync --delete ./dist s3:// From c149b04545f67845a37925137340eb4def7fb7fa Mon Sep 17 00:00:00 2001 From: saul Date: Wed, 9 Aug 2023 13:22:17 -0500 Subject: [PATCH 09/24] Showing estela web built directory --- .github/workflows/pr-preview-estela-web.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pr-preview-estela-web.yaml b/.github/workflows/pr-preview-estela-web.yaml index b28911ec..f364f5b7 100644 --- a/.github/workflows/pr-preview-estela-web.yaml +++ b/.github/workflows/pr-preview-estela-web.yaml @@ -115,6 +115,8 @@ jobs: - name: Creating new S3 Bucket run: | ls + cd estela-web + ls # - name: Deploy web to s3 # run: | From 0458abcd381fd744325763d5315db0ae9e0bba34 Mon Sep 17 00:00:00 2001 From: saul Date: Wed, 9 Aug 2023 13:47:26 -0500 Subject: [PATCH 10/24] Debugging --- .github/workflows/pr-preview-estela-web.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pr-preview-estela-web.yaml b/.github/workflows/pr-preview-estela-web.yaml index f364f5b7..dd09eafc 100644 --- a/.github/workflows/pr-preview-estela-web.yaml +++ b/.github/workflows/pr-preview-estela-web.yaml @@ -114,9 +114,13 @@ jobs: - name: Creating new S3 Bucket run: | + echo "Accessing main folder" ls + echo "accessing estela-web folder" cd estela-web ls + echo "accessing dist folder" + ls # - name: Deploy web to s3 # run: | From 726482a941dfd03d2879f8d9049e11c40f44a4ee Mon Sep 17 00:00:00 2001 From: saul Date: Wed, 9 Aug 2023 13:50:29 -0500 Subject: [PATCH 11/24] Debugging --- .github/workflows/pr-preview-estela-web.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-preview-estela-web.yaml b/.github/workflows/pr-preview-estela-web.yaml index dd09eafc..efd5bee3 100644 --- a/.github/workflows/pr-preview-estela-web.yaml +++ b/.github/workflows/pr-preview-estela-web.yaml @@ -120,6 +120,7 @@ jobs: cd estela-web ls echo "accessing dist folder" + cd dist ls # - name: Deploy web to s3 From 21411122e64758cd3dd46a2401dd2eec8f92d7f5 Mon Sep 17 00:00:00 2001 From: saul Date: Wed, 9 Aug 2023 14:15:58 -0500 Subject: [PATCH 12/24] Adding setup-node action for building estela-web --- ...eb.yaml => deploy-estela-web-preview.yaml} | 21 ++++++++++++------- .../workflows/remove-estela-web-preview.yaml | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) rename .github/workflows/{pr-preview-estela-web.yaml => deploy-estela-web-preview.yaml} (88%) create mode 100644 .github/workflows/remove-estela-web-preview.yaml diff --git a/.github/workflows/pr-preview-estela-web.yaml b/.github/workflows/deploy-estela-web-preview.yaml similarity index 88% rename from .github/workflows/pr-preview-estela-web.yaml rename to .github/workflows/deploy-estela-web-preview.yaml index efd5bee3..ce87bbbc 100644 --- a/.github/workflows/pr-preview-estela-web.yaml +++ b/.github/workflows/deploy-estela-web-preview.yaml @@ -46,23 +46,30 @@ jobs: api_changed: ${{ needs.check-api.outputs.api_changed }} steps: - name: Check out code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - - uses: actions/cache@v2 - id: cache + - uses: actions/setup-node@v3 with: - path: $WEB_DIRECTORY/node_modules - key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + node-version: 18.x + cache: "yarn" + cache-dependency-path: ${{env.WEB_DIRECTORY}}/yarn.lock + + # - uses: actions/cache@v2 + # id: cache + # with: + # path: $WEB_DIRECTORY/node_modules + # key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - name: Build Web + working-directory: ${{env.WEB_DIRECTORY}} run: | - cd $WEB_DIRECTORY echo "REACT_APP_API_BASE_URL=${{ secrets.STAGING_BMC_API_URL }}" > .env.production yarn install yarn build --env publicPath=${{ secrets.STAGING_BMC_PUBLIC_PATH }} - name: Web changed run: | + ls echo "estela-api changed status: ${{ env.api_changed }}" echo "estela-web changed status: ${{ env.web_changed }}!" echo "API URL: ${{ secrets.STAGING_BMC_API_URL }}" @@ -80,7 +87,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Download built Web uses: actions/download-artifact@v3 diff --git a/.github/workflows/remove-estela-web-preview.yaml b/.github/workflows/remove-estela-web-preview.yaml new file mode 100644 index 00000000..78e600d7 --- /dev/null +++ b/.github/workflows/remove-estela-web-preview.yaml @@ -0,0 +1 @@ +name: "Remove estela-web preview" From 70696eea14bf659192fb07a9b06fd1480263929d Mon Sep 17 00:00:00 2001 From: saul Date: Wed, 9 Aug 2023 14:18:51 -0500 Subject: [PATCH 13/24] Solving directory path name --- .github/workflows/deploy-estela-web-preview.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-estela-web-preview.yaml b/.github/workflows/deploy-estela-web-preview.yaml index ce87bbbc..9b86e85a 100644 --- a/.github/workflows/deploy-estela-web-preview.yaml +++ b/.github/workflows/deploy-estela-web-preview.yaml @@ -52,7 +52,7 @@ jobs: with: node-version: 18.x cache: "yarn" - cache-dependency-path: ${{env.WEB_DIRECTORY}}/yarn.lock + cache-dependency-path: ./${{env.WEB_DIRECTORY}}/yarn.lock # - uses: actions/cache@v2 # id: cache @@ -61,7 +61,7 @@ jobs: # key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - name: Build Web - working-directory: ${{env.WEB_DIRECTORY}} + working-directory: ./${{env.WEB_DIRECTORY}} run: | echo "REACT_APP_API_BASE_URL=${{ secrets.STAGING_BMC_API_URL }}" > .env.production yarn install From 3d2ca8b7823fe799a8db38e520086bfe6bbb9cc3 Mon Sep 17 00:00:00 2001 From: saul Date: Wed, 9 Aug 2023 14:23:45 -0500 Subject: [PATCH 14/24] Debugging when api change too --- .github/workflows/deploy-estela-web-preview.yaml | 10 ++-------- estela-api/README.md | 6 ++++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy-estela-web-preview.yaml b/.github/workflows/deploy-estela-web-preview.yaml index 9b86e85a..03fe640f 100644 --- a/.github/workflows/deploy-estela-web-preview.yaml +++ b/.github/workflows/deploy-estela-web-preview.yaml @@ -54,12 +54,6 @@ jobs: cache: "yarn" cache-dependency-path: ./${{env.WEB_DIRECTORY}}/yarn.lock - # - uses: actions/cache@v2 - # id: cache - # with: - # path: $WEB_DIRECTORY/node_modules - # key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - - name: Build Web working-directory: ./${{env.WEB_DIRECTORY}} run: | @@ -123,10 +117,10 @@ jobs: run: | echo "Accessing main folder" ls - echo "accessing estela-web folder" + echo "Accessing estela-web folder" cd estela-web ls - echo "accessing dist folder" + echo "Accessing dist folder" cd dist ls diff --git a/estela-api/README.md b/estela-api/README.md index cf8e6eba..fca43303 100644 --- a/estela-api/README.md +++ b/estela-api/README.md @@ -3,10 +3,11 @@ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) The API consists of three main components: + - Django API: Implements a REST API built with the Django REST framework toolkit, exposing several endpoints to manage - projects, spiders, and jobs. + projects, spiders, and jobs. - Celery worker and beat: Responsible for executing the tasks and periodic tasks ordered by the API. -- Redis: Keeps a record of the tasks and periodic tasks to be executed. It is needed by Celery. +- Redis: Keeps a record of the tasks and periodic tasks to be executed. It is needed by Celery. These components have a corresponding Docker configuration file to build their images and run in Docker containers. @@ -40,3 +41,4 @@ module will take care of calling the appropriate methods to access both the regi are saved, fetching any required credentials (such as your `AWS_ACCESS_KEY_ID` for AWS). For more information on the currently supported credentials, refer to the [Credentials](https://bitmaker.la/docs/bitmaker-cloud/api/credentials.html) section in our official documentation. +Changed From c53ca105dd438fe2032a81635d8272d8170695dc Mon Sep 17 00:00:00 2001 From: saul Date: Wed, 9 Aug 2023 14:25:19 -0500 Subject: [PATCH 15/24] Deleting change from api --- estela-api/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/estela-api/README.md b/estela-api/README.md index fca43303..9ec97983 100644 --- a/estela-api/README.md +++ b/estela-api/README.md @@ -41,4 +41,3 @@ module will take care of calling the appropriate methods to access both the regi are saved, fetching any required credentials (such as your `AWS_ACCESS_KEY_ID` for AWS). For more information on the currently supported credentials, refer to the [Credentials](https://bitmaker.la/docs/bitmaker-cloud/api/credentials.html) section in our official documentation. -Changed From 271bfcc2b30f01d77a4ec85749bb6b78f37c0e7c Mon Sep 17 00:00:00 2001 From: saul Date: Wed, 9 Aug 2023 14:31:02 -0500 Subject: [PATCH 16/24] Restoring README.md file same as main branch from estela api --- estela-api/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/estela-api/README.md b/estela-api/README.md index 9ec97983..cf8e6eba 100644 --- a/estela-api/README.md +++ b/estela-api/README.md @@ -3,11 +3,10 @@ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) The API consists of three main components: - - Django API: Implements a REST API built with the Django REST framework toolkit, exposing several endpoints to manage - projects, spiders, and jobs. + projects, spiders, and jobs. - Celery worker and beat: Responsible for executing the tasks and periodic tasks ordered by the API. -- Redis: Keeps a record of the tasks and periodic tasks to be executed. It is needed by Celery. +- Redis: Keeps a record of the tasks and periodic tasks to be executed. It is needed by Celery. These components have a corresponding Docker configuration file to build their images and run in Docker containers. From a26641baf52b3964451942b0e46affcfc72134f4 Mon Sep 17 00:00:00 2001 From: saul Date: Fri, 11 Aug 2023 12:17:28 -0500 Subject: [PATCH 17/24] Testing new secrets --- estela-web/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/estela-web/README.md b/estela-web/README.md index 56d96326..c704239a 100644 --- a/estela-web/README.md +++ b/estela-web/README.md @@ -16,4 +16,3 @@ This module introduces users with a friendly interface that interacts with the [ This module allows users to **manage** their scraping projects and data collected from their spiders. This is a graphical alternative to [estela-cli](https://github.com/bitmakerla/estela-cli). For more information on this module and how to set it up, please refer to our [official documentation 📂](https://estela.bitmaker.la/docs/estela/web/web.html). -PR preview From 534b3a0b8c89e60c46a658e47f6537f6e2971aad Mon Sep 17 00:00:00 2001 From: saul Date: Fri, 11 Aug 2023 12:18:33 -0500 Subject: [PATCH 18/24] Testing new env vars --- estela-web/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/estela-web/README.md b/estela-web/README.md index c704239a..4ac16140 100644 --- a/estela-web/README.md +++ b/estela-web/README.md @@ -16,3 +16,4 @@ This module introduces users with a friendly interface that interacts with the [ This module allows users to **manage** their scraping projects and data collected from their spiders. This is a graphical alternative to [estela-cli](https://github.com/bitmakerla/estela-cli). For more information on this module and how to set it up, please refer to our [official documentation 📂](https://estela.bitmaker.la/docs/estela/web/web.html). +PR From 9bf0efa63e557bb76b3a0d3fc0d81bc9a52801ae Mon Sep 17 00:00:00 2001 From: saul Date: Fri, 11 Aug 2023 12:46:32 -0500 Subject: [PATCH 19/24] Adding deployment to s3 --- .../workflows/deploy-estela-web-preview.yaml | 119 +++++++++--------- 1 file changed, 63 insertions(+), 56 deletions(-) diff --git a/.github/workflows/deploy-estela-web-preview.yaml b/.github/workflows/deploy-estela-web-preview.yaml index 03fe640f..bd0d6500 100644 --- a/.github/workflows/deploy-estela-web-preview.yaml +++ b/.github/workflows/deploy-estela-web-preview.yaml @@ -4,13 +4,14 @@ on: env: WEB_DIRECTORY: estela-web + API_DIRECTORY: estela-api jobs: check-web: runs-on: ubuntu-latest name: Test if web files changed outputs: - web_changed: ${{ steps.changed-estela-web-files.outputs.any_changed }} + web_changed: ${{steps.changed-estela-web-files.outputs.any_changed}} steps: - name: Checkout uses: actions/checkout@v3 @@ -19,13 +20,13 @@ jobs: id: changed-estela-web-files uses: tj-actions/changed-files@v37 with: - files: estela-web + files: ${{env.WEB_DIRECTORY}} check-api: runs-on: ubuntu-latest name: Test if api files changed outputs: - api_changed: ${{ steps.changed-estela-api-files.outputs.any_changed }} + api_changed: ${{steps.changed-estela-api-files.outputs.any_changed}} steps: - name: Checkout uses: actions/checkout@v3 @@ -34,7 +35,7 @@ jobs: id: changed-estela-api-files uses: tj-actions/changed-files@v37 with: - files: estela-api + files: ${{env.API_DIRECTORY}} build_web: if: needs.check-web.outputs.web_changed == 'true' && needs.check-api.outputs.api_changed == 'false' @@ -42,8 +43,8 @@ jobs: needs: [check-web, check-api] runs-on: ubuntu-latest env: - web_changed: ${{ needs.check-web.outputs.web_changed }} - api_changed: ${{ needs.check-api.outputs.api_changed }} + web_changed: ${{needs.check-web.outputs.web_changed}} + api_changed: ${{needs.check-api.outputs.api_changed}} steps: - name: Check out code uses: actions/checkout@v3 @@ -57,28 +58,23 @@ jobs: - name: Build Web working-directory: ./${{env.WEB_DIRECTORY}} run: | - echo "REACT_APP_API_BASE_URL=${{ secrets.STAGING_BMC_API_URL }}" > .env.production + echo "REACT_APP_API_BASE_URL=${{secrets.STAGING_BMC_API_URL}}" > .env.production yarn install - yarn build --env publicPath=${{ secrets.STAGING_BMC_PUBLIC_PATH }} - - - name: Web changed - run: | - ls - echo "estela-api changed status: ${{ env.api_changed }}" - echo "estela-web changed status: ${{ env.web_changed }}!" - echo "API URL: ${{ secrets.STAGING_BMC_API_URL }}" + yarn build --env publicPath=${{secrets.STAGING_BMC_PUBLIC_PATH}} - name: "Upload Artifact" uses: actions/upload-artifact@v3 with: name: build-web - path: estela-web/dist/ + path: ${{env.WEB_DIRECTORY}}/dist/ retention-days: 1 deploy_to_s3: name: Deploy web to s3 needs: build_web runs-on: ubuntu-latest + env: + bucket_name: estela-web-${{github.head_ref}} steps: - name: Check out code uses: actions/checkout@v3 @@ -87,44 +83,55 @@ jobs: uses: actions/download-artifact@v3 with: name: build-web - path: estela-web/dist/ - - # - name: Configure AWS credentials - # uses: aws-actions/configure-aws-credentials@v1 - # with: - # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - # aws-region: ${{ secrets.AWS_DEFAULT_REGION }} - - # - name: Defining bucket name and policies - # run: | - # export _BUCKET_NAME=$(echo estela-web-${{ github.head_ref }} | tr '[:upper:]' '[:lower:]') - # echo "BUCKET_NAME=$_BUCKET_NAME" - # echo "{ - # \"Version\": \"2012-10-17\", - # \"Statement\": [ - # { - # \"Sid\": \"PublicReadGetObject\", - # \"Effect\": \"Allow\", - # \"Principal\": \"*\", - # \"Action\": \"s3:GetObject\", - # \"Resource\": \"arn:aws:s3:::$_BUCKET_NAME/*\" - # } - # ] - # }" > bucket_policy.json - - - name: Creating new S3 Bucket + path: ${{env.WEB_DIRECTORY}}/dist/ + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}} + aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}} + aws-region: ${{secrets.AWS_DEFAULT_REGION}} + + - name: Defining bucket name and policies run: | - echo "Accessing main folder" - ls - echo "Accessing estela-web folder" - cd estela-web - ls - echo "Accessing dist folder" - cd dist - ls - - # - name: Deploy web to s3 - # run: | - # cd $WEB_DIRECTORY - # aws s3 sync --delete ./dist s3:// + echo "{ + \"Version\": \"2012-10-17\", + \"Statement\": [ + { + \"Sid\": \"PublicReadGetObject\", + \"Effect\": \"Allow\", + \"Principal\": \"*\", + \"Action\": \"s3:GetObject\", + \"Resource\": \"arn:aws:s3:::${{env.bucket_name}}/*\" + } + ] + }" > bucket_policy.json + + - name: Create new S3 Bucket + run: | + if ! aws s3api head-bucket --bucket ${{env.bucket_name}} 2>/dev/null; then \ + aws s3 mb s3://${{env.bucket_name}}; \ + cd ./${{env.WEB_DIRECTORY}}/dist/ + aws s3 website s3://${{env.bucket_name}} --index-document index.html; \ + cd ../../ + aws s3api put-public-access-block --bucket ${{env.bucket_name}} --public-access-block-configuration "BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"; \ + aws s3api put-bucket-policy --bucket ${{env.bucket_name}} --policy file://bucket_policy.json; \ + fi + + - name: Deploy to S3 Bucket + run: aws s3 sync ./${{env.WEB_DIRECTORY}}/dist/ s3://${{env.bucket_name}} --delete + + - name: Comment Website Direction + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: Docs preview + recreate: true + message: | + ## estela web preview + You are viewing this message because you made a change in estela-web + | Tables | Are | Cool | + |----------|:-------------:|------:| + | col 1 is | left-aligned | $1600 | + | col 2 is | centered | $12 | + | col 3 is | right-aligned | $1 | + Check out the docs preview [here](http://${{env.bucket_name}}.s3-website-${{secrets.AWS_DEFAULT_REGION}}.amazonaws.com/index.html) :point_left: From a817bb275c35b6741c246de2dd8acd06d1f33cd5 Mon Sep 17 00:00:00 2001 From: saul Date: Fri, 11 Aug 2023 13:01:16 -0500 Subject: [PATCH 20/24] Solving issue with env var bucket name --- .../workflows/deploy-estela-web-preview.yaml | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy-estela-web-preview.yaml b/.github/workflows/deploy-estela-web-preview.yaml index bd0d6500..5a0ac381 100644 --- a/.github/workflows/deploy-estela-web-preview.yaml +++ b/.github/workflows/deploy-estela-web-preview.yaml @@ -73,8 +73,6 @@ jobs: name: Deploy web to s3 needs: build_web runs-on: ubuntu-latest - env: - bucket_name: estela-web-${{github.head_ref}} steps: - name: Check out code uses: actions/checkout@v3 @@ -94,6 +92,8 @@ jobs: - name: Defining bucket name and policies run: | + export _BUCKET_NAME=$(echo estela-docs-${{ github.head_ref }} | tr '[:upper:]' '[:lower:]') + echo "BUCKET_NAME=$_BUCKET_NAME" >> $GITHUB_ENV echo "{ \"Version\": \"2012-10-17\", \"Statement\": [ @@ -102,24 +102,24 @@ jobs: \"Effect\": \"Allow\", \"Principal\": \"*\", \"Action\": \"s3:GetObject\", - \"Resource\": \"arn:aws:s3:::${{env.bucket_name}}/*\" + \"Resource\": \"arn:aws:s3:::$_BUCKET_NAME/*\" } ] }" > bucket_policy.json - name: Create new S3 Bucket run: | - if ! aws s3api head-bucket --bucket ${{env.bucket_name}} 2>/dev/null; then \ - aws s3 mb s3://${{env.bucket_name}}; \ + if ! aws s3api head-bucket --bucket ${{env.BUCKET_NAME}} 2>/dev/null; then \ + aws s3 mb s3://${{env.BUCKET_NAME}}; \ cd ./${{env.WEB_DIRECTORY}}/dist/ - aws s3 website s3://${{env.bucket_name}} --index-document index.html; \ + aws s3 website s3://${{env.BUCKET_NAME}} --index-document index.html; \ cd ../../ - aws s3api put-public-access-block --bucket ${{env.bucket_name}} --public-access-block-configuration "BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"; \ - aws s3api put-bucket-policy --bucket ${{env.bucket_name}} --policy file://bucket_policy.json; \ + aws s3api put-public-access-block --bucket ${{env.BUCKET_NAME}} --public-access-block-configuration "BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"; \ + aws s3api put-bucket-policy --bucket ${{env.BUCKET_NAME}} --policy file://bucket_policy.json; \ fi - name: Deploy to S3 Bucket - run: aws s3 sync ./${{env.WEB_DIRECTORY}}/dist/ s3://${{env.bucket_name}} --delete + run: aws s3 sync ./${{env.WEB_DIRECTORY}}/dist/ s3://${{env.BUCKET_NAME}} --delete - name: Comment Website Direction uses: marocchino/sticky-pull-request-comment@v2 @@ -134,4 +134,4 @@ jobs: | col 1 is | left-aligned | $1600 | | col 2 is | centered | $12 | | col 3 is | right-aligned | $1 | - Check out the docs preview [here](http://${{env.bucket_name}}.s3-website-${{secrets.AWS_DEFAULT_REGION}}.amazonaws.com/index.html) :point_left: + Check out the docs preview [here](http://${{env.BUCKET_NAME}}.s3-website-${{secrets.AWS_DEFAULT_REGION}}.amazonaws.com/index.html) :point_left: From a9d776ab607e969bb41ee1f61887930c598e1e32 Mon Sep 17 00:00:00 2001 From: saul Date: Fri, 11 Aug 2023 13:29:38 -0500 Subject: [PATCH 21/24] Adding new comment table template and adding metadata preview vars --- .github/workflows/deploy-estela-web-preview.yaml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy-estela-web-preview.yaml b/.github/workflows/deploy-estela-web-preview.yaml index 5a0ac381..b0702108 100644 --- a/.github/workflows/deploy-estela-web-preview.yaml +++ b/.github/workflows/deploy-estela-web-preview.yaml @@ -121,7 +121,11 @@ jobs: - name: Deploy to S3 Bucket run: aws s3 sync ./${{env.WEB_DIRECTORY}}/dist/ s3://${{env.BUCKET_NAME}} --delete - - name: Comment Website Direction + - name: Define preview metadata + run: | + echo "SHORT_COMMIT_SHA=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV" + echo "LAST_UPDATED="$(date -u +'%Y-%m-%d %H:%M:%S') UTC"" >> "$GITHUB_ENV" + - name: Comment Website Preview uses: marocchino/sticky-pull-request-comment@v2 with: header: Docs preview @@ -129,9 +133,6 @@ jobs: message: | ## estela web preview You are viewing this message because you made a change in estela-web - | Tables | Are | Cool | - |----------|:-------------:|------:| - | col 1 is | left-aligned | $1600 | - | col 2 is | centered | $12 | - | col 3 is | right-aligned | $1 | - Check out the docs preview [here](http://${{env.BUCKET_NAME}}.s3-website-${{secrets.AWS_DEFAULT_REGION}}.amazonaws.com/index.html) :point_left: + | Commit | Preview | Last Updated | + |---------|-------------|-------------------------| + | ${{env.SHORT_COMMIT_SHA}} | [See preview](http://${{env.BUCKET_NAME}}.s3-website-${{secrets.AWS_DEFAULT_REGION}}.amazonaws.com){:target="_blank"} | ${{env.LAST_UPDATED}} | From 7bb005b97b4660334940fc0e40c7f53c50052216 Mon Sep 17 00:00:00 2001 From: saul Date: Fri, 11 Aug 2023 13:36:09 -0500 Subject: [PATCH 22/24] Changing text for preview --- .github/workflows/deploy-estela-web-preview.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-estela-web-preview.yaml b/.github/workflows/deploy-estela-web-preview.yaml index b0702108..0bb99df4 100644 --- a/.github/workflows/deploy-estela-web-preview.yaml +++ b/.github/workflows/deploy-estela-web-preview.yaml @@ -135,4 +135,4 @@ jobs: You are viewing this message because you made a change in estela-web | Commit | Preview | Last Updated | |---------|-------------|-------------------------| - | ${{env.SHORT_COMMIT_SHA}} | [See preview](http://${{env.BUCKET_NAME}}.s3-website-${{secrets.AWS_DEFAULT_REGION}}.amazonaws.com){:target="_blank"} | ${{env.LAST_UPDATED}} | + | ${{env.SHORT_COMMIT_SHA}} | See preview | ${{env.LAST_UPDATED}} | From d4c29ac5429456773a3bbcd76f88a1e3581781df Mon Sep 17 00:00:00 2001 From: saul Date: Fri, 11 Aug 2023 13:44:12 -0500 Subject: [PATCH 23/24] Adding deletion of bucket --- .../workflows/delete-estela-web-preview.yaml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/delete-estela-web-preview.yaml diff --git a/.github/workflows/delete-estela-web-preview.yaml b/.github/workflows/delete-estela-web-preview.yaml new file mode 100644 index 00000000..f6c95576 --- /dev/null +++ b/.github/workflows/delete-estela-web-preview.yaml @@ -0,0 +1,25 @@ +name: Delete estela-web preview + +on: + pull_request: + types: + - closed + workflow_dispatch: + +jobs: + delete_bucket: + runs-on: ubuntu-latest + steps: + - name: Set Environment Variables + run: | + echo "BUCKET_NAME=$(echo estela-docs-${{ github.head_ref }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + + - name: Delete S3 Bucket + run: aws s3 rb s3://$BUCKET_NAME --force From 6c3f6533952d60d29818c0ef6c8cf05f95ae6092 Mon Sep 17 00:00:00 2001 From: saul Date: Fri, 11 Aug 2023 13:49:52 -0500 Subject: [PATCH 24/24] Deleting bucket --- .github/workflows/delete-estela-web-preview.yaml | 2 +- .github/workflows/deploy-estela-web-preview.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/delete-estela-web-preview.yaml b/.github/workflows/delete-estela-web-preview.yaml index f6c95576..09c25417 100644 --- a/.github/workflows/delete-estela-web-preview.yaml +++ b/.github/workflows/delete-estela-web-preview.yaml @@ -12,7 +12,7 @@ jobs: steps: - name: Set Environment Variables run: | - echo "BUCKET_NAME=$(echo estela-docs-${{ github.head_ref }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + echo "BUCKET_NAME=$(echo estela-web-${{ github.head_ref }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 diff --git a/.github/workflows/deploy-estela-web-preview.yaml b/.github/workflows/deploy-estela-web-preview.yaml index 0bb99df4..38f79d37 100644 --- a/.github/workflows/deploy-estela-web-preview.yaml +++ b/.github/workflows/deploy-estela-web-preview.yaml @@ -92,7 +92,7 @@ jobs: - name: Defining bucket name and policies run: | - export _BUCKET_NAME=$(echo estela-docs-${{ github.head_ref }} | tr '[:upper:]' '[:lower:]') + export _BUCKET_NAME=$(echo estela-web-${{ github.head_ref }} | tr '[:upper:]' '[:lower:]') echo "BUCKET_NAME=$_BUCKET_NAME" >> $GITHUB_ENV echo "{ \"Version\": \"2012-10-17\",