Merge branch 'workflow' into 'master'
Move development workflow to Makefile See merge request !11
This commit is contained in:
commit
ce2fd03f10
46
Makefile
46
Makefile
@ -1,4 +1,4 @@
|
|||||||
.PHONY: docker migration dev clean test
|
.PHONY: docker migration dev clean test build-prepare build-js build-css build-font build-go copy-templates watch-js watch-css watch-templates watch
|
||||||
|
|
||||||
DB_USER=test
|
DB_USER=test
|
||||||
DB_PASS=test
|
DB_PASS=test
|
||||||
@ -12,19 +12,57 @@ MIGRATION_TEST_DATA=./sql/dev
|
|||||||
DOCKER_COMPOSE_FILE=./docker/docker-compose.yml
|
DOCKER_COMPOSE_FILE=./docker/docker-compose.yml
|
||||||
DOCKER_COMPOSE=docker-compose -f $(DOCKER_COMPOSE_FILE)
|
DOCKER_COMPOSE=docker-compose -f $(DOCKER_COMPOSE_FILE)
|
||||||
|
|
||||||
|
build-prepare:
|
||||||
|
mkdir -p ./build/public/js
|
||||||
|
mkdir -p ./build/public/css
|
||||||
|
mkdir -p ./build/templates
|
||||||
|
mkdir -p ./build/public/img/movies
|
||||||
|
|
||||||
|
build-js: build-prepare
|
||||||
|
node node_modules/.bin/browserify src/public/js/app.js -o build/public/js/app.js
|
||||||
|
|
||||||
|
build-css: build-prepare
|
||||||
|
node ./node_modules/.bin/lessc --include-path=./node_modules src/public/less/app.less build/public/css/app.css
|
||||||
|
|
||||||
|
build-font: build-prepare
|
||||||
|
node ./node_modules/.bin/fontify
|
||||||
|
|
||||||
|
build-go: build-prepare
|
||||||
|
go build -o ./build/canape src/main.go
|
||||||
|
|
||||||
|
copy-templates: build-prepare
|
||||||
|
cp -r ./src/templates/* ./build/templates
|
||||||
|
|
||||||
|
build: build-js build-css build-font copy-templates build-go
|
||||||
|
|
||||||
|
watch-js: build-prepare
|
||||||
|
node ./node_modules/.bin/nodemon -e js -w src/public/js/app.js -x 'make build-js' &
|
||||||
|
|
||||||
|
watch-css: build-prepare
|
||||||
|
node ./node_modules/.bin/nodemon -e less -w src/public/less/app.less -x 'make build-css' &
|
||||||
|
|
||||||
|
watch-templates: build-prepare
|
||||||
|
node ./node_modules/.bin/nodemon -e tmpl -w src/templates -x 'make copy-templates' &
|
||||||
|
|
||||||
|
watch-go: build-prepare
|
||||||
|
CONFIG_FILE="./config.yml" fresh -c fresh.conf
|
||||||
|
|
||||||
|
watch: watch-js watch-css watch-templates watch-go
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
$(DOCKER_COMPOSE) up -d
|
$(DOCKER_COMPOSE) up -d
|
||||||
sleep 2
|
sleep 4
|
||||||
|
|
||||||
migration:
|
migration:
|
||||||
$(MIGRATION) -path $(MIGRATION_SCHEMA) up
|
$(MIGRATION) -path $(MIGRATION_SCHEMA) up
|
||||||
$(MIGRATION) -path $(MIGRATION_TEST_DATA) up
|
$(MIGRATION) -path $(MIGRATION_TEST_DATA) up
|
||||||
|
|
||||||
dev: docker migration
|
dev: docker migration watch
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
-rm -r ./build
|
||||||
$(DOCKER_COMPOSE) stop
|
$(DOCKER_COMPOSE) stop
|
||||||
$(DOCKER_COMPOSE) rm --force --all
|
$(DOCKER_COMPOSE) rm --force -v
|
||||||
|
|
||||||
test: docker
|
test: docker
|
||||||
POSTGRES_DSN="$(DB_DSN_TEST)" go test -v -p=1 ./...
|
POSTGRES_DSN="$(DB_DSN_TEST)" go test -v -p=1 ./...
|
||||||
|
61
README.md
61
README.md
@ -1,10 +1,34 @@
|
|||||||
|
## Install dependencies
|
||||||
|
|
||||||
|
Go dependancies:
|
||||||
|
|
||||||
|
```
|
||||||
|
go get -v github.com/pilu/fresh
|
||||||
|
go get -v github.com/mattes/migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
NPM dependencies:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
### NOTE: for debian users
|
||||||
|
|
||||||
|
If you use debian the node binary is named nodejs you have to symlink it to node:
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
# ln -s /usr/bin/nodejs /usr/bin/node
|
||||||
|
```
|
||||||
|
|
||||||
## Dev
|
## Dev
|
||||||
|
|
||||||
```
|
```
|
||||||
make dev
|
make dev
|
||||||
```
|
```
|
||||||
|
|
||||||
To setup the dev env.
|
To setup the dev env, run server, and auto-reload on file changes
|
||||||
|
|
||||||
## Connect to the database
|
## Connect to the database
|
||||||
|
|
||||||
@ -25,45 +49,16 @@ make test
|
|||||||
make clean
|
make clean
|
||||||
```
|
```
|
||||||
|
|
||||||
## Debian user
|
|
||||||
|
|
||||||
If you use debian the node binary is named nodejs you have to symlink it to node:
|
|
||||||
|
|
||||||
```
|
|
||||||
# ln -s /usr/bin/nodejs /usr/bin/node
|
|
||||||
```
|
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
Install npm depedencies
|
|
||||||
|
|
||||||
```
|
```
|
||||||
npm install
|
make build
|
||||||
```
|
|
||||||
|
|
||||||
Then run build
|
|
||||||
|
|
||||||
```
|
|
||||||
npm run build
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Watch js and less update
|
## Watch js and less update, and auto-reload server
|
||||||
|
|
||||||
```
|
```
|
||||||
npm run watch
|
make watch
|
||||||
```
|
|
||||||
|
|
||||||
## Auto reload web server
|
|
||||||
|
|
||||||
First install fresh
|
|
||||||
|
|
||||||
```
|
|
||||||
go get github.com/pilu/fresh
|
|
||||||
```
|
|
||||||
|
|
||||||
Then run it
|
|
||||||
|
|
||||||
```
|
|
||||||
fresh -c fresh.conf
|
|
||||||
```
|
```
|
||||||
|
@ -3,15 +3,6 @@
|
|||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "``` make dev ```",
|
"description": "``` make dev ```",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
|
||||||
"build-js": "mkdir -p ./build/public/js & node node_modules/.bin/browserify src/public/js/app.js -o build/public/js/app.js",
|
|
||||||
"build-less": "mkdir -p ./build/public/css & node ./node_modules/.bin/lessc --include-path=./node_modules src/public/less/app.less build/public/css/app.css",
|
|
||||||
"build-font": "mkdir -p ./build & node ./node_modules/.bin/fontify",
|
|
||||||
"watch-js": "node ./node_modules/.bin/nodemon -e js -w src/public/js/app.js -x 'npm run build-js'",
|
|
||||||
"watch-less": "node ./node_modules/.bin/nodemon -e less -w src/public/less/app.less -x 'npm run build-less'",
|
|
||||||
"build": "npm run build-js & npm run build-less & npm run build-font",
|
|
||||||
"watch": "npm run watch-js & npm run watch-less"
|
|
||||||
},
|
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "ssh://git@gitlab.quimbo.fr:5022/odwrtw/canape-sql.git"
|
"url": "ssh://git@gitlab.quimbo.fr:5022/odwrtw/canape-sql.git"
|
||||||
|
@ -12,6 +12,8 @@ type Config struct {
|
|||||||
PGDSN string `yaml:"pgdsn"`
|
PGDSN string `yaml:"pgdsn"`
|
||||||
Port string `yaml:"listen_port"`
|
Port string `yaml:"listen_port"`
|
||||||
TraktTVClientID string `yaml:"trakttv_client_id"`
|
TraktTVClientID string `yaml:"trakttv_client_id"`
|
||||||
|
TemplatesDir string `yaml:"templates_dir"`
|
||||||
|
PublicDir string `yaml:"public_dir"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthorizerConfig struct {
|
type AuthorizerConfig struct {
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/odwrtw/papi"
|
"github.com/odwrtw/papi"
|
||||||
"github.com/odwrtw/polochon/lib"
|
"github.com/odwrtw/polochon/lib"
|
||||||
@ -82,7 +83,7 @@ func FromPolochon(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
|||||||
|
|
||||||
for _, m := range movies {
|
for _, m := range movies {
|
||||||
m.Detailers = []polochon.Detailer{detailer}
|
m.Detailers = []polochon.Detailer{detailer}
|
||||||
err := m.GetDetails(env.Database, env.Log)
|
err := m.GetDetails(env.Database, filepath.Join(env.Config.PublicDir, "img", "movies"), env.Log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
env.Log.Error(err)
|
env.Log.Error(err)
|
||||||
}
|
}
|
||||||
@ -121,7 +122,7 @@ func ExplorePopular(env *web.Env, w http.ResponseWriter, r *http.Request) error
|
|||||||
for _, m := range tmovies {
|
for _, m := range tmovies {
|
||||||
movie := New(m.IDs.ImDB)
|
movie := New(m.IDs.ImDB)
|
||||||
movie.Detailers = []polochon.Detailer{detailer}
|
movie.Detailers = []polochon.Detailer{detailer}
|
||||||
err := movie.GetDetails(env.Database, env.Log)
|
err := movie.GetDetails(env.Database, filepath.Join(env.Config.PublicDir, "img", "movies"), env.Log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
env.Log.Error(err)
|
env.Log.Error(err)
|
||||||
continue
|
continue
|
||||||
|
@ -77,7 +77,7 @@ func (m *Movie) Get(db *sqlx.DB) error {
|
|||||||
// GetDetails retrieves details for the movie, first try to
|
// GetDetails retrieves details for the movie, first try to
|
||||||
// get info from db, if not exists, use polochon.Detailer
|
// get info from db, if not exists, use polochon.Detailer
|
||||||
// and save informations in the database for future use
|
// and save informations in the database for future use
|
||||||
func (m *Movie) GetDetails(db *sqlx.DB, log *logrus.Entry) error {
|
func (m *Movie) GetDetails(db *sqlx.DB, imgPath string, log *logrus.Entry) error {
|
||||||
var err error
|
var err error
|
||||||
err = m.Get(db)
|
err = m.Get(db)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -101,7 +101,7 @@ func (m *Movie) GetDetails(db *sqlx.DB, log *logrus.Entry) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Download poster
|
// Download poster
|
||||||
err = web.Download(m.Thumb, filepath.Join("./build/public/img/movies", m.ImdbID+".jpg"))
|
err = web.Download(m.Thumb, filepath.Join(imgPath, m.ImdbID+".jpg"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -26,11 +26,10 @@ type Env struct {
|
|||||||
|
|
||||||
// EnvParams represents parameters for NewEnv
|
// EnvParams represents parameters for NewEnv
|
||||||
type EnvParams struct {
|
type EnvParams struct {
|
||||||
Database *sqlx.DB
|
Database *sqlx.DB
|
||||||
Auth *auth.Authorizer
|
Auth *auth.Authorizer
|
||||||
Log *logrus.Entry
|
Log *logrus.Entry
|
||||||
Config *config.Config
|
Config *config.Config
|
||||||
TemplatesDir string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEnv returns a new *Env
|
// NewEnv returns a new *Env
|
||||||
@ -50,7 +49,7 @@ func NewEnv(p EnvParams) *Env {
|
|||||||
})
|
})
|
||||||
|
|
||||||
e.Render = render.New(render.Options{
|
e.Render = render.New(render.Options{
|
||||||
Directory: p.TemplatesDir,
|
Directory: p.Config.TemplatesDir,
|
||||||
Layout: "layout",
|
Layout: "layout",
|
||||||
Funcs: tmplFuncs,
|
Funcs: tmplFuncs,
|
||||||
DisableHTTPErrorRendering: true,
|
DisableHTTPErrorRendering: true,
|
||||||
|
20
src/main.go
20
src/main.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/auth"
|
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/auth"
|
||||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/config"
|
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/config"
|
||||||
@ -25,8 +26,14 @@ func (b *UserBackend) Get(username string) (auth.User, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var cfgPath string
|
||||||
|
cfgPath = os.Getenv("CONFIG_FILE")
|
||||||
|
if cfgPath == "" {
|
||||||
|
cfgPath = "./config.yml"
|
||||||
|
}
|
||||||
|
|
||||||
log := logrus.NewEntry(logrus.New())
|
log := logrus.NewEntry(logrus.New())
|
||||||
cf, err := config.Load("config.yml")
|
cf, err := config.Load(cfgPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
@ -47,11 +54,10 @@ func main() {
|
|||||||
authorizer := auth.New(authParams)
|
authorizer := auth.New(authParams)
|
||||||
|
|
||||||
env := web.NewEnv(web.EnvParams{
|
env := web.NewEnv(web.EnvParams{
|
||||||
Database: db,
|
Database: db,
|
||||||
Auth: authorizer,
|
Auth: authorizer,
|
||||||
Log: log,
|
Log: log,
|
||||||
Config: cf,
|
Config: cf,
|
||||||
TemplatesDir: "./src/templates",
|
|
||||||
})
|
})
|
||||||
|
|
||||||
authMiddleware := auth.NewMiddleware(env.Auth)
|
authMiddleware := auth.NewMiddleware(env.Auth)
|
||||||
@ -72,7 +78,7 @@ func main() {
|
|||||||
|
|
||||||
n := negroni.Classic()
|
n := negroni.Classic()
|
||||||
n.Use(authMiddleware)
|
n.Use(authMiddleware)
|
||||||
n.Use(negroni.NewStatic(http.Dir("./build/public")))
|
n.Use(negroni.NewStatic(http.Dir(cf.PublicDir)))
|
||||||
n.UseHandler(env.Router)
|
n.UseHandler(env.Router)
|
||||||
n.Run(":" + cf.Port)
|
n.Run(":" + cf.Port)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user