Deploy Standalone Website #9
Workflow file for this run
This file contains hidden or 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
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: | | |
echo "Packaging Image optimization..." | |
cd image-optimization-function | |
zip -r ./image-optimization-function.zip . | |
echo "Packaging Dynamo provider..." | |
cd ../dynamodb-provider | |
zip -r ./dynamodb-provider.zip . | |
echo "Packaging Revalidation function..." | |
cd ../revalidation-function | |
zip -r ./revalidation-function.zip . | |
echo "Packaging Server function..." | |
cd ../server-functions/default | |
zip -r ./server-functions.zip . | |
- name: Update Server function | |
working-directory: apps/nextjs-website/.open-next | |
run: | | |
aws s3 cp ./server-functions/default/server-functions.zip \ | |
s3://devportal-${{ matrix.environment }}-website-opennext-lambda-code-01 | |
- name: Deploy Lambda Server Function | |
run: | | |
aws lambda update-function-code \ | |
--function-name devportal-${{ env.ENV_SHORT }}-website-opnext-server-lambda-01 \ | |
--s3-bucket devportal-${{ matrix.environment }}-website-opennext-lambda-code-01 \ | |
--s3-key server-functions.zip |