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

Add configuration for netlify deploy previews #13

Merged
merged 1 commit into from
May 15, 2023

Conversation

wotnak
Copy link
Collaborator

@wotnak wotnak commented Feb 26, 2023

This pr adds configuration needed to setup deploy previews for pull requests in this repo.

Netlify sites are very coupled to the specific repo and its branches, so the easiest way to configure deploy previews is to setup this repo as a netlify site. To this end I created a build configuration that temporarily copies the main site repo and using repo/branch overrides builds the site with the blog source replaced with the pr repo/branch. Netlify doesn't have an existing env var for pr source repo, so to get it's url I created a small script that queries github api for pr details. I also added netlify configuration to set http header telling search engines to don't index this repo's site.

After merging this, netlify site for this repo will need to be created. Just creating a site without changing any defaults should be enough, any additional required netlify configuration is handled using the netlify.toml file.

@mstenta
Copy link
Member

mstenta commented Mar 28, 2023

Tagging @paul121 @jgaehring and @symbioquine as reviewers for this. Not urgent - we just need two approvals to merge. I don't feel like I have enough of an understanding of the considerations here.

@jgaehring
Copy link
Member

Maybe it's worth spinning up a Netlify site and see if it works? Proof's in the pudding no?

I nominate @mstenta to give it a try! 😜

Copy link
Member

@paul121 paul121 left a comment

Choose a reason for hiding this comment

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

Thanks for bumping this. Yes this LGTM. Creating another Netlify site that we never publish is a bit odd, but is certainly the easiest way to get nice netlify deploy previews for community blog!

@mstenta
Copy link
Member

mstenta commented Mar 28, 2023

I nominate @mstenta to give it a try! stuck_out_tongue_winking_eye

I'd love to dip my toes into the farmOS.org code more! Just didn't want to leave @wotnak hanging on this one. :-)

@mstenta
Copy link
Member

mstenta commented Mar 28, 2023

After merging this, netlify site for this repo will need to be created.

Ah I see we need to set up another Netlify site? I haven't done that before. I think all the current Netlify stuff is set up in @jgaehring's account? @jgaehring how does it work? Does it make sense to keep them all under the same account? Or can you only have one site per account? Maybe we should set up a farmOS org and move everything into that? Scope creeping? :-P

@jgaehring
Copy link
Member

jgaehring commented Mar 28, 2023

how does it work?

Any one of us can sign into Netlify via GitHub and then just give Netlify OAuth permission to read from this repo. Then, if I'm reading this correctly, the build process should start up simply from the netlify.toml file. And I don't think we're married to the decision of who does it, since at any time someone else can just create another one. In fact, maybe that could be the recommended workflow?

Does it make sense to keep them all under the same account?

Eh, I don't see any reason why (see next answer).

Maybe we should set up a farmOS org and move everything into that?

That would be the adult thing to do, yes, and then it might make sense to have everything in one place. But last I checked, it was cost-prohibitive to have more than one seat on a given plan, and at that time I was also the only one both maintaining and deploying anything to Netlify (FK and f.o), so it seemed unnecessary, at least back then. I don't know if you can create an account as the farmOS GitHub org, or maybe just using a shared farmOS email (do I recall setting something like that up?) instead of signing in with GH, but you will have to OAuth into GH at some point to give Netlify permissions I think, soooooo..... ??? ¯_(ツ)_/¯

Scope creeping?

💯

@mstenta
Copy link
Member

mstenta commented Mar 29, 2023

Thanks for the detailed reply @jgaehring, and the link back to farmOS/farmOS.org#11 for context!

We may be able to get a free Netlify Pro plan! See my comment here: farmOS/farmOS.org#11 (comment)

I will investigate and report back...

Copy link
Member

@jgaehring jgaehring left a comment

Choose a reason for hiding this comment

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

If someone tries this out on Netlify and it works, then I say go for it and merge. It looks good to me otherwise.

@wotnak
Copy link
Collaborator Author

wotnak commented Mar 29, 2023

Example pr on my fork with working deploy preview on Netlify: wotnak#5

@mstenta
Copy link
Member

mstenta commented May 15, 2023

Update: farmOS/farmOS.org#74 (comment)

What do we need to do next to get this PR finished up? Do we need to create a new site in Netlify linked to this repository?

@wotnak
Copy link
Collaborator Author

wotnak commented May 15, 2023

We need now to:

  • merge this pr (so Netlify can use netlify.toml and build script),
  • create a Netlify site linked to this repo (required netlify settings are set in netlify.toml so just creating a site without additional configuration should be enough).

After this for every new pr to the main branch in this repo deploy preview will be generated.

If you want to test this before merging to the main branch, you can merge this to some other branch in this repo and setup netlify to use said branch instead of main and then create some test pr to that branch. Alternatively you can just check how it worked here wotnak#5.

@mstenta mstenta requested a review from jgaehring May 15, 2023 13:58
@jgaehring
Copy link
Member

I say go for it! 🚀

@mstenta mstenta merged commit c98d792 into farmOS:main May 15, 2023
@mstenta
Copy link
Member

mstenta commented May 15, 2023

Merged! Thanks again @wotnak!

I'll set up a site in Netflify pointed at this repo now...

@mstenta
Copy link
Member

mstenta commented May 15, 2023

OK I think I set up the Netlify site correctly, but I just tested it with a new PR (#17) and it failed.

Here are the logs:

2:23:56 PM: build-image version: 340a5296c836ef3d99ac1d871c6447bb7a417c33 (focal)
2:23:56 PM: buildbot version: 20d735efc756356fd09bbc43982bef2018461b10
2:23:56 PM: Fetching cached dependencies
2:23:56 PM: Starting to download cache of 173.9MB
2:23:58 PM: Finished downloading cache in 1.612s
2:23:58 PM: Starting to extract cache
2:24:00 PM: Finished extracting cache in 1.855s
2:24:00 PM: Finished fetching cache in 3.518s
2:24:00 PM: Starting to prepare the repo for build
2:24:00 PM: Preparing Git Reference pull/17/head
2:24:01 PM: Parsing package.json dependencies
2:24:02 PM: Starting to install dependencies
2:24:02 PM: Python version set to 3.8
2:24:02 PM: Attempting Ruby version 2.7.2, read from environment
2:24:02 PM: Using Ruby version 2.7.2
2:24:03 PM: Started restoring cached go cache
2:24:03 PM: Finished restoring cached go cache
2:24:03 PM: Installing Go version 1.19.5 (requested 1.19.5)
2:24:07 PM: go version go1.19.5 linux/amd64
2:24:08 PM: Using PHP version 8.0
2:24:08 PM: Started restoring cached Node.js version
2:24:09 PM: Finished restoring cached Node.js version
2:24:09 PM: v16.20.0 is already installed.
2:24:10 PM: Now using node v16.20.0 (npm v8.19.4)
2:24:10 PM: Enabling Node.js Corepack
2:24:10 PM: Started restoring cached build plugins
2:24:10 PM: Finished restoring cached build plugins
2:24:10 PM: Install dependencies script success
2:24:10 PM: Starting build script
2:24:11 PM: Detected 0 framework(s)
2:24:11 PM: Section completed: initializing
2:24:12 PM: ​
2:24:12 PM: Netlify Build                                                 
2:24:12 PM: ────────────────────────────────────────────────────────────────
2:24:12 PM: ​
2:24:12 PM: ❯ Version
2:24:12 PM:   @netlify/build 29.11.2
2:24:12 PM: ​
2:24:12 PM: ❯ Flags
2:24:12 PM:   baseRelDir: true
2:24:12 PM:   buildId: 646278b7dd65140008f9df0b
2:24:12 PM:   deployId: 646278b7dd65140008f9df0d
2:24:12 PM: ​
2:24:12 PM: ❯ Current directory
2:24:12 PM:   /opt/build/repo
2:24:12 PM: ​
2:24:12 PM: ❯ Config file
2:24:12 PM:   No config file was defined: using default values.
2:24:12 PM: ​
2:24:12 PM: ❯ Context
2:24:12 PM:   deploy-preview
2:24:12 PM: ​
2:24:12 PM: Build command from Netlify app                                
2:24:12 PM: ────────────────────────────────────────────────────────────────
2:24:12 PM: ​
2:24:12 PM: $ npm run build-preview
2:24:12 PM: npm ERR! code ENOENT
2:24:12 PM: npm ERR! syscall open
2:24:13 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
2:24:12 PM: npm ERR! path /opt/build/repo/package.json
2:24:12 PM: npm ERR! errno -2
2:24:12 PM: npm ERR! enoent ENOENT: no such file or directory, open '/opt/build/repo/package.json'
2:24:12 PM: npm ERR! enoent This is related to npm not being able to find a file.
2:24:12 PM: npm ERR! enoent
2:24:12 PM: npm ERR! A complete log of this run can be found in:
2:24:12 PM: npm ERR!     /opt/buildhome/.npm/_logs/2023-05-15T18_24_12_847Z-debug-0.log
2:24:12 PM: ​
2:24:12 PM: "build.command" failed                                        
2:24:12 PM: ────────────────────────────────────────────────────────────────
2:24:12 PM: ​
2:24:12 PM:   Error message
2:24:12 PM:   Command failed with exit code 254: npm run build-preview (https://ntl.fyi/exit-code-254)
2:24:12 PM: ​
2:24:12 PM:   Error location
2:24:12 PM:   In Build command from Netlify app:
2:24:12 PM:   npm run build-preview
2:24:12 PM: ​
2:24:12 PM:   Resolved config
2:24:12 PM:   build:
2:24:12 PM:     command: npm run build-preview
2:24:12 PM:     commandOrigin: ui
2:24:12 PM:     environment:
2:24:12 PM:       - REVIEW_ID
2:24:12 PM:     publish: /opt/build/repo/farmOS.org/public
2:24:12 PM:     publishOrigin: ui
2:24:12 PM:   redirects:
2:24:12 PM:     - force: true
2:24:12 PM:       from: http://docs.farmos.org/*
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://farmos.org/:splat
2:24:12 PM:     - force: true
2:24:12 PM:       from: https://docs.farmos.org/*
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://farmos.org/:splat
2:24:12 PM:     - from: /development/architecture/
2:24:12 PM:       status: 301
2:24:12 PM:       to: /model/
2:24:12 PM:     - from: /development/docker/
2:24:12 PM:       status: 301
2:24:12 PM:       to: /development/environment/
2:24:12 PM:     - from: /guide/areas/
2:24:12 PM:       status: 301
2:24:12 PM:       to: /guide/mapping/
2:24:12 PM:     - from: /guide/assets/animals/
2:24:12 PM:       status: 301
2:24:12 PM:       to: /guide/assets/
2:24:12 PM:     - from: /guide/assets/compost/
2:24:12 PM:       status: 301
2:24:12 PM:       to: /guide/assets/
2:24:12 PM:     - from: /guide/assets/equipment/
2:24:12 PM:       status: 301
2:24:12 PM:       to: /guide/assets/
2:24:12 PM:     - from: /guide/assets/groups/
2:24:12 PM:       status: 301
2:24:12 PM:       to: /guide/assets/
2:24:12 PM:     - from: /guide/assets/plantings/
2:24:12 PM:       status: 301
2:24:12 PM:       to: /guide/assets/
2:24:12 PM:     - from: /guide/quantity/
2:24:12 PM:       status: 301
2:24:12 PM:       to: /guide/quantities/
2:24:12 PM:     - from: /hosting/docker/
2:24:12 PM:       status: 301
2:24:12 PM:       to: /hosting/install/
2:24:12 PM:     - from: /hosting/installing/
2:24:12 PM:       status: 301
2:24:12 PM:       to: /hosting/install/
2:24:12 PM:     - from: /hosting/updating/
2:24:12 PM:       status: 301
2:24:12 PM:       to: /hosting/update/
2:24:12 PM:     - from: /app/privacy/
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://v1.farmos.org/app/privacy/
2:24:12 PM:     - from: /community/contribute/
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://v1.farmos.org/community/contribute/
2:24:12 PM:     - from: /community/farms/
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://v1.farmos.org/community/farms/
2:24:12 PM:     - from: /development/client/
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://v1.farmos.org/development/client/
2:24:12 PM:     - from: /development/drupal/
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://v1.farmos.org/development/drupal/
2:24:12 PM:     - from: /development/projects/
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://v1.farmos.org/development/projects/
2:24:12 PM:     - from: /development/release/
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://v1.farmos.org/development/release/
2:24:12 PM:     - from: /development/update-safety/
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://v1.farmos.org/development/update-safety/
2:24:12 PM:     - from: /faq/
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://v1.farmos.org/faq/
2:24:12 PM:     - from: /guide/assets/sensors/
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://v1.farmos.org/guide/assets/sensors/
2:24:12 PM:     - from: /hosting/apikeys/
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://v1.farmos.org/hosting/apikeys/
2:24:12 PM:     - from: /hosting/googlemaps/
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://v1.farmos.org/hosting/apikeys/
2:24:12 PM:     - from: /hosting/localization/
2:24:12 PM:       status: 301
2:24:12 PM:       to: https://v1.farmos.org/hosting/localization/
2:24:12 PM:     - from: /guide/app/
2:24:12 PM:       status: 302
2:24:12 PM:       to: https://v1.farmos.org/guide/app/
2:24:12 PM:     - from: /guide/export/
2:24:12 PM:       status: 302
2:24:12 PM:       to: https://v1.farmos.org/guide/export/
2:24:12 PM:     - from: /guide/import/
2:24:12 PM:       status: 302
2:24:12 PM:       to: https://v1.farmos.org/guide/import/
2:24:13 PM:     - from: /guide/contrib/*
      status: 302
      to: https://v1.farmos.org/guide/contrib/:splat
Caching artifacts
2:24:13 PM: Started saving build plugins
2:24:13 PM: Finished saving build plugins
2:24:13 PM: Started saving pip cache
2:24:13 PM: Finished saving pip cache
2:24:13 PM: Started saving emacs cask dependencies
2:24:13 PM: Finished saving emacs cask dependencies
2:24:13 PM: Started saving maven dependencies
2:24:13 PM: Finished saving maven dependencies
2:24:13 PM: Started saving boot dependencies
2:24:13 PM: Finished saving boot dependencies
2:24:13 PM: Started saving rust rustup cache
2:24:13 PM: Finished saving rust rustup cache
2:24:13 PM: Started saving go dependencies
2:24:13 PM: Finished saving go dependencies
2:24:13 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:24:13 PM: Failing build: Failed to build site
2:24:13 PM: Finished processing build request in 17.469s

Maybe I didn't configure the Netlify site correctly?

@wotnak
Copy link
Collaborator Author

wotnak commented May 15, 2023

The branch in #17 doesn't contain the commit from this pr with the build preview configuration. If you update your branch with the changes from the current main branch it should fix the deploy preview build.

@mstenta
Copy link
Member

mstenta commented May 15, 2023

Ah silly me! 😅

That worked! Thanks @wotnak!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants