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

Possibility of running on Heroku #59

Closed
JDsnyke opened this issue Jun 12, 2018 · 25 comments
Closed

Possibility of running on Heroku #59

JDsnyke opened this issue Jun 12, 2018 · 25 comments

Comments

@JDsnyke
Copy link

JDsnyke commented Jun 12, 2018

Loving the Fathom concept. Would it be possible to run a limited version on Heroku by any chance?

Cheers!

@Pierstoval
Copy link

Have you tried to fork the project & make it your git root on Heroku? I'm not sure with Go apps, but setting up an application seems quite straightforward:

https://devcenter.heroku.com/articles/deploying-go

But of course setting it up with default Fathom repository could be nice too 😄

@dannyvankooten
Copy link
Contributor

Hey @JDsnyke,

I don't actually have any experience with Heroku myself but I'll dive into their docs tomorrow to see how we can make deploying to Heroku easier (or whether anything is even needed to make the two compatible).

From a quick glance at their docs, it seems you can push the official Docker image to the Heroku Container Registory.

@smobbl-bobbl
Copy link

any news here? am excited to try fathom on heroku as well!

@prologic
Copy link

prologic commented Jun 18, 2018 via email

@Pierstoval
Copy link

I made a few tests, and what I struggle with, mostly:

  • With Docker, I don't know how to use the port that is provided by Heroku's proxy through the PORT env var, but apart that, setup is easy:

    Run these commands to start the project:

    $ git clone git@github.com:usefathom/fathom.git
    $ cd fathom
    $ heroku create
    $ heroku stack:set container
    $ heroku config:set FATHOM_DEBUG=false FATHOM_DATABASE_DRIVER=mysql FATHOM_SECRET=whateverGeneratedSecretYouWantToUse
    $ heroku addons:create jawsdb:kitefin
    

    Retrieve the database url from JawsDB's config:

    $ heroku config:get JAWSDB_URL
    mysql://user:password@host:3306/database_name
    

    Fetch all information and add the config so Fathom can use it:

    $ heroku config:set FATHOM_DATABASE_NAME=database_name FATHOM_DATABASE_USER="user" FATHOM_DATABASE_PASSWORD="password" FATHOM_DATABASE_HOST="host:3306"
    
  • Without Docker, I don't really know how to build fathom, but if I figure out how to do it when deploying, it's easy to just build the binary at deploy-time and just execute fathom via a Procfile. Any idea on this?

@lovethebomb
Copy link
Contributor

lovethebomb commented Jun 20, 2018

I do not have a Heroku account under hand but try setting the env variable FATHOM_SERVER_ADDR , default is :8080.

Maybe something like this would work, using $PORT from Heroku env:

heroku config:set FATHOM_SERVER_ADDR=":$PORT"

Mind the : colon!

Default port in fathom/main.go:47-50

@Pierstoval
Copy link

@lovethebomb this solution doesn't work because $PORT must be resolved at deploy time, which is not the case.

I don't know Go, but I think there might be a way to parse every $... instruction in env vars values to resolve them based on env vars, is this even possible?

@lovethebomb
Copy link
Contributor

lovethebomb commented Jun 22, 2018

@dannyvankooten Maybe this could be solved by using the env var cascading definition?

https://github.com/urfave/cli#values-from-the-environment

Which would be in fathom/main.go:

cli.StringFlag{
	EnvVar: "FATHOM_SERVER_ADDR,PORT",
	Name:   "addr,port",
	Usage:  "server address",
	Value:  ":8080",
},

@theolampert
Copy link

theolampert commented Aug 16, 2018

Hi all, for anyone new coming to this issue I got this working by following @Pierstoval and others in this thread. To recap (I can also add a note to the readme if it helps):

// Get the code
$ git clone https://github.com/usefathom/fathom.git
$ cd fathom

// Create a new heroku app
$ heroku create

//Push the fathom container to heroku's registry
$ heroku container:push web

//Release the container
$ heroku container:release web

//Configure fathon to use msql and a secret
$ heroku config:set FATHOM_DATABASE_DRIVER=mysql FATHOM_SECRET=whateverGeneratedSecretYouWantToUse

//Create a new mysql database
$ heroku addons:create jawsdb:kitefin

//Get the mysql connection url
$ heroku config:get JAWSDB_URL
//mysql://user:password@host:3306/database_name

//Set database variables from the above url
$ heroku config:set FATHOM_DATABASE_NAME=database_name FATHOM_DATABASE_USER="user" FATHOM_DATABASE_PASSWORD="password" FATHOM_DATABASE_HOST="host:3306"

//Register a new user
$ heroku run ./fathom register --email=something@email.com --password='yourpassword'

@Pierstoval
Copy link

Pierstoval commented Aug 16, 2018

@theolampert I just tried and it doesn't work, probably because of the PORT issue 😕

Edit: Nevermind, I forgot to upgrade my repository with the latest commits from master 😆 🤣

@theolampert
Copy link

theolampert commented Aug 16, 2018

@Pierstoval I managed to get it running, I think you need to remove any reference to PORT or FATHOM_SERVER_ADDR in your heroku config, afaik this commit c437f8a should make fathon use heroku's PORT environmental variable.

@Pierstoval
Copy link

Yep, I edited my comment, it's actually working well :)

@theolampert
Copy link

@Pierstoval glad to hear it!, @dannyvankooten maybe we could close this and add a note somewhere?.

@Pierstoval
Copy link

I suggest to add this to the Wiki & add a link in the README to make sure everyone can create a Heroku project easily just to host a Fathom app 😄

@dannyvankooten
Copy link
Contributor

Hey, glad you got it working and thanks for sharing the info here. That helps!

I'll be closing this issue while linking to it from the wiki.

@jdsimcoe
Copy link

@theolampert Thanks for the instructions! They worked marvelously. Once my Heroku instance is up I can't find a way to add multiple sites. Once I've added a site, the dialog and UI in the upper right goes away.

@dannyvankooten
Copy link
Contributor

Hi @jdsimcoe,

That is most likely because you didn't add a user account to your Fathom dashboard, effectively making it a "public" dashboard. Right now public dashboards don't show the site switcher dropdown until we work in more advanced user management (with roles), but you should be able to add a user, add your sites and then delete your user again to track multiple sites in a public dashboard.

Example:

fathom user add --email=your@email.com --password='super-strong-password'

Then, login to your Fathom dashboard via the web interface and add your additional sites.

To make the dashboard public again, delete the user account when you're done adding your sites.

fathom user delete --email=your@email.com

@jdsimcoe
Copy link

Thanks so much, @dannyvankooten! This worked fabulously.

@aleccool213
Copy link

getting this error when I run heroku container:push web :

=== Building web (/Users/alecbrunelle/github/fathom/Dockerfile)
Sending build context to Docker daemon  35.02MB
Step 1/18 : FROM node:alpine AS assetbuilder
alpine: Pulling from library/node
169185f82c45: Pull complete
80e1b3e484f0: Pull complete
93e33f1be740: Pull complete
Digest: sha256:175109ea9ade024a2851a8847b04e67860e58c757ba66d15a4cd057749018b46
Status: Downloaded newer image for node:alpine
 ---> ebbf98230a82
Step 2/18 : WORKDIR /app
 ---> Running in 613dfacb3a25
Removing intermediate container 613dfacb3a25
 ---> b0e3f4365c1d
Step 3/18 : COPY package*.json ./
 ---> 0897a39b3f49
Step 4/18 : COPY gulpfile.js ./
 ---> 8ec981a64aba
Step 5/18 : COPY assets/ ./assets/
 ---> 502452d5afb6
Step 6/18 : RUN npm install && NODE_ENV=production ./node_modules/gulp/bin/gulp.js
 ---> Running in d03fc86538d6

> preact@8.3.1 postinstall /app/node_modules/preact
> node -e "console.log('\u001b[35m\u001b[1mLove Preact? You can now donate to our open collective:\u001b[22m\u001b[39m\n > \u001b[34mhttps://opencollective.com/preact/donate\u001b[0m')"

Love Preact? You can now donate to our open collective:
 > https://opencollective.com/preact/donate
npm WARN app No description
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 667 packages from 380 contributors and audited 8105 packages in 14.552s
found 3 vulnerabilities (1 low, 2 high)
  run `npm audit fix` to fix them, or `npm audit` for details
[14:55:48] Using gulpfile /app/gulpfile.js
[14:55:48] Starting 'default'...
[14:55:48] Starting 'app-js'...
[14:55:56] Finished 'app-js' after 8.72 s
[14:55:56] Starting 'tracker-js'...
[14:55:57] Finished 'tracker-js' after 119 ms
[14:55:57] Starting 'css'...
[14:55:57] Finished 'css' after 7.79 ms
[14:55:57] Starting 'html'...
[14:55:57] Finished 'html' after 22 ms
[14:55:57] Starting 'img'...
[14:55:57] Finished 'img' after 5.26 ms
[14:55:57] Starting 'fonts'...
[14:55:57] Finished 'fonts' after 94 ms
[14:55:57] Finished 'default' after 8.98 s
Removing intermediate container d03fc86538d6
 ---> 6ef28fd8e3c0
Step 7/18 : FROM golang:latest AS binarybuilder
latest: Pulling from library/golang
ab1fc7e4bf91: Already exists
35fba333ff52: Already exists
f0cb1fa13079: Already exists
3d1dd648b5ad: Already exists
866ed2e2b1fe: Pull complete
ddc4ad35a2f0: Pull complete
ab8da8d8889d: Pull complete
Digest: sha256:6486ea568f95953b86c9687c1e656f4297d9b844481e645a00c0602f26fee136
Status: Downloaded newer image for golang:latest
 ---> 5049ec6e3141
Step 8/18 : WORKDIR /go/src/github.com/usefathom/fathom
 ---> Running in 5e406992fff3
Removing intermediate container 5e406992fff3
 ---> db3862e1cef0
Step 9/18 : COPY . /go/src/github.com/usefathom/fathom
 ---> 7cde2bde71ce
Step 10/18 : COPY --from=assetbuilder /app/assets/build ./assets/build
 ---> 2e1ee9393d83
Step 11/18 : RUN make docker
 ---> Running in aa4d880ac0ae
GOOS=linux GOARCH=amd64 /go/bin/packr build -v -ldflags '-w -extldflags "-static" -X "main.version=1.2.1+18-g05598eb" -X "main.commit=05598eb1317d703052b26a087f1acd7c03ca4435"  -X "main.date="' -o fathom ./main.go
/bin/sh: 1: /go/bin/packr: not found
make: *** [docker] Error 127
Makefile:20: recipe for target 'docker' failed
The command '/bin/sh -c make docker' returned a non-zero code: 2
 ▸    Error: docker build exited with Error: 2

@davidyeiser
Copy link

@aleccool213 I got the same error using the latest files on master. I switched to the 1.2.1 release and it worked fine.

Also, if you get the error below when you run heroku container:push web

no basic auth credentials
 ▸    Error: docker push exited with Error: 1

Run heroku container:login and that should fix it.

@aleccool213
Copy link

@davidyeiser Thank you so much! 😃

@gmolveau
Copy link
Contributor

gmolveau commented Feb 11, 2019

Hi ! I made a tutorialon how to deploy on heroku if anyone's interested.

https://gist.github.com/gmolveau/78f88af3f5951ba6e093f93a07caa302

@Pierstoval
Copy link

Great!

@gmolveau Can you submit a PR to add a documentation section explaining this? 😄

@gmolveau
Copy link
Contributor

@Pierstoval okay I'll make one. I have another one for clever-cloud.com too.

@Pierstoval
Copy link

Awesome! 👍

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

No branches or pull requests