Skip to content
chadweimerPublic

About

GOMP: Go Meal Planner

Topics

Resources

Stars

5 stars

Watchers

1 watching

Forks

Repository files navigation

GOMP: Go Meal Planner

Web-based recipe book.

Continuous Integration Maintainability Rating Coverage Closed Pull Requests GitHub release license

Installation

Docker

The easiest method is via docker.

docker run -p 5000:5000 ghcr.io/chadweimer/gomp

On a fresh deployment, you can log into the application using the default user "admin@example.com" with password "password".

The above command will use the default configuration, which includes using an embedded SQLite database and ephemeral storage, which is not recommended in production. In order to have persistent storage, you can use a bind mount or named volume with the volume exposed by the container at "/var/app/gomp/data".

docker run -p 5000:5000 -v /path/on/host:/var/app/gomp/data ghcr.io/chadweimer/gomp

The equivalent compose file, this time using a named volume, would look like the following.

services:
  web:
    image: ghcr.io/chadweimer/gomp
    ports:
      - 5000:5000
    volumes:
      - data:/var/app/gomp/data
volumes:
  data:

With PostgreSQL

The easiest way to deploy with a PostgreSQL database is via docker-compose. An example compose file can be found at examples/docker-compose.yml and is shown below.

services:
  web:
    depends_on:
      db:
        condition: service_healthy
    environment:
      DATABASE_URL: postgres://dbuser:dbpassword@db/gomp?sslmode=disable
    image: ghcr.io/chadweimer/gomp
    ports:
      - 5000:5000
    volumes:
      - data:/var/app/gomp/data
  db:
    environment:
      POSTGRES_PASSWORD: dbpassword
      POSTGRES_USER: dbuser
      POSTGRES_DB: gomp
    healthcheck:
      test: ["CMD-SHELL", "pg_isready", "-d", "gomp"]
      interval: 10s
      timeout: 30s
      retries: 5
    image: postgres:alpine
    volumes:
      - db-data:/var/lib/postgresql/data
volumes:
  data:
  db-data:

You will obviously want to cater the values (e.g., passwords) for your deployment.

Manual

Note

All gomp CLI commands referenced here rely on the configuration documented in the next section.

To launch the server, execute the following:

./gomp serve

Database Migration

When running the process manually as above, database migrations are not automatically executed like they are when leveraging the provided docker image. To provision a new database, or run migrations on an existing database, execute the following:

./gomp db migrate up

See CLI Interface for more on the available commands.

Configuration

The following table summarizes the available configuration settings, which are settable through environment variables. Unless otherwise specified, for settings that are arrays, multiple values should be separated by commas.

ENV Value(s) Default Description
BASE_ASSETS_PATH string static The base path to the client assets.
DATABASE_DRIVER postgres, sqlite <empty> Which database/sql driver to use. If blank, the app will attempt to infer it based on the value of DATABASE_URL.
DATABASE_SKIP_MIGRATION boolean false Only used by the docker image. If set to "true", skips the gomp db migration up on container startup. Can be useful when overriding the default container command.
DATABASE_URL string file:data/data.db?_pragma=foreign_keys(1) The url (path, connection string, etc) to use with the associated database driver when opening the database connection. When using the provided docker image, the DATABASE_URL_FILE variable can be set to the path to a file containing the value.
LOG_LEVEL debug,info,warn,error info Defines the logging level for the application.
PORT uint 5000 The port number under which the site is being hosted.
SECURE_KEY []string ChangeMe Used for session authentication. Recommended to be 32 or 64 ASCII characters. When using the provided docker image, the SECURE_KEY_FILE variable can be set to the path to a file containing the value.
TRUSTED_PROXIES []string <empty> List of IP addresses or CIDR ranges that are considered trusted proxies. When determining the client IP address, if the request comes from a trusted proxy, the X-Forwarded-For header will be used to determine the original client IP.
FILES_PATH string data The path (full or relative) under which to store file data.
IMAGE_QUALITY original, high, medium, low original The quality level for recipe images. Original quality falls back to High if the uploaded image is not a JPEG. JPEG Qualities: High == 92, Medium == 80, Low == 70. Resizing Algorithm: High = CatmullRom, Medium = BiLinear, Low = NearestNeighbor.
IMAGE_SIZE uint 2000 The size of the bounding box to fit recipe images to. Ignored if IMAGE_QUALITY == original.
THUMBNAIL_QUALITY high, medium, low medium The quality level for the thumbnails of recipe images. JPEG Qualities: High == 92, Medium == 80, Low == 70. Low also uses the Nearest Neighbor instead of the Box resizing algorithm.
THUMBNAIL_SIZE uint 500 The size of the bounding box to fit the thumbnails of recipe images to.

All environment variables can also be prefixed with "GOMP_" (e.g., GOMP_PORT=1234) in cases where there is a need to avoid collisions with other applications. The name with "GOMP_" is prefered if both are present.

For values that allow releative paths (e.g., BASE_ASSETS_PATH, DATABASE_URL for SQLite, and FILES_PATH), they are always relative to the application working directory. When using docker, this is "/var/app/gomp", so anything at or below the "data/" relative path is in the exposed "/var/app/gomp/data" volume.

CLI interface

Command-line interface for the application.

Usage:

$ ./gomp [COMMAND] [COMMAND FLAGS] [ARGUMENTS...]

serve command

Serve the application.

Usage:

$ ./gomp [GLOBAL FLAGS] serve [ARGUMENTS...]

db command

Database related commands.

Usage:

$ ./gomp [GLOBAL FLAGS] db [ARGUMENTS...]

db export subcommand

Export the complete database to a JSON file.

Usage:

$ ./gomp [GLOBAL FLAGS] db export [COMMAND FLAGS] [ARGUMENTS...]

The following flags are supported:

Name Description Type Default value Environment variables
--output="…" (-o) Path to output JSON file for the exported database (required) string none
--pretty Pretty-print the exported JSON bool false none

db import subcommand

Import the complete database from a JSON file. WARNING: Overwrites all existing data.

Usage:

$ ./gomp [GLOBAL FLAGS] db import [COMMAND FLAGS] [ARGUMENTS...]

The following flags are supported:

Name Description Type Default value Environment variables
--input="…" (-i) Path to input JSON file for the database import (required) string none

db migrate subcommand

Run database migrations.

Usage:

$ ./gomp [GLOBAL FLAGS] db migrate [ARGUMENTS...]

db migrate up subcommand

Migrate the database up by applying all pending migrations.

Usage:

$ ./gomp [GLOBAL FLAGS] db migrate up [ARGUMENTS...]

db migrate down subcommand

Migrate the database down by applying all pending migrations.

Usage:

$ ./gomp [GLOBAL FLAGS] db migrate down [ARGUMENTS...]

db migrate steps subcommand

Migrate the database by the specified number of steps. The steps can be positive (up) or negative (down) (default 1).

Usage:

$ ./gomp [GLOBAL FLAGS] db migrate steps [COMMAND FLAGS] [ARGUMENTS...]

The following flags are supported:

Name Description Type Default value Environment variables
--steps="…" Number of steps to migrate int 1 none

images command

Image related commands.

Usage:

$ ./gomp [GLOBAL FLAGS] images [ARGUMENTS...]

images optimize subcommand

Optimize images.

Optimizing images will load and re-save all uploaded recipe images using the latest configuration settings, including regenerating thumbnails. If this was already run and the settings have not changed, it will have no effect.

Usage:

$ ./gomp [GLOBAL FLAGS] images optimize [ARGUMENTS...]

Building

This repository uses make. The simplest way to build the entire project is to issue the following command at the root of the repository:

make

The sections below describe additional operations that are available, though it is not a complete list. Refer the the Makefile for more.

Installing Dependencies

make install

The equivalent for uninstalling is make uninstall.

Linting

make lint

Compiling

make build

The equivalent for cleaning is make clean.

Building Docker Images

make docker

Creating Release Archives

make archive

These archives are deleted (cleaned) by the same clean target as above.

Credits

See static/package.json and go.mod

About

GOMP: Go Meal Planner

Topics

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages