Skip to content

bartholomews/keyaki

Repository files navigation

ケヤキ

Build Status Docker Pulls License: MIT

🔧 This project is still early stage and very much WIP / experimental 🔧

Haskell service

Seed from servant-persistent

Elm client

Look at the client package

Run the db

From within the project, you can start the db locally with:

docker-compose up

Alternatively, you can set up a docker network:

# Create a custom network if you want to use the app and db in docker without docker-compose
# (https://blog.linuxserver.io/2017/10/17/using-docker-networks-for-better-inter-container-communication/)
docker network create keyaki-network
docker run -p 5432:5432 \
    -e POSTGRES_USER=test \
    -e POSTGRES_PASSWORD=test \
    -e POSTGRES_DB=keyaki \
    --network=keyaki-network \
    --name=keyaki-postgres \
    postgres

Run the app from docker registry

docker pull bartholomews/keyaki
docker run -it -p 8081:8081 \
    -e PG_USER='test' \
    -e PG_PASSWORD='test' \
    -e PG_HOST='keyaki-postgres' \
    --network=keyaki-network \
    --name=keyaki \
    bartholomews/keyaki

If you want to change the port you need to add the PORT env var as well.

Development

  • Go to project folder
cd keyaki
  • Build project:
stack build

Please note that in order to build persistent-postgresql, you need to have pg_config in your PATH. Look at https://stackoverflow.com/questions/11618898/pg-config-executable-not-found if you have any issues.

  • Execute app
    (make sure you have built the client first)
stack exec keyaki
  • Live reloading w/ --file-watch:
./scripts/dev.sh
ghcid -c stack ghci -W -T main

Open http://localhost:8081

Run tests

stack build --test

Please note that you must have the following env vars defined:

  • KEYAKI_PG_HOST
  • KEYAKI_PG_PORT
  • KEYAKI_PG_USER
  • KEYAKI_PG_PASSWORD
  • KEYAKI_PG_DATABASE

Build a docker image locally

docker build -f docker/local/Dockerfile -t bartholomews/keyaki .

DB queries

by using httpie:

# add an entry
http POST localhost:8081/api/entry meaning="keyaki" kana="ケヤキ"

# get an entry
http :8081/api/entry/1

# get all entries
http :8081/api/entries

# update an entry
http PUT :8081/api/entry/1 meaning="keyaki" kana="ケヤキ" active:=true

# delete an entry (TODO)
http DELETE :8081/api/entry/1

Helpful Haskell / Servant stuff