Updated readme and stuff

This commit is contained in:
Lilleman auf Larv 2022-01-22 15:51:14 +01:00
parent 795222f342
commit 113c177bdc
4 changed files with 9 additions and 29 deletions

View File

@ -1,4 +1,4 @@
FROM golang:1.17.5-alpine3.14 AS builder FROM golang:1.17.6-alpine3.14 AS builder
# Install missing pkgs # Install missing pkgs
RUN apk add --no-cache git RUN apk add --no-cache git

View File

@ -1,5 +0,0 @@
FROM amacneil/dbmate:v1.12.1
COPY ./db ./db
CMD ["--wait", "up"]

View File

@ -6,25 +6,9 @@ A tiny REST API for auth. Register accounts, auth with api-key or name/password,
Migrate database: `docker-compose run --rm db-migrations` Migrate database: `docker-compose run --rm db-migrations`
(Optional) Run tests: `docker-compose run --rm tests` Start the API (on port 4000 by default): `docker-compose up -d`
Start the service (on port 4000 by default): `docker-compose up -d` (db migrations must be ran before this) Point your browser to `http://localhost:4000` to view the swagger API documentation.
## Databaes migration
Done using [dbmate](https://github.com/amacneil/dbmate). Db stuff is stored in `./db`.
Example of running the migrations:
`docker run --rm -it -e DATABASE_URL="postgres://postgres:postgres@127.0.0.1:5432/auth?sslmode=disable" --network=host -v "$(pwd)/db:/db" amacneil/dbmate up`
Example of setting up a postgres SQL server:
`docker run -d --name postgres --network=host -e POSTGRES_PASSWORD=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=auth postgres`
If you are on of those poor people runnin macOS you must use this one to start a postgres server :(
`docker run -d --name pwrpln-postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=auth postgres`
## Admin account ## Admin account
@ -34,6 +18,10 @@ On first startup with a clean database, an account with name "admin" and the fie
The account field "role" is a bit special, in that if it contains "admin" as one of its values, that grants access to all methods on all accounts on this service. It might be a good idea to use the field "role" for authorization throughout your services. The account field "role" is a bit special, in that if it contains "admin" as one of its values, that grants access to all methods on all accounts on this service. It might be a good idea to use the field "role" for authorization throughout your services.
## Tests
Run integration tests (Requires migrated database and started API): `docker-compose run --rm tests`
## Some useful cURLs ## Some useful cURLs
Obtain an admin GWT: `curl -d '"api-key-goes-here"' -H "Content-Type: application/json" -i http://localhost:4000/auth/api-key` Obtain an admin GWT: `curl -d '"api-key-goes-here"' -H "Content-Type: application/json" -i http://localhost:4000/auth/api-key`

View File

@ -11,15 +11,12 @@ services:
- 5432:5432 - 5432:5432
db-migrations: db-migrations:
build: image: amacneil/dbmate:v1.12.1
context: .
dockerfile: Dockerfile.db
#image: amacneil/dbmate:v1.12.1
environment: environment:
- DATABASE_URL=postgres://postgres:postgres@postgres:5432/auth?sslmode=disable - DATABASE_URL=postgres://postgres:postgres@postgres:5432/auth?sslmode=disable
volumes: volumes:
- "./db:/db:ro" - "./db:/db:ro"
command: --wait up command: ["--wait", "up"]
profiles: ["migrations"] profiles: ["migrations"]
depends_on: depends_on:
- postgres - postgres