GithubHelp home page GithubHelp logo

libero / article-store Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 5.0 1.42 MB

Libero Publisher Article Store

License: MIT License

Shell 0.42% Dockerfile 1.71% Makefile 4.36% TypeScript 92.45% JavaScript 1.06%

article-store's Introduction

Libero

Article Store

Build status Open issues Docker pulls License Slack

This app provides an HTTP API for creating, maintaining and reading articles.

An article is an RDF graph, where the root node is a http://schema.org/Article. We can encode an article in JSON-LD:

{
  "@context": "http://schema.org/",
  "@id": "http://example.com/my-article-store/articles/1234567890",
  "@type": "Article",
  "name": "My article"
}

The API uses the Hydra vocabulary as its hypermedia format. It also follows the Libero API specification.

It's written in TypeScript, uses the Koa framework, and various RDF/JS libraries.

The app persists articles in a PostgreSQL database.

Further reading

Table of contents

  1. Installation
    1. Running an Article Store
      1. Using the Docker CLI
      2. Using Docker Compose
    2. Configuration
  2. Development
    1. Running the app
    2. Running the tests
    3. API testing
    4. Linting
  3. Contributing
  4. Getting help
  5. License

Installation

You can find the app on Docker Hub: liberoadmin/article-store.

As it is still under heavy development, there are not yet tagged releases. An image is available for every commit.

Running an Article Store

Using the Docker CLI

  1. Start a PostgreSQL container by executing:

    docker run -d --name article-store-database \
      -e "POSTGRES_DB=article-store" \
      -e "POSTGRES_USER=user" \
      postgres:11.5-alpine
  2. Run the database creation with an ephemeral Article Store container:

    docker run --rm \
      --link article-store-database \
      -e "DATABASE_HOST=article-store-database" \
      -e "DATABASE_NAME=article-store" \
      -e "DATABASE_USER=user" \
      liberoadmin/article-store:latest npm run initdb
  3. Run an Article Store container and link it to the database container:

    docker run \
      --link article-store-database \
      -e "DATABASE_HOST=article-store-database" \
      -e "DATABASE_NAME=article-store" \
      -e "DATABASE_USER=user" \
      -p 8080:8080 \
      liberoadmin/article-store:latest
  4. Access the Article Store entry point:

    curl --include http://localhost:8080/
  1. Create a file called docker-compose.yml:

    version: '3.4'
    
    services:
    
      db:
        image: postgres:11.5-alpine
        environment:
          POSTGRES_DB: article-store
          POSTGRES_USER: user
     
      initdb:
        image: liberoadmin/article-store:latest
        command: >
          /bin/sh -c '
            while ! nc -z db 5432 ; do sleep 1 ; done
            npm run initdb
          '
        environment:
          DATABASE_HOST: db
          DATABASE_NAME: article-store
          DATABASE_USER: user
     
      app:
        image: liberoadmin/article-store:latest
        environment:
          DATABASE_HOST: db
          DATABASE_NAME: article-store
          DATABASE_USER: user
        ports:
          - '8080:8080'
  2. Bring up the containers

    docker-compose up
  3. Access the Article Store entry point:

    curl --include http://localhost:8080/

Configuration

The following environment variables can be set:

DATABASE_HOST

This variable is mandatory is the PostgreSQL hostname.

DATABASE_NAME

This variable is mandatory and is the name of the PostgreSQL database.

DATABASE_USER

This variable is mandatory and is the name of the PostgreSQL user.

DATABASE_PASSWORD

This variable is optional and is the password of the PostgreSQL user (default is blank).

DATABASE_PORT

This variable is optional and is the PostgreSQL port (default 5432).

Development

Requirements

The project contains a Makefile which uses Docker Compose for development and testing.

You can find the possible commands by executing:

make help

Running the app

To build and run the app for development, execute:

make dev

You can now access the entry point at http://localhost:8080, or view the console at http://localhost:8081.

Rebuilding the container

Code is attached to the containers as volumes so most updates are visible without a need to rebuild the container. However, changes to NPM dependencies, for example, require a rebuild. So you may need to execute

make build

before running further commands.

Running the tests

We use Jest to test the app. You can run it by executing:

make test

You can also run the tests in separate suites:

make unit-test
make integration-test

Integration tests have a @group integration annotation, and can access a PostgreSQL instance.

API testing

You can validate the API using the Hydra validator:

make api-validate

And test it using Hypertest:

make api-test

Linting

We lint the app with ESLint. You can run it by:

make lint

You can fix problems, where possible, by executing:

make fix

Contributing

Pull requests and other contributions are more than welcome. Please take a look at the contributing guidelines for further details.

Getting help

License

We released this software under the MIT license. Copyright © 2019 eLife Sciences Publications, Ltd.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.