Skip to content

Deploy Standalone Website #8

Deploy Standalone Website

Deploy Standalone Website #8

name: Deploy Standalone Website
on:
push:
branches:
- "main"
paths:
- "**/apps/nextjs-website/**"
workflow_dispatch:
inputs:
environment:
description: 'Choose environment'
type: choice
required: true
default: dev
options:
- dev
- uat
- prod
jobs:
setup:
runs-on: ubuntu-24.04
outputs:
matrix: ${{ steps.setmatrix.outputs.matrix }}
permissions:
id-token: write
contents: read
steps:
- name: Set Dynamic Env Matrix
id: setmatrix
run: |
echo "github.ref ${{ github.ref }}"
echo "event name ${{ github.event_name }}"
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
matrixStringifiedObject="{\"include\":[{\"environment\":\"${{ github.event.inputs.environment }}\"}]}"
else
matrixStringifiedObject="{\"include\":[{\"environment\":\"dev\"}, {\"environment\":\"uat\"}]}"
fi
echo "matrix=$matrixStringifiedObject" >> $GITHUB_OUTPUT
deploy:
name: Deploy standalone website ${{ matrix.environment }}
if: ${{ needs.setup.outputs.matrix != '' }}
runs-on: ubuntu-24.04
needs: [ setup ]
strategy:
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
continue-on-error: false
environment: ${{ matrix.environment }}
env:
ENV_SHORT: ${{ fromJSON('{"dev":"d","uat":"u","prod":"p"}')[matrix.environment] }}
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
with:
submodules: recursive
- name: Setup Node.JS
uses: ./.github/actions/setup-node
with:
package_manager: npm
- name: Install dependencies
run: npm ci --audit=false --fund=false
- name: Compile
run: npm run compile
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
with:
role-to-assume: ${{ secrets.IAM_ROLE_DEPLOY_LAMBDA }}
aws-region: eu-south-1
- name: Setup env variables
working-directory: apps/nextjs-website
run: |
aws lambda get-function-configuration \
--function-name devportal-${{ env.ENV_SHORT }}-website-opnext-server-lambda-01 | jq -r '.Environment.Variables | to_entries[] | "\(.key)=\(.value)"' > .env
- name: build open-next
working-directory: apps/nextjs-website
run: npx @opennextjs/aws build
env:
AWS_REGION: eu-south-1
- name: Sync Assets to S3
working-directory: apps/nextjs-website
run: |
aws s3 sync ./.open-next/assets s3://devportal-${{ env.ENV_SHORT }}-website-opnext-assets-01/_assets
- name: Sync Cache to S3
working-directory: apps/nextjs-website
run: |
aws s3 sync ./.open-next/cache s3://devportal-${{ env.ENV_SHORT }}-website-opnext-assets-01/_cache
- name: Package the application
working-directory: apps/nextjs-website/.open-next
run: |
cd image-optimization-function
zip -r ./image-optimization-function.zip .
cd ../dynamodb-provider
zip -r ./dynamodb-provider.zip .
cd ../revalidation-function
zip -r ./revalidation-function.zip .
cd ../server-functions
zip -r ./server-functions.zip .
- name: Deploy Lambda function (${{ matrix.environment }})
run: |
aws lambda update-function-code \
--function-name devportal-${{ env.ENV_SHORT }}-website-opnext-server-lambda-01 \
--zip-file fileb://nextjs-app.zip --region eu-south-1