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_PASS=test
|
||||
@ -12,19 +12,57 @@ MIGRATION_TEST_DATA=./sql/dev
|
||||
DOCKER_COMPOSE_FILE=./docker/docker-compose.yml
|
||||
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_COMPOSE) up -d
|
||||
sleep 2
|
||||
sleep 4
|
||||
|
||||
migration:
|
||||
$(MIGRATION) -path $(MIGRATION_SCHEMA) up
|
||||
$(MIGRATION) -path $(MIGRATION_TEST_DATA) up
|
||||
|
||||
dev: docker migration
|
||||
dev: docker migration watch
|
||||
|
||||
clean:
|
||||
-rm -r ./build
|
||||
$(DOCKER_COMPOSE) stop
|
||||
$(DOCKER_COMPOSE) rm --force --all
|
||||
$(DOCKER_COMPOSE) rm --force -v
|
||||
|
||||
test: docker
|
||||
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
|
||||
|
||||
```
|
||||
make dev
|
||||
```
|
||||
|
||||
To setup the dev env.
|
||||
To setup the dev env, run server, and auto-reload on file changes
|
||||
|
||||
## Connect to the database
|
||||
|
||||
@ -25,45 +49,16 @@ make test
|
||||
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
|
||||
|
||||
Install npm depedencies
|
||||
|
||||
```
|
||||
npm install
|
||||
```
|
||||
|
||||
Then run build
|
||||
|
||||
```
|
||||
npm run build
|
||||
make build
|
||||
|
||||
```
|
||||
|
||||
## Watch js and less update
|
||||
## Watch js and less update, and auto-reload server
|
||||
|
||||
```
|
||||
npm run watch
|
||||
```
|
||||
|
||||
## Auto reload web server
|
||||
|
||||
First install fresh
|
||||
|
||||
```
|
||||
go get github.com/pilu/fresh
|
||||
```
|
||||
|
||||
Then run it
|
||||
|
||||
```
|
||||
fresh -c fresh.conf
|
||||
make watch
|
||||
```
|
||||
|
@ -3,15 +3,6 @@
|
||||
"version": "0.0.1",
|
||||
"description": "``` make dev ```",
|
||||
"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": {
|
||||
"type": "git",
|
||||
"url": "ssh://git@gitlab.quimbo.fr:5022/odwrtw/canape-sql.git"
|
||||
|
@ -12,6 +12,8 @@ type Config struct {
|
||||
PGDSN string `yaml:"pgdsn"`
|
||||
Port string `yaml:"listen_port"`
|
||||
TraktTVClientID string `yaml:"trakttv_client_id"`
|
||||
TemplatesDir string `yaml:"templates_dir"`
|
||||
PublicDir string `yaml:"public_dir"`
|
||||
}
|
||||
|
||||
type AuthorizerConfig struct {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/odwrtw/papi"
|
||||
"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 {
|
||||
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 {
|
||||
env.Log.Error(err)
|
||||
}
|
||||
@ -121,7 +122,7 @@ func ExplorePopular(env *web.Env, w http.ResponseWriter, r *http.Request) error
|
||||
for _, m := range tmovies {
|
||||
movie := New(m.IDs.ImDB)
|
||||
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 {
|
||||
env.Log.Error(err)
|
||||
continue
|
||||
|
@ -77,7 +77,7 @@ func (m *Movie) Get(db *sqlx.DB) error {
|
||||
// GetDetails retrieves details for the movie, first try to
|
||||
// get info from db, if not exists, use polochon.Detailer
|
||||
// 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
|
||||
err = m.Get(db)
|
||||
if err == nil {
|
||||
@ -101,7 +101,7 @@ func (m *Movie) GetDetails(db *sqlx.DB, log *logrus.Entry) error {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ type EnvParams struct {
|
||||
Auth *auth.Authorizer
|
||||
Log *logrus.Entry
|
||||
Config *config.Config
|
||||
TemplatesDir string
|
||||
}
|
||||
|
||||
// NewEnv returns a new *Env
|
||||
@ -50,7 +49,7 @@ func NewEnv(p EnvParams) *Env {
|
||||
})
|
||||
|
||||
e.Render = render.New(render.Options{
|
||||
Directory: p.TemplatesDir,
|
||||
Directory: p.Config.TemplatesDir,
|
||||
Layout: "layout",
|
||||
Funcs: tmplFuncs,
|
||||
DisableHTTPErrorRendering: true,
|
||||
|
12
src/main.go
12
src/main.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/auth"
|
||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/config"
|
||||
@ -25,8 +26,14 @@ func (b *UserBackend) Get(username string) (auth.User, error) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
var cfgPath string
|
||||
cfgPath = os.Getenv("CONFIG_FILE")
|
||||
if cfgPath == "" {
|
||||
cfgPath = "./config.yml"
|
||||
}
|
||||
|
||||
log := logrus.NewEntry(logrus.New())
|
||||
cf, err := config.Load("config.yml")
|
||||
cf, err := config.Load(cfgPath)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
@ -51,7 +58,6 @@ func main() {
|
||||
Auth: authorizer,
|
||||
Log: log,
|
||||
Config: cf,
|
||||
TemplatesDir: "./src/templates",
|
||||
})
|
||||
|
||||
authMiddleware := auth.NewMiddleware(env.Auth)
|
||||
@ -72,7 +78,7 @@ func main() {
|
||||
|
||||
n := negroni.Classic()
|
||||
n.Use(authMiddleware)
|
||||
n.Use(negroni.NewStatic(http.Dir("./build/public")))
|
||||
n.Use(negroni.NewStatic(http.Dir(cf.PublicDir)))
|
||||
n.UseHandler(env.Router)
|
||||
n.Run(":" + cf.Port)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user