-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Benjamin Clark
committed
Apr 11, 2024
1 parent
4186a15
commit c14e6af
Showing
4 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Build | ||
|
||
on: pull_request | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [20.12.0] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Deploy | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
permissions: | ||
id-token: write # required to use OIDC authentication | ||
contents: read # required to checkout the code from the repo | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout 📥 | ||
uses: actions/checkout@v2 | ||
|
||
- name: Use Node.js 20.12.0 ⚙️ | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 20.12.0 | ||
|
||
- name: Setup vars 📋 | ||
id: vars | ||
run: | | ||
echo ::set-output name=distdir::$(git rev-parse --short ${{ github.sha }})-20.x-dist | ||
- name: Install 🎯 | ||
run: yarn install | ||
|
||
- name: Build 🏃 | ||
run: npm run build --env CI | ||
- name: Upload artifacts 📤 | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: build-artifacts | ||
path: site/dist | ||
if-no-files-found: error | ||
|
||
deploy: | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
needs: build | ||
|
||
steps: | ||
- name: Checkout 📥 | ||
uses: actions/checkout@v2 | ||
|
||
- name: Download artifacts 📥 | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: build-artifacts | ||
path: site/dist | ||
|
||
- name: Configure AWS credentials 🔐 | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
role-to-assume: arn:aws:iam::851725248912:role/aria-cicd-role | ||
role-duration-seconds: 900 # the ttl of the session, in seconds. | ||
aws-region: us-east-2 | ||
|
||
- name: Setup vars 📋 | ||
id: vars | ||
run: | | ||
echo ::set-output name=identifier::$(git rev-parse --short ${{ github.sha }})-20.x | ||
echo ::set-output name=distdir::$(git rev-parse --short ${{ github.sha }})-20.x-dist | ||
- name: Prep files 🔨 | ||
run: npm run aws_deploy | ||
env: | ||
IDENTIFIER: ${{ steps.vars.outputs.identifier }} | ||
DISTDIR: ${{ steps.vars.outputs.distdir }} | ||
|
||
- name: Copy new index file to S3 📤 | ||
run: aws s3 cp $DISTDIR/index.html s3://aria-site/aria/$IDENTIFIER-aria.html --no-progress | ||
env: | ||
IDENTIFIER: ${{ steps.vars.outputs.identifier }} | ||
DISTDIR: ${{ steps.vars.outputs.distdir }} | ||
|
||
- name: Copy new dist dir to S3 📤 | ||
run: aws s3 cp $DISTDIR s3://aria-site/aria/$DISTDIR --recursive --no-progress | ||
env: | ||
IDENTIFIER: ${{ steps.vars.outputs.identifier }} | ||
DISTDIR: ${{ steps.vars.outputs.distdir }} | ||
|
||
- name: Deployment complete! 🚀 | ||
run: | | ||
echo "Your build is at: https://d13285jxgcxetl.cloudfront.net/aria/${{ steps.vars.outputs.distdir }}/index.html" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright(c) Meta Platforms, Inc. and affiliates. | ||
|
||
import errno | ||
import os | ||
import shutil | ||
import subprocess | ||
import sys | ||
|
||
"""Script to upload Aria app to S3 bucket | ||
Usage: python3 aws_deploy.py | ||
Assumptions: | ||
1) You have the aws cli installed, and it can get access to credentials | ||
1a) This can be anything specified here: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html | ||
1b) For github actions, you should have AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY set as secrets, with AWS_DEFAULT_REGION in the environment | ||
2) You have installed python 3. | ||
3) You are running from within the root directory of the repo (and therefore need to look inside the 'site' folder to start work) | ||
4) Environment variables NODE_VERSION, DISTDIR, and IDENTIFIER are defined | ||
See .github/workflows/deploy.yml 'Setup Vars' step for how those env vars are created. | ||
""" | ||
|
||
def deploy(): | ||
os.chdir('site') | ||
print("Calculating build hash and distdir...") | ||
output = subprocess.run( | ||
["git", "rev-parse", "--short", "HEAD"], capture_output=True | ||
) | ||
hash = output.stdout.decode("utf-8").strip() | ||
print("\ngithash: " + hash) | ||
identifier = os.environ["IDENTIFIER"] | ||
distdir = os.environ["DISTDIR"] | ||
print("\ndistdir: " + distdir) | ||
# Blow away the previous dir, if any. | ||
if os.path.exists(distdir): | ||
print(f"Previous distribution dir {distdir} found, removing.") | ||
shutil.rmtree(distdir) | ||
print(f"\nCreating dist folder {distdir}") | ||
try: | ||
os.mkdir(distdir) | ||
except OSError as err: | ||
if err.errno == errno.EEXIST: | ||
print(f"{distdir} already exists") | ||
elif err.errno == errno.EACCES: | ||
print(f"{distdir} permission denied") | ||
raise | ||
print("\nCopying dist folder") | ||
subprocess.check_call(args=f"cp -a ./dist/* {distdir}", shell=True) | ||
print("\nPrepping index.html with correct asset, css, and javascript paths") | ||
index = "dist/index.html" | ||
newindex = os.path.join(distdir, "index.html") | ||
with open(index, "r") as input: | ||
with open(newindex, "w+") as output: | ||
# Massage the paths appropriately | ||
for s in input: | ||
s = ( | ||
s.replace("/assets/", f"/aria/{distdir}/assets/") | ||
s.replace("/favicon.png", f"/aria/{distdir}/favicon.png") | ||
) | ||
output.write(s) | ||
|
||
if __name__ == "__main__": | ||
deploy() |