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

BITMAKER-3655 Feature environments: Automatic workflow for preview deployment of estela-web #218

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
68f4548
Adding first draft of the workflow, checking if estela-web folder cha…
webtaken Aug 7, 2023
a7d6917
Stop build_web job whenever estela-web/** files doesn't change
webtaken Aug 7, 2023
7a5f127
Update build_web job execution if statement
webtaken Aug 7, 2023
734c346
Testing estela-web changed build_web job
webtaken Aug 7, 2023
4db4c2c
Adding debugging for changed files in estela-web and estela-api
webtaken Aug 8, 2023
db47a7e
Testing changes on estela-web folder
webtaken Aug 8, 2023
f267472
Testing
webtaken Aug 8, 2023
fa0ff55
Adding initial draft for building and deploying only web and connecti…
webtaken Aug 9, 2023
c149b04
Showing estela web built directory
webtaken Aug 9, 2023
0458abc
Debugging
webtaken Aug 9, 2023
726482a
Debugging
webtaken Aug 9, 2023
2141112
Adding setup-node action for building estela-web
webtaken Aug 9, 2023
70696ee
Solving directory path name
webtaken Aug 9, 2023
3d2ca8b
Debugging when api change too
webtaken Aug 9, 2023
c53ca10
Deleting change from api
webtaken Aug 9, 2023
271bfcc
Restoring README.md file same as main branch from estela api
webtaken Aug 9, 2023
a26641b
Testing new secrets
webtaken Aug 11, 2023
534b3a0
Testing new env vars
webtaken Aug 11, 2023
9bf0efa
Adding deployment to s3
webtaken Aug 11, 2023
a817bb2
Solving issue with env var bucket name
webtaken Aug 11, 2023
a9d776a
Adding new comment table template and adding metadata preview vars
webtaken Aug 11, 2023
7bb005b
Changing text for preview
webtaken Aug 11, 2023
d4c29ac
Adding deletion of bucket
webtaken Aug 11, 2023
6c3f653
Deleting bucket
webtaken Aug 11, 2023
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
25 changes: 25 additions & 0 deletions .github/workflows/delete-estela-web-preview.yaml
Original file line number Diff line number Diff line change
@@ -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-web-${{ 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
138 changes: 138 additions & 0 deletions .github/workflows/deploy-estela-web-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Build and Deploy estela-web preview
on:
pull_request:

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}}
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: ${{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}}
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: ${{env.API_DIRECTORY}}

build_web:
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
env:
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

- uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: ./${{env.WEB_DIRECTORY}}/yarn.lock

- name: Build Web
working-directory: ./${{env.WEB_DIRECTORY}}
run: |
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: "Upload Artifact"
uses: actions/upload-artifact@v3
with:
name: build-web
path: ${{env.WEB_DIRECTORY}}/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@v3

- name: Download built Web
uses: actions/download-artifact@v3
with:
name: build-web
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: |
export _BUCKET_NAME=$(echo estela-web-${{ github.head_ref }} | tr '[:upper:]' '[:lower:]')
echo "BUCKET_NAME=$_BUCKET_NAME" >> $GITHUB_ENV
echo "{
\"Version\": \"2012-10-17\",
\"Statement\": [
{
\"Sid\": \"PublicReadGetObject\",
\"Effect\": \"Allow\",
\"Principal\": \"*\",
\"Action\": \"s3:GetObject\",
\"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}}; \
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: 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
recreate: true
message: |
## estela web preview
You are viewing this message because you made a change in estela-web
| Commit | Preview | Last Updated |
|---------|-------------|-------------------------|
| ${{env.SHORT_COMMIT_SHA}} | <a target="_blank" href="http://${{env.BUCKET_NAME}}.s3-website-${{secrets.AWS_DEFAULT_REGION}}.amazonaws.com">See preview</a> | ${{env.LAST_UPDATED}} |
1 change: 1 addition & 0 deletions .github/workflows/remove-estela-web-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: "Remove estela-web preview"
1 change: 1 addition & 0 deletions estela-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading