diff --git a/Dockerfile b/Dockerfile index 2c94341..1e321b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 RUN apk add --no-cache git diff --git a/Dockerfile.db b/Dockerfile.db deleted file mode 100644 index 782c4b9..0000000 --- a/Dockerfile.db +++ /dev/null @@ -1,5 +0,0 @@ -FROM amacneil/dbmate:v1.12.1 - -COPY ./db ./db - -CMD ["--wait", "up"] diff --git a/README.md b/README.md index 51b2c1c..d3efc69 100644 --- a/README.md +++ b/README.md @@ -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` -(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) - -## 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` +Point your browser to `http://localhost:4000` to view the swagger API documentation. ## 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. +## Tests + +Run integration tests (Requires migrated database and started API): `docker-compose run --rm tests` + ## 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` diff --git a/docker-compose.yml b/docker-compose.yml index 1f378c4..bab27ba 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,15 +11,12 @@ services: - 5432:5432 db-migrations: - build: - context: . - dockerfile: Dockerfile.db - #image: amacneil/dbmate:v1.12.1 + image: amacneil/dbmate:v1.12.1 environment: - DATABASE_URL=postgres://postgres:postgres@postgres:5432/auth?sslmode=disable volumes: - "./db:/db:ro" - command: --wait up + command: ["--wait", "up"] profiles: ["migrations"] depends_on: - postgres