ponzu-cms / ponzu

Headless CMS with automatic JSON API. Featuring auto-HTTPS from Let's Encrypt, HTTP/2 Server Push, and flexible server framework written in Go.
https://docs.ponzu-cms.org
BSD 3-Clause "New" or "Revised" License
5.68k stars 387 forks source link

Add support for building snaps #313

Closed ghost closed 5 years ago

ghost commented 5 years ago

Following up on https://github.com/ponzu-cms/ponzu/pull/307.

This is the PR for building a snap package of ponzu.

Build and test

You can use:

Build locally

I used Ubuntu 18.04 for this.

git clone https://github.com/igorljubuncic/ponzu.git
cd ponzu
git checkout add-snapcraft
snapcraft

This command will generate a .snap file, something like ponzu_1.0_amd64.snap.

Install locally

snap install ponzu_1.0_amd64.snap --dangerous

The --dangerous flag is necessary because the app (snap) does not originate from the snap store just yet and is not digitally signed.

Run ponzu

snap run ponzu "options"

Register dev account

You can do this here: https://snapcraft.io/account.

Register ponzu name in the store

This can be done on the command line with snapcraft:

snapcraft login snapcraft register

Upload/push ponzu to the store

snapcraft push ponzu_1.0_amd64.snap --release edge

We use release channels to denote risk, as follows:

You can promote to different channels after testing and validation.

Install from store for (a second) test

snap install ponzu --edge

I think this covers it.

Once you land the PR, we can help you with the promotion of ponzu.

Feel free to ask any questions you may have.

Thanks!

olliephillips commented 5 years ago

Hey @igorljubuncic really appreciate you taking the time to send this on the ponzu-dev branch. I did read the further notes in PR #307 and this: https://forum.snapcraft.io/t/stage-snaps/11001 would appear to be exactly what is needed to ensure the ponzu snap, leverages the go snap, without which ponzu may not build.

Would you be in a position to include the necessary yaml instructions or should this be a decision and job for the snapcraft user who may have the necessary go environment or have added the go snap already?

Appreciate your guidance and assistance since as you can probably tell, I have very limited knowledge of Snap, but want to ensure the file we include in the repo lets a snap user get Ponzu up and running with no issues. Thanks again.

ghost commented 5 years ago

Hi Ollie,

Sure thing, just one question for clarification - do you need go at build time or runtime?

So if it's build time, then the yaml changes as follows:

parts:
  ponzu:
    plugin: go
    source: https://github.com/ponzu-cms/ponzu.git
    go-importpath: github.com/ponzu-cms/ponzu
    build-packages:
      - build-essential
      - ADD HERE ANY LIBS YOU NEED TO BUILD (I DON'T THINK YOU NEED ANY OTHER)

If it's runtime, the yaml changes as follows:

parts:
  ponzu:
    plugin: go
    source: https://github.com/ponzu-cms/ponzu.git
    go-importpath: github.com/ponzu-cms/ponzu
    build-packages:
      - build-essential
    stage-packages:
      - ADD HERE LIBS OR RUNTIMES YOU NEED, E.G. GO, LIBGO, ETC.

For the stage package, you could just add go and you will have go available with the snap.

olliephillips commented 5 years ago

There are two binaries, the Ponzu CLI, for which it is necessary to have Go installed, to build & install the CLI itself, and then the Ponzu server (your application) and the CLI uses Go under the hood to build the Ponzu server.

With version control someone may pull their ponzu server source down to the physical production server and build it there, in which case they'd need Go installed so the CLI could build the Ponzu server binary, or, they may send the Ponzu server binary direct via SCP or similar, in which case there'd be no requirement for Go.

To summarise this, I think, in the development environment you would definitely need Go installed. In the production environment, you may need Go installed, depending on your workflow. But in both cases they are build-time dependencies.

ghost commented 5 years ago

You could have two apps inside the snap - both the cli and the server. Most of the time, snaps have a single app in the app stanza, but you can have more (including the server). They can have their different parts, and be built separately, but still be offered in a single bundle.

You can build with just build packages, see if everything works, then add stage packages. This will only slightly change the size of the snap, e.g.:

  build-packages:
    - build-essential
    - go
stage-packages:
      - go

Does this make sense?

olliephillips commented 5 years ago

That's not clear to me - I might have muddied the water a bit with my explanation. I think as a minimum, if someone whats to install Ponzu from a snap, then Go (either from a snap, or other source) should be present.

ghost commented 5 years ago

Then this is what you need (stage = runtime assets):

parts:
  ponzu:
    plugin: go
    source: https://github.com/ponzu-cms/ponzu.git
    go-importpath: github.com/ponzu-cms/ponzu
    build-packages:
      - build-essential
    stage-packages:
      - go
olliephillips commented 5 years ago

@igorljubuncic I've added that to the file, it's in ponzu-dev but will be merged to master in due course

ghost commented 5 years ago

Excellent! Once ponzu is in the store, we can do some work together to promote it.