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

feat: course-authoring MFE s3 deployment action (#1) #4

Merged
Merged
Changes from all 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
106 changes: 106 additions & 0 deletions .github/workflows/deploy-mfe-s3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: MFE S3 Bucket Deployment 🚀


on:
push:
branches:
- open-release/palm.nelp
- open-rc/palm.nelp

pull_request:
branches:
- "**open-rc**"
jobs:
build:
environment:
name: ${{ github.ref_name == 'open-release/palm.nelp' && 'prod' || 'stage' }}
runs-on: ubuntu-latest
steps:

- name: "Echo job vars"
env:
JOB_VARS: ${{ toJson(vars) }}
run: echo "$JOB_VARS"

- name: checkout mfe repo
uses: actions/checkout@v3

- name: Use Node.js ${{ vars.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ vars.NODE_VERSION }}

- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list

- name: npm Install
run: npm install

- name: npm Build # check env variables of repo.
run: npm run build
env:
PUBLIC_PATH: ${{ vars.PUBLIC_PATH_CDN }}
APP_ID: ${{ vars.APP_ID }}
MFE_CONFIG_API_URL: ${{ vars.MFE_CONFIG_API_URL }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is going to point to stage or prod domains. But what could we do with alpha?
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

probably you are referring to this https://edunext.atlassian.net/browse/FUTUREX-1023 and yes, this will use stage as the other mfes

ENABLE_NEW_RELIC: false
NODE_ENV: production

- name: print generated html of mfe
run: cat dist/index.html

- name: Share artifact inside workflow
uses: actions/upload-artifact@v3
with:
name: ${{ vars.APP_ID }}-dist-artifact
path: dist

deployment:
environment:
name: ${{ github.ref_name == 'open-release/palm.nelp' && 'prod' || 'stage' }}
url: ${{ vars.PUBLIC_PATH_CDN }}
runs-on: ubuntu-latest
needs: build
steps:
# get build artifact
- name: Get artifact
uses: actions/download-artifact@v3
with:
name: ${{ vars.APP_ID }}-dist-artifact

- name: "Echo job vars"
env:
JOB_VARS: ${{ toJson(vars) }}
run: echo "$JOB_VARS"

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
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: Deploy to S3
run: |
aws s3 sync . $S3_BUCKET --delete
env:
S3_BUCKET: s3://${{ vars.BUCKET_NAME }}/${{ vars.APP_ID }}/

- name: Invalidate past cloudfront cache
run: |
aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/${{ vars.APP_ID }}/*"
Loading