Skip to content
New issue

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

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

Already on GitHub? # to your account

Documentation website? #20

Closed
jimafisk opened this issue Apr 29, 2019 · 5 comments
Closed

Documentation website? #20

jimafisk opened this issue Apr 29, 2019 · 5 comments

Comments

@jimafisk
Copy link

@jonahgeorge this project looks awesome, thanks for sharing! The repo has a link to a website at https://letterdrop.jonahgeorge.com/ but it doesn't seem to exist anymore. Is there any way to get access to this site, or other documentation on using / contributing? Thanks!

@jonahgeorge
Copy link
Owner

Hey Jim, this was a project I put together a few years back to scratch an itch. I haven't been using it since then, but can point you in the right direction if you're interesting in getting your own instance running.

Ultimately its Docker container that expects to be pointed at a Postgres instance (originally deployed on Heroku) and is configured via a few environment variables:

The set of database migration that need to be applied live here and were deployed via migrate.

Let me know if you have further questions

@jimafisk
Copy link
Author

jimafisk commented May 4, 2019

Thanks @jonahgeorge! I'm completely new to Go, so here's the steps I took:

  1. Copied .env.example to .env and set PORT=3000, DATABASE_URL=localhost and HOST=localhost
  2. Installed go per https://medium.com/@RidhamTarpara/install-go-1-11-on-ubuntu-18-04-16-04-lts-8c098c503c5f
  3. Installed forego: https://dl.equinox.io/ddollar/forego/stable
  4. Migrated from dep to Go 1.11+ modules: https://blog.callr.tech/migrating-from-dep-to-go-1.11-modules/
    (My project was never in my $GOPATH so I simply ran go mod init which copied the contents of Gopkg.lock to the new go.mod file, then go build which actually downloaded the dependencies).
  5. Then ran forego run 'go run *.go' from the README and that brought up the app at: http://localhost:3000/
    app
  6. Created a RECAPTCHA at https://www.google.com/recaptcha (Needed to choose v2) and added the site key and secret key to my local .env file
  7. Setup lando to get a local postgres connected. The .lando.yml file looks like this:
name: letterdrop
services:
  postgres:
    type: postgres:9.6.11
    portforward: 3306
    creds:
      database: database
      # Note that you cannot change the below but they are shown here for transparency
      # You can read more about why this is below
      # By "NO PASSWORD" we mean the password is blank
      user: postgres
      password: NO PASSWORD
  1. Needed to manually add postgresql-contrib:
  • lando ssh -s postgres --user=root
  • apt-get update
  • sudo apt install postgresql-contrib
  • You can optionally access the db: psql -d postgres -U postgres
  1. Installed migrate by adding sudo to the install instructions:
    • curl -L https://packagecloud.io/golang-migrate/migrate/gpgkey | sudo apt-key add -
    • echo "deb https://packagecloud.io/golang-migrate/migrate/ubuntu/ bionic main" | sudo tee -a /etc/apt/sources.list.d/migrate.list
    • sudo apt-get update
    • sudo apt-get install -y migrate
      go get -tags 'postgres' -u github.com/golang-migrate/migrate/cmd/migrate
  2. Trying to run the db migrations is where I'm having some trouble. If I run migrate -source file://migrations -database postgres://postgres@localhost:3306/database?sslmode=disable up 2 or migrate -path migrations -database postgres://postgres@localhost:3306?sslmode=disable up 2 force 01 I get the following error:
error: Dirty database version 1. Fix and force version.

I know it's likely dependent on my specific setup, but do you have any insight into what I might be doing wrong?

@jimafisk
Copy link
Author

jimafisk commented May 6, 2019

Quick update: I replaced lando with a simple docker-compose.yml file and that seemed to work better. Here's the setup I used:

version: '3'                   
services:                      
  db:                          
    image: postgres            
    ports:                     
    - "5433:5432"              
    environment:               
      POSTGRES_DB: "postgres"  
      POSTGRES_USER: "postgres"
      POSTGRES_PASSWORD: ""    

You can just run docker-compose up -d to start the container, then migrate -path migrations -database 'postgres://postgres@localhost:5433?sslmode=disable' up 2 should work:

1/u create_extensions (49.905273ms)
2/u create_users_table (115.910641ms)

You can open up a prompt to see the database changes using: docker-compose exec -u postgres db psql

For folks new to postgres, in the psql prompt:

  1. Switch to the "postgres" database we created: \c postgres
  2. List the tables for our db: \dt

@jonahgeorge
Copy link
Owner

Check out this branch- #21

I've made some small changes (and added brief instructions) which should help you

@jimafisk
Copy link
Author

jimafisk commented May 7, 2019

Thanks @jonahgeorge that helped me get this going!

test

The key things for me were:

  • Making sure my .env file had the right db connection format. For the docker-compose.yml I mentioned earlier: DATABASE_URL=postgres://postgres@localhost:5433?sslmode=disable
  • Creating an admin user so I could login: insert into users (name, email, password_digest, is_email_confirmed) values ('admin', lower('admin@letterdrop.com'), crypt('keyboardcat', gen_salt('bf', 8)), true) returning *

I assume all the docker stuff (e.g. https://hub.docker.com/r/jonahgeorge/letterdrop) and scripting (e.g. ./script/deploy) is related to setting up a postgres db and deploying it to heroku? Def good to know, for now I'm just running that stuff locally.

@jimafisk jimafisk closed this as completed May 7, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants