Merge branch 'devMode' into 'master'
Update the README / dev process explanation See merge request !3
This commit is contained in:
commit
b478f12c13
30
Makefile
Normal file
30
Makefile
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
.PHONY: docker migration dev clean test
|
||||||
|
|
||||||
|
DB_USER=test
|
||||||
|
DB_PASS=test
|
||||||
|
DB_DATABASE=test
|
||||||
|
DB_DSN=postgres://$(DB_USER):$(DB_PASS)@127.0.0.1:5432/$(DB_DATABASE)?sslmode=disable
|
||||||
|
|
||||||
|
MIGRATION=migrate -url '$(DB_DSN)'
|
||||||
|
MIGRATION_SCHEMA=./sql
|
||||||
|
MIGRATION_TEST_DATA=./sqltest
|
||||||
|
|
||||||
|
DOCKER_COMPOSE_FILE=./docker/docker-compose.yml
|
||||||
|
DOCKER_COMPOSE=docker-compose -f $(DOCKER_COMPOSE_FILE)
|
||||||
|
|
||||||
|
docker:
|
||||||
|
$(DOCKER_COMPOSE) up -d
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
migration:
|
||||||
|
$(MIGRATION) -path $(MIGRATION_SCHEMA) up
|
||||||
|
$(MIGRATION) -path $(MIGRATION_TEST_DATA) up
|
||||||
|
|
||||||
|
dev: docker migration
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(DOCKER_COMPOSE) stop
|
||||||
|
$(DOCKER_COMPOSE) rm --force --all
|
||||||
|
|
||||||
|
test: docker
|
||||||
|
POSTGRES_DSN="$(DB_DSN)" go test -v -p=1 ./...
|
22
README.md
22
README.md
@ -1,16 +1,26 @@
|
|||||||
## Setup the dev env
|
## Dev
|
||||||
|
|
||||||
Just run the docker-compose file to create the database.
|
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
docker-compose up -d
|
make dev
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To setup the dev env.
|
||||||
|
|
||||||
|
## Connect to the database
|
||||||
|
|
||||||
|
```
|
||||||
|
docker run -it --rm --link canape_postgresql_dev:postgres postgres:9.5 psql -h postgres -U test
|
||||||
|
```
|
||||||
|
|
||||||
## Run the tests
|
## Run the tests
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
POSTGRES_DSN="postgres://test:test@127.0.0.1:5432/test?sslmode=disable" go test -v -p=1 ./...
|
make test
|
||||||
|
```
|
||||||
|
|
||||||
|
## To clean up
|
||||||
|
|
||||||
|
```
|
||||||
|
make clean
|
||||||
```
|
```
|
||||||
|
@ -5,5 +5,7 @@ postgresql:
|
|||||||
environment:
|
environment:
|
||||||
- POSTGRES_PASSWORD=test
|
- POSTGRES_PASSWORD=test
|
||||||
- POSTGRES_USER=test
|
- POSTGRES_USER=test
|
||||||
|
volumes:
|
||||||
|
- .:/docker-entrypoint-initdb.d/
|
||||||
ports:
|
ports:
|
||||||
- 127.0.0.1:5432:5432
|
- 127.0.0.1:5432:5432
|
1
docker/init.sql
Normal file
1
docker/init.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
CREATE DATABASE dev;
|
2
main.go
2
main.go
@ -23,7 +23,7 @@ func (b *UserBackend) Get(username string) (auth.User, error) {
|
|||||||
func main() {
|
func main() {
|
||||||
log := logrus.NewEntry(logrus.New())
|
log := logrus.NewEntry(logrus.New())
|
||||||
|
|
||||||
pgdsn := "postgres://test:test@127.0.0.1:5432/test?sslmode=disable"
|
pgdsn := "postgres://test:test@127.0.0.1:5432/dev?sslmode=disable"
|
||||||
db, err := sqlx.Connect("postgres", pgdsn)
|
db, err := sqlx.Connect("postgres", pgdsn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user