Skip to content

Commit

Permalink
Adding CICD to main
Browse files Browse the repository at this point in the history
  • Loading branch information
amarouane-ABDELHAK committed Oct 1, 2024
2 parents 4cd585e + 9f54bc7 commit bcea235
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 15 deletions.
127 changes: 127 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Deploy the site to AWS S3 on a push to specific branches

name: Deploy

permissions:
id-token: write
contents: read

on:
push:
branches:
- main
- develop
- cicd/add-auto-deployment

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
NODE: 20

jobs:
define-environment:
name: Set environment
runs-on: ubuntu-latest
steps:
- name: Set the environment based on the branch
id: define_environment
run: |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "env_name=production" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" = "refs/heads/develop" ]; then
echo "env_name=staging" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" = "refs/heads/cicd/add-auto-deployment" ]; then
echo "env_name=staging" >> $GITHUB_OUTPUT
fi
- name: Print the environment
run: echo "The environment is ${{ steps.define_environment.outputs.env_name }}"

outputs:
env_name: ${{ steps.define_environment.outputs.env_name }}

build:
runs-on: ubuntu-latest
needs: define-environment
environment: ${{ needs.define-environment.outputs.env_name }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Use Node.js ${{ env.NODE }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE }}

- name: Cache node_modules
uses: actions/cache@v2
id: cache-node-modules
with:
path: |
node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}

- name: Cache dist
uses: actions/cache@v2
id: cache-dist
with:
path: dist
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.workflow }}-${{ github.sha }}


- name: Build website
env:
GOOGLE_TAG_MANAGER_ID: ${{secrets.GOOGLE_TAG_MANAGER_ID}}
GOOGLE_TAG_AUTH: ${{secrets.GOOGLE_TAG_AUTH}}
GOOGLE_TAG_PREVIEW: ${{secrets.GOOGLE_TAG_PREVIEW}}
run: |
npm install
npm run build # vars.SUBPATH should include the preceeding slash /
deploy:
runs-on: ubuntu-latest
needs: [build, define-environment]
environment: ${{ needs.define-environment.outputs.env_name }}
steps:
# See comment on checks.yml - prep step
- name: Checkout
uses: actions/checkout@v3

- name: Restore node_modules
uses: actions/cache@v2
id: cache-node-modules
with:
path: |
node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}

- name: Restore dist cache
uses: actions/cache@v2
id: cache-dist
with:
path: dist
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.workflow }}-${{ github.sha }}

- name: Use Node.js ${{ env.NODE }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE }}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.DEPLOYMENT_ROLE_ARN }}
role-session-name: "mobile-climate-${{ needs.define-environment.outputs.env_name }}"
aws-region: "us-west-2"

- name: Deploy to S3 Production
run: |
aws s3 sync ./dist s3://${{ secrets.S3_BUCKET }}${{ vars.SUBPATH }} --cache-control max-age=30,must-revalidate,s-maxage=604800 --delete
- name: Request Invalidation to AWS Cloudfront
uses: oneyedev/aws-cloudfront-invalidation@v1
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
${{ vars.SUBPATH }}*
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="src\assets\eic.svg" />
<link rel="icon" type="image/svg+xml" href="./src/assets/eic.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
Expand All @@ -11,6 +11,7 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
<script type="module" src="./src/main.jsx"></script>
</body>
</html>

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/components/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export default function Home() {
layerList.push(mediaLayer);

console.log(
`Initializing video for: ${variable.name}`,
`Initializing video for: ${import.meta.env.BASE_URL}${variable.name}`,
variable.video
);

Expand Down
24 changes: 12 additions & 12 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"description": "Carbon dioxide emissions decline to net zero around 2070, followed by varying levels of reductions in existing carbon dioxide in the atmosphere.",
"variable": "tasmax_ssp126",
"unit": "Heatmax",
"video": "/tasmax_monthly_ssp126_max12_8192_1024x512.mp4",
"mobileVideo": "/tasmax_monthly_ssp126_max12_8192_512x256.mp4",
"fallbackImage": "/tasmax_monthly_ssp126_first_frame.png",
"video": "./tasmax_monthly_ssp126_max12_8192_1024x512.mp4",
"mobileVideo": "./tasmax_monthly_ssp126_max12_8192_512x256.mp4",
"fallbackImage": "./tasmax_monthly_ssp126_first_frame.png",
"service":
"https://gis.earthdata.nasa.gov/eic/rest/services/tasmax_yearly_median/ImageServer",
"datetimeRange": ["1950-01-31T00:00:00Z", "2100-12-31T23:59:59Z"],
Expand Down Expand Up @@ -41,9 +41,9 @@
"description": "Carbon dioxide emissions remain around current levels until the middle of the 21st century.",
"unit": "Heatmax",
"variable": "tasmax_ssp245",
"video": "/tasmax_monthly_ssp245_max12_8192_1024x512.mp4",
"mobileVideo": "/tasmax_monthly_ssp245_max12_8192_1024x512.mp4",
"fallbackImage": "/tasmax_monthly_ssp245_first_frame.png",
"video": "./tasmax_monthly_ssp245_max12_8192_1024x512.mp4",
"mobileVideo": "./tasmax_monthly_ssp245_max12_8192_1024x512.mp4",
"fallbackImage": "./tasmax_monthly_ssp245_first_frame.png",
"service":
"https://gis.earthdata.nasa.gov/eic/rest/services/tasmax_yearly_median/ImageServer",
"datetimeRange": ["1950-01-31T00:00:00Z", "2100-12-31T23:59:59Z"],
Expand Down Expand Up @@ -73,9 +73,9 @@
"description": "Carbon dioxide emissions roughly double from current levels by 2100.",
"unit": "Heatmax",
"variable": "tasmax_ssp370",
"video": "/tasmax_monthly_ssp370_max12_8192_1024x512.mp4",
"mobileVideo": "/tasmax_monthly_ssp370_max12_8192_512x256.mp4",
"fallbackImage": "/tasmax_monthly_ssp370_first_frame.png",
"video": "./tasmax_monthly_ssp370_max12_8192_1024x512.mp4",
"mobileVideo": "./tasmax_monthly_ssp370_max12_8192_512x256.mp4",
"fallbackImage": "./tasmax_monthly_ssp370_first_frame.png",
"service":
"https://gis.earthdata.nasa.gov/eic/rest/services/tasmax_yearly_median/ImageServer",
"datetimeRange": ["1950-01-31T00:00:00Z", "2100-12-31T23:59:59Z"],
Expand Down Expand Up @@ -104,9 +104,9 @@
"name": "585 - Very High",
"description": "Carbon dioxide emissions roughly double from current levels by 2050.",
"unit": "Heatmax",
"video": "/tasmax_monthly_ssp585_max12_8192_1024x512.mp4",
"mobileVideo": "/tasmax_monthly_ssp585_max12_8192_512x256.mp4",
"fallbackImage": "/tasmax_monthly_ssp585_first_frame.png",
"video": "./tasmax_monthly_ssp585_max12_8192_1024x512.mp4",
"mobileVideo": "./tasmax_monthly_ssp585_max12_8192_512x256.mp4",
"fallbackImage": "./tasmax_monthly_ssp585_first_frame.png",
"variable": "tasmax_ssp585",
"service":
"https://gis.earthdata.nasa.gov/eic/rest/services/tasmax_yearly_median/ImageServer",
Expand Down
1 change: 1 addition & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
base: './',
plugins: [react()],
})

0 comments on commit bcea235

Please sign in to comment.