Skip to content

Commit

Permalink
Merge pull request microfeed#93 from jcary741/main
Browse files Browse the repository at this point in the history
Add variable validation and document local dev requirements
  • Loading branch information
wenbinf authored Aug 19, 2023
2 parents c9ee74d + f0bc7b8 commit e5c790f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
·
<a href="mailto:[email protected]"><b>Email Us Privately</b></a>
</p>

Welcome to microfeed, a lightweight content management system (CMS) self-hosted on Cloudflare.
With microfeed, you can easily publish a variety of content such as audios, videos, photos, documents, blog posts,
and external URLs to a feed in the form of web, RSS, and JSON. It's the perfect solution for tech-savvy individuals who
Expand Down Expand Up @@ -178,7 +178,7 @@ Select "Admin Read & Write" permission and create an API token:

<img width="858" alt="Screenshot 2023-08-08 at 4 33 55 PM" src="https://github.com/microfeed/microfeed/assets/1719237/1a90df29-5660-49d4-b66a-24873812492d">


Copy Access Key ID for R2_ACCESS_KEY_ID, and Secret Access Key for R2_SECRET_ACCESS_KEY
<img width="728" alt="Screenshot 2022-12-04 at 4 45 35 PM" src="https://user-images.githubusercontent.com/1719237/205526582-92f440ac-21c4-46d9-a065-cfc1937391c8.png">

Expand Down Expand Up @@ -330,7 +330,7 @@ You can use the command line tool `wrangler` to find sqlite database files and d

<b>How to download media files from R2?</b>

As of Feb 16, 2023, Cloudflare has not provided tools to to batch download all files from a R2 bucket.
As of Feb 16, 2023, Cloudflare has not provided tools to to batch download all files from a R2 bucket.

You may need to write a script to use [S3-compatible APIs](https://developers.cloudflare.com/r2/data-access/s3-api/api/) to fetch all objects from a specific R2 bucket.

Expand All @@ -345,6 +345,8 @@ If you'd like to submit a fix or new feature, please create a pull request with

### Run microfeed on local

Pre-requisites: node / npm, yarn, and wrangler

First, create a .vars.toml file in microfeed's root directory (same level as this README.md file) and put 5 secrets in the .vars.toml file (Similar to [Step 2. Put some secrets on your forked repo](#step-2-put-some-secrets-on-your-forked-repo)):
```toml
# .vars.toml
Expand Down
36 changes: 27 additions & 9 deletions ops/sync_project_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ const https = require('https');
const {VarsReader, WranglerCmd} = require('./lib/utils');

const ALLOWED_VARS = [
{name: 'CLOUDFLARE_ACCOUNT_ID', encrypted: true},
{name: 'CLOUDFLARE_PROJECT_NAME', encrypted: true},
{name: 'CLOUDFLARE_API_TOKEN', encrypted: true},
{name: 'DEPLOYMENT_ENVIRONMENT', encrypted: false},
{name: 'CLOUDFLARE_ACCOUNT_ID', encrypted: true, required: true},
{name: 'CLOUDFLARE_PROJECT_NAME', encrypted: true, required: true},
{name: 'CLOUDFLARE_API_TOKEN', encrypted: true, required: true},
{name: 'DEPLOYMENT_ENVIRONMENT', encrypted: false, required: false},

{name: 'R2_ACCESS_KEY_ID', encrypted: true},
{name: 'R2_SECRET_ACCESS_KEY', encrypted: true},
{name: 'R2_PUBLIC_BUCKET', encrypted: true},
{name: 'R2_ACCESS_KEY_ID', encrypted: true, required: true},
{name: 'R2_SECRET_ACCESS_KEY', encrypted: true, required: true},
{name: 'R2_PUBLIC_BUCKET', encrypted: true, required: false},

{name: 'NODE_VERSION', encrypted: false}, // Cloudflare Pages CI needs this to use the right Node version.
{name: 'MICROFEED_VERSION', encrypted: false},
{name: 'NODE_VERSION', encrypted: false, required: false}, // Cloudflare Pages CI needs this to use the right Node version.
{name: 'MICROFEED_VERSION', encrypted: false, required: false},
];

class SyncProjectConfig {
Expand Down Expand Up @@ -94,6 +94,24 @@ class SyncProjectConfig {
syncEnvVars() {
console.log(`Sync-ing for [${this.currentEnv}]...`);

// ensure that required vars are set
let missingVars = [];
ALLOWED_VARS.forEach((varDict) => {
if (varDict.required && !this.v.get(varDict.name)) {
missingVars.push(varDict.name);
}
});
if (missingVars.length > 0) {
console.error(`Missing required vars: ${missingVars.join(', ')}`);
process.exit(1);
}
// ensure that the project name is valid
if (!this.v.get('CLOUDFLARE_PROJECT_NAME').match(/^[a-zA-Z0-9-]+$/)) {
console.error(`Invalid project name: ${this.v.get('CLOUDFLARE_PROJECT_NAME')}`);
process.exit(1);
}


this.cmd.getDatabaseId((databaseId) => {
console.log('Database id (num of chars): ', databaseId.length)
const varsToAddOrUpdate = JSON.stringify({
Expand Down

0 comments on commit e5c790f

Please sign in to comment.