Skip to content

Commit

Permalink
ci(cd): remove old web files
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Jan 22, 2024
1 parent f175307 commit 66f564b
Show file tree
Hide file tree
Showing 4 changed files with 386 additions and 20 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,20 @@ jobs:
vars.STACK_NAME }} | jq -r '.Stacks[0].Outputs[] | select(.OutputKey
== "bucketName") | .OutputValue'`" >> $GITHUB_ENV

- name: Delete old files
run: |
aws s3 rm s3://${{ env.BUCKET_NAME }}/map/ --recursive
- name: Upload build
run: |
aws s3 sync dist s3://${{ env.BUCKET_NAME }}/map
aws s3 sync dist s3://${{ env.BUCKET_NAME }}/map/
- name: Set cache metadata
run: |
# All files to 1 year
aws s3 cp s3://${{ env.BUCKET_NAME }} s3://${{ env.BUCKET_NAME }} --recursive --cache-control max-age=30758400,public
aws s3 cp s3://${{ env.BUCKET_NAME }}/map/ s3://${{ env.BUCKET_NAME }}/map/ --recursive --cache-control max-age=30758400,public
# HTML files and .well-known/ to 10 minutes
aws s3 cp s3://${{ env.BUCKET_NAME }} s3://${{ env.BUCKET_NAME }} --exclude "*" --include "*.html" --include ".well-known/*" --recursive --cache-control max-age=600,public --content-type "text/html; charset=UTF-8"
aws s3 cp s3://${{ env.BUCKET_NAME }}/map/ s3://${{ env.BUCKET_NAME }}/map/ --exclude "*" --include "*.html" --include ".well-known/*" --recursive --cache-control max-age=600,public --content-type "text/html; charset=UTF-8"
- name:
Trigger CloudFront cache invalidation for fixed resources (all other
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/invalidate-cloudfront.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
CreateInvalidationCommand,
} from '@aws-sdk/client-cloudfront'
import { stackOutput } from '@nordicsemiconductor/cloudformation-helpers'
import chalk from 'chalk'
import { glob } from 'glob'
import { randomUUID } from 'node:crypto'
import path, { parse } from 'node:path'
Expand All @@ -27,16 +26,16 @@ const pathesToInvalidate = [
]

const stackName = process.env.STACK_NAME ?? 'hello-nrfcloud-web'
console.log(chalk.yellow('Stack name:'), chalk.blue(stackName))
console.log('Stack name:', stackName)

const { distributionId } = await stackOutput(cloudFormation)<{
distributionId: string
}>(stackName)

console.log(chalk.yellow('Distribution ID:'), chalk.blue(distributionId))
console.log('Distribution ID:', distributionId)

console.log(chalk.yellow('Pathes to invalidate:'))
pathesToInvalidate.map((s) => console.log(chalk.gray('-'), chalk.blue(s)))
console.log('Pathes to invalidate:')
pathesToInvalidate.map((s) => console.log('-', s))

const { Invalidation } = await cloudFront.send(
new CreateInvalidationCommand({
Expand All @@ -51,5 +50,5 @@ const { Invalidation } = await cloudFront.send(
}),
)

console.log(chalk.green('Invalidation created!'))
console.log(chalk.yellow('Invalidation ID:'), chalk.blue(Invalidation?.Id))
console.log('Invalidation created!')
console.log('Invalidation ID:', Invalidation?.Id)
Loading

0 comments on commit 66f564b

Please sign in to comment.