diff --git a/Makefile b/Makefile index b5f54ef..52ddd83 100644 --- a/Makefile +++ b/Makefile @@ -27,3 +27,5 @@ test: docker run -t "url-short:test" .PHONY:test +migrate: + goose postgres "postgres://url-short:password@localhost:5002/url-short" up diff --git a/bin/local-init.sql b/bin/local-init.sql new file mode 100644 index 0000000..aaf3cf1 --- /dev/null +++ b/bin/local-init.sql @@ -0,0 +1,7 @@ +CREATE ROLE url_short WITH +CREATEDB +LOGIN +PASSWORD 'password'; + +CREATE DATABASE url_short WITH +OWNER url_short; diff --git a/docker-compose.yaml b/docker-compose.yaml index 7a6dab0..3decf39 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,6 +7,11 @@ services: - .env ports: - 5001:8080 + healthcheck: + test: wget --no-verbose --tries=1 --spider http://localhost/api/v1/healthz || exit 1 + interval: 2s + retries: 5 + timeout: 10s depends_on: db: condition: service_healthy @@ -15,10 +20,12 @@ services: restart: always environment: PGDATA: /var/lib/postgresql/data/pgdata - PGUSER: url-short + POSTGRES_USER: postgres POSTGRES_PASSWORD: password + user: postgres volumes: - pgdata:/var/lib/postgresql/data + - ./bin/local-init.sql:/docker-entrypoint-initdb.d/local-init.sql ports: - 5002:5432 healthcheck: