From 437be672eace5330d688d658ef10745a54b80b8b Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Thu, 7 May 2020 10:05:40 +1200 Subject: [PATCH 1/2] build: production builds need to be tagged as production --- .github/workflows/push.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 8d22dbdbc..a6fab62fc 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -81,3 +81,4 @@ jobs: env: ALB_CERTIFICATE_ARN: ${{secrets.ALB_CERTIFICATE_ARN_PROD}} CLOUDFRONT_CERTIFICATE_ARN: ${{secrets.CLOUDFRONT_CERTIFICATE_ARN_PROD}} + NODE_ENV: 'production' From eb21e3965e25f53b5073026f0dc2645193332aeb Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Thu, 7 May 2020 10:19:33 +1200 Subject: [PATCH 2/2] build: dont fail to deploy if old landing page does not exist --- packages/landing/deploy.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/landing/deploy.js b/packages/landing/deploy.js index c6fb54bce..e9684572b 100644 --- a/packages/landing/deploy.js +++ b/packages/landing/deploy.js @@ -10,6 +10,16 @@ const HashKey = 'linz-hash'; const s3 = new AWS.S3({ region: 'us-east-1' }); const cf = new AWS.CloudFormation({ region: 'us-east-1' }); +async function getHash(Bucket, Key) { + try { + const obj = await s3.getObject({ Bucket, Key }).promise(); + return obj.Metadata[HashKey]; + } catch (e) { + console.log('FailedToFetch', { Bucket, Key }, e); + } + return null; +} + /** * Deploy the built s3 assets into the Edge bucket * @@ -18,26 +28,23 @@ const cf = new AWS.CloudFormation({ region: 'us-east-1' }); async function deploy() { // Since the bucket is generated inside of CDK lets look up the bucket name const stackInfo = await cf.describeStacks({ StackName: 'Edge' }).promise(); - const bucket = stackInfo.Stacks[0].Outputs.find(f => f.OutputKey == 'CloudFrontBucket'); + const bucket = stackInfo.Stacks[0].Outputs.find((f) => f.OutputKey == 'CloudFrontBucket'); if (bucket == null) throw new Error('Failed to find EdgeBucket'); const s3BucketName = bucket.OutputValue; const allBuckets = await s3.listBuckets().promise(); - const s3Bucket = allBuckets.Buckets.find(f => f.Name == s3BucketName); + const s3Bucket = allBuckets.Buckets.find((f) => f.Name == s3BucketName); if (s3Bucket == null) throw new Error('Failed to locate edge bucket in current account'); const files = await fs.readdir(DistDir); for (const fileName of files) { const fileData = await fs.readFile(`${DistDir}/${fileName}`); - const hash = crypto - .createHash('sha512') - .update(fileData) - .digest('base64'); + const hash = crypto.createHash('sha512').update(fileData).digest('base64'); - const obj = await s3.getObject({ Bucket: s3BucketName, Key: fileName }).promise(); + const oldHash = await getHash(s3BucketName, fileName); // Only upload files if they have changed - if (obj.Metadata[HashKey] == hash) { + if (oldHash == hash) { console.log('Skipped', fileName, `${(fileData.byteLength / 1024).toFixed(2)}Kb`, hash); continue; }