Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOP-4247: Build Artifacts #1000

Merged
merged 77 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
5f82b21
chatbot import, npmrc
mmeigs Jan 10, 2024
f9904bc
layout of chatbot fab and feedback fab
mmeigs Jan 11, 2024
cc43f7c
comment
mmeigs Jan 11, 2024
0757509
gitignore
mmeigs Jan 11, 2024
ab21490
correct
mmeigs Jan 11, 2024
f5d65cc
final cleanup
mmeigs Jan 11, 2024
9270b55
change prompts
mmeigs Jan 16, 2024
c809683
alter and add test
mmeigs Jan 16, 2024
ff1977e
lazy test
mmeigs Jan 16, 2024
ebf2d0a
timeout
mmeigs Jan 16, 2024
bc55f1f
remove browser, sob
mmeigs Jan 16, 2024
e231046
added ways to get metadata and documents from file system rather than…
mmeigs Jan 23, 2024
6286ac0
add logs
mmeigs Jan 24, 2024
069a596
add github workflow for lighthouse
mmeigs Jan 24, 2024
c524650
added build snooty, and corrected name fields in action
mmeigs Jan 24, 2024
8d16f86
add auth for npm ci
mmeigs Jan 24, 2024
6611b97
add manifest path placeholder, json parse files
mmeigs Jan 24, 2024
495d61c
make sure not having a zip doesnt error
mmeigs Jan 24, 2024
4d99418
try to get assets from file
mmeigs Jan 24, 2024
d02c297
log asset
mmeigs Jan 24, 2024
b6434df
checksum?
mmeigs Jan 24, 2024
e13244f
assetData now
mmeigs Jan 24, 2024
863e2fe
access assets in map
mmeigs Jan 24, 2024
f81549f
save artifact to lighthouse-public dir
mmeigs Jan 24, 2024
e3779f7
clean up conditionals, logs
mmeigs Jan 25, 2024
4d950cc
rename
mmeigs Jan 26, 2024
7ac7f8c
extra asset log
mmeigs Jan 26, 2024
9b3b8e8
Empty Commit
mmeigs Jan 26, 2024
a236676
log images
mmeigs Jan 29, 2024
162ca9d
assets logs
mmeigs Jan 29, 2024
257674c
gatsbyImages
mmeigs Jan 29, 2024
79151d3
try no format
mmeigs Jan 29, 2024
3d1c36f
read asset from specific file
mmeigs Jan 29, 2024
86260f8
Empty Commit
mmeigs Jan 29, 2024
bb86874
Empty Commit
mmeigs Jan 29, 2024
66efa0b
Empty Commit
mmeigs Jan 29, 2024
c1f2d84
Empty Commit
mmeigs Jan 29, 2024
6dac07b
decode base64
mmeigs Jan 29, 2024
1b11116
escape
mmeigs Jan 29, 2024
012d6fc
parse and buffer
mmeigs Jan 29, 2024
0ea635e
read asset
mmeigs Jan 29, 2024
e567e22
is buffer
mmeigs Jan 29, 2024
b337578
no webp
mmeigs Jan 29, 2024
b62450a
Empty Commit
mmeigs Jan 29, 2024
91c870e
webp back, log keys
mmeigs Jan 29, 2024
59f182a
test run
mmeigs Jan 30, 2024
cb060a8
clone
mmeigs Jan 30, 2024
57ab47e
use auth in action
mmeigs Jan 30, 2024
75f7e3e
ssh
mmeigs Jan 30, 2024
f6efc0c
separate steps
mmeigs Jan 30, 2024
92a0792
use prod data pi
mmeigs Jan 30, 2024
720dd9a
experiment
mmeigs Jan 30, 2024
b004d1e
deleted old images
mmeigs Jan 30, 2024
ce404db
use encoding
mmeigs Jan 31, 2024
0111623
Empty Commit
mmeigs Jan 31, 2024
63e2050
clean, try without creating Buffer
mmeigs Jan 31, 2024
50d9016
create buffer earlier
mmeigs Jan 31, 2024
c642da7
clean
mmeigs Jan 31, 2024
d601d53
build docs
mmeigs Feb 1, 2024
9e10928
build both artifacts
mmeigs Feb 1, 2024
1d79ed4
rename actions
mmeigs Feb 1, 2024
ebaebdd
add comments, fix conditional
mmeigs Feb 1, 2024
7d6fc3f
better conditional in fetch manifest metadata
mmeigs Feb 1, 2024
0f3647f
Merge branch 'main' into DOP-4247-build-artifacts
mmeigs Feb 1, 2024
9679b62
Merge branch 'main' into DOP-4247-build-artifacts
mmeigs Feb 1, 2024
ad2d53b
change github workflow triggers
mmeigs Feb 1, 2024
a6f34cd
PR feedback, matrix
mmeigs Feb 2, 2024
7643654
add workflow trigger, async read file without blocking thread
mmeigs Feb 5, 2024
fc9a69b
Merge branch 'main' into DOP-4247-build-artifacts
mmeigs Feb 5, 2024
283d8cc
use await
mmeigs Feb 5, 2024
e1c3ff6
use env var for Action Artifact
mmeigs Feb 5, 2024
c7d44f3
add env vars to artifact github action
mmeigs Feb 6, 2024
fd92fb6
dont use realm
mmeigs Feb 6, 2024
a87e547
remove env vars
mmeigs Feb 6, 2024
b1d254c
re-add env vars
mmeigs Feb 6, 2024
d9fe459
Merge branch 'main' into DOP-4247-build-artifacts
mmeigs Feb 6, 2024
8a7632b
try v4 for actions steps
mmeigs Feb 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/stage-docs-site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
on:
push:
branches:
- "main"
pull_request:
mmeigs marked this conversation as resolved.
Show resolved Hide resolved
types: [opened, synchronize]
name: Build docs site artifact
jobs:
staging:
permissions: write-all
runs-on: ubuntu-latest
strategy:
matrix:
project: ['cloud-docs', 'docs']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: Access Build Data
uses: mongodb/docs-worker-actions/build-artifact@main
env:
PROJECT_TO_BUILD: ${{ matrix.project }}
- name: Build Snooty
env:
NPM_BASE_64_AUTH: ${{ secrets.NPM_BASE_64_AUTH }}
NPM_EMAIL: ${{ secrets.NPM_EMAIL }}
GATSBY_BUILD_FROM_JSON: true
GATSBY_PARSER_USER: docsworker-xlarge
GATSBY_SITE: ${{ matrix.project }}
GATSBY_PARSER_BRANCH: main
run: |
npm ci --legacy-peer-deps
npm run build
- name: Save Artifact
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

laying the law for DOP-4248 ❤️

uses: actions/upload-artifact@v4
with:
name: artifact-${{ matrix.project }}
path: |
public
2 changes: 1 addition & 1 deletion plugins/gatsby-source-snooty-prod/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ exports.sourceNodes = async ({ actions, createContentDigest, createNodeId }) =>

// wait to connect to Realm

if (siteMetadata.manifestPath) {
if (siteMetadata.manifestPath || process.env.GATSBY_BUILD_FROM_JSON === 'true') {
console.log('Loading documents from manifest');
db = manifestDocumentDatabase;
} else {
Expand Down
41 changes: 34 additions & 7 deletions src/init/DocumentDatabase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const AdmZip = require('adm-zip');
const BSON = require('bson');
const fs = require('fs');
const { promisify } = require('util');
const { initRealm } = require('../utils/setup/init-realm');
const { DOCUMENTS_COLLECTION, METADATA_COLLECTION, ASSETS_COLLECTION } = require('../build-constants');
const { manifestMetadata, siteMetadata } = require('../utils/site-metadata');
Expand All @@ -8,6 +10,8 @@ const { constructBuildFilter } = require('../utils/setup/construct-build-filter'
const DB = siteMetadata.database;
const buildFilter = constructBuildFilter(siteMetadata);

const readFileAsync = promisify(fs.readFile);

class RealmInterface {
constructor() {
this.realmClient = null;
Expand Down Expand Up @@ -55,7 +59,8 @@ class RealmInterface {

class ManifestDocumentDatabase {
constructor(path) {
this.zip = new AdmZip(path);
// Allow no zip if building artifact through Github Action
this.zip = process.env.GATSBY_BUILD_FROM_JSON !== 'true' ? new AdmZip(path) : null;
this.realmInterface = new RealmInterface();
}

Expand All @@ -65,11 +70,22 @@ class ManifestDocumentDatabase {

async getDocuments() {
const result = [];
const zipEntries = this.zip.getEntries();
for (const entry of zipEntries) {
if (entry.entryName.startsWith('documents/')) {
const doc = BSON.deserialize(entry.getData());
result.push(doc);
if (!this.zip && process.env.GATSBY_BUILD_FROM_JSON === 'true') {
// Read documents from Gatsby Action download
try {
const documents = JSON.parse(await readFileAsync('snooty-documents.json'));
return documents;
} catch (err) {
console.error('No Manifest Path was found.');
return result;
}
} else {
const zipEntries = this.zip.getEntries();
for (const entry of zipEntries) {
if (entry.entryName.startsWith('documents/')) {
const doc = BSON.deserialize(entry.getData());
result.push(doc);
}
}
}
return result;
Expand All @@ -80,9 +96,20 @@ class ManifestDocumentDatabase {
}

async getAsset(checksum) {
if (!this.zip && process.env.GATSBY_BUILD_FROM_JSON === 'true') {
// Read assets from Gatsby Action download
try {
const asset = await readFileAsync(`assets/${checksum}`, { encoding: 'base64' });
return Buffer.from(asset, 'base64');
} catch (err) {
console.error('No Manifest Path was found.');
return null;
}
}
const result = this.zip.getEntry(`assets/${checksum}`);
if (result) {
return result.getData();
const buffer = result.getData();
return buffer;
}
return null;
}
Expand Down
12 changes: 11 additions & 1 deletion src/utils/setup/fetch-manifest-metadata.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
const AdmZip = require('adm-zip');
const BSON = require('bson');
const fs = require('fs');

// Returns the metadata from the manifest file if provided
const fetchManifestMetadata = () => {
let metadata = {};
if (process.env.GATSBY_MANIFEST_PATH) {
if (!process.env.GATSBY_MANIFEST_PATH && process.env.GATSBY_BUILD_FROM_JSON === 'true') {
// Read metadata from Gatsby Action download
try {
metadata = JSON.parse(fs.readFileSync('snooty-metadata.json'));
return metadata;
} catch (err) {
console.error('No metadata was found.');
return metadata;
}
} else if (process.env.GATSBY_MANIFEST_PATH) {
const zip = new AdmZip(process.env.GATSBY_MANIFEST_PATH);
const zipEntries = zip.getEntries();
for (const entry of zipEntries) {
Expand Down
Loading