Proposal: move buffalo app to cmd (#91)
* buffalo app moved to cmd * ooops: * added copy of proxy as olympus * removed buffalo test * added blank endpoint for feed * forgot db config file and storage setup * resolved comments * newlines * resolved conficts
@@ -1,5 +1,5 @@
|
||||
build:
|
||||
buffalo build
|
||||
cd cmd/proxy && buffalo build
|
||||
|
||||
run: build
|
||||
./athens
|
||||
|
||||
@@ -27,6 +27,7 @@ Download
|
||||
binary into your PATH, and then run the following from the root of this repository:
|
||||
|
||||
```console
|
||||
cd cmd/proxy
|
||||
buffalo dev
|
||||
```
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"presets": ["env"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
app_root: .
|
||||
ignored_folders:
|
||||
- vendor
|
||||
- log
|
||||
- logs
|
||||
- assets
|
||||
- public
|
||||
- grifts
|
||||
- tmp
|
||||
- bin
|
||||
- node_modules
|
||||
- .sass-cache
|
||||
included_extensions:
|
||||
- .go
|
||||
- .env
|
||||
build_path: tmp
|
||||
build_delay: 200ns
|
||||
binary_name: olympus-build
|
||||
command_flags: []
|
||||
enable_colors: true
|
||||
log_name: buffalo
|
||||
@@ -0,0 +1,36 @@
|
||||
# This is a multi-stage Dockerfile and requires >= Docker 17.05
|
||||
# https://docs.docker.com/engine/userguide/eng-image/multistage-build/
|
||||
FROM gobuffalo/buffalo:v0.11.0 as builder
|
||||
|
||||
RUN mkdir -p $GOPATH/src/github.com/gomods/athens/cmd/olympus
|
||||
WORKDIR $GOPATH/src/github.com/gomods/athens/cmd/olympus
|
||||
|
||||
# this will cache the npm install step, unless package.json changes
|
||||
ADD cmd/olympus/package.json .
|
||||
ADD cmd/olympus/yarn.lock .
|
||||
RUN yarn install --no-progress
|
||||
|
||||
WORKDIR $GOPATH/src/github.com/gomods/athens
|
||||
|
||||
ADD . .
|
||||
RUN cd cmd/olympus && buffalo build -s -o /bin/app
|
||||
|
||||
FROM alpine
|
||||
RUN apk add --no-cache bash
|
||||
RUN apk add --no-cache ca-certificates
|
||||
|
||||
WORKDIR /bin/
|
||||
|
||||
COPY --from=builder /bin/app .
|
||||
|
||||
# Comment out to run the binary in "production" mode:
|
||||
# ENV GO_ENV=production
|
||||
|
||||
# Bind the app to 0.0.0.0 so it can be seen from outside the container
|
||||
ENV ADDR=0.0.0.0
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
# Comment out to run the migrations before running the binary:
|
||||
# CMD /bin/app migrate; /bin/app
|
||||
CMD exec /bin/app
|
||||
@@ -0,0 +1,78 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/gobuffalo/buffalo"
|
||||
"github.com/gobuffalo/buffalo/middleware"
|
||||
"github.com/gobuffalo/buffalo/middleware/ssl"
|
||||
"github.com/gobuffalo/envy"
|
||||
"github.com/rs/cors"
|
||||
"github.com/unrolled/secure"
|
||||
|
||||
"github.com/gobuffalo/buffalo/middleware/csrf"
|
||||
"github.com/gobuffalo/buffalo/middleware/i18n"
|
||||
"github.com/gobuffalo/packr"
|
||||
)
|
||||
|
||||
// ENV is used to help switch settings based on where the
|
||||
// application is being run. Default is "development".
|
||||
var ENV = envy.Get("GO_ENV", "development")
|
||||
var app *buffalo.App
|
||||
|
||||
// T is buffalo Translator
|
||||
var T *i18n.Translator
|
||||
|
||||
// App is where all routes and middleware for buffalo
|
||||
// should be defined. This is the nerve center of your
|
||||
// application.
|
||||
func App() *buffalo.App {
|
||||
if app == nil {
|
||||
app = buffalo.New(buffalo.Options{
|
||||
Env: ENV,
|
||||
PreWares: []buffalo.PreWare{
|
||||
cors.Default().Handler,
|
||||
},
|
||||
SessionName: "_olympus_session",
|
||||
})
|
||||
// Automatically redirect to SSL
|
||||
app.Use(ssl.ForceSSL(secure.Options{
|
||||
SSLRedirect: ENV == "production",
|
||||
SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"},
|
||||
}))
|
||||
|
||||
if ENV == "development" {
|
||||
app.Use(middleware.ParameterLogger)
|
||||
}
|
||||
initializeTracing(app)
|
||||
// Protect against CSRF attacks. https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)
|
||||
// Remove to disable this.
|
||||
csrfMiddleware := csrf.New
|
||||
app.Use(csrfMiddleware)
|
||||
|
||||
// Wraps each request in a transaction.
|
||||
// c.Value("tx").(*pop.PopTransaction)
|
||||
// Remove to disable this.
|
||||
// app.Use(middleware.PopTransaction(models.DB))
|
||||
|
||||
// Setup and use translations:
|
||||
var err error
|
||||
if T, err = i18n.New(packr.NewBox("../locales"), "en-US"); err != nil {
|
||||
app.Stop(err)
|
||||
}
|
||||
app.Use(T.Middleware())
|
||||
|
||||
storage, err := newStorage()
|
||||
if err != nil {
|
||||
log.Fatalf("error creating storage (%s)", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
app.GET("/", homeHandler)
|
||||
app.GET("/feed/{syncpoint:.*}", feedHandler(storage))
|
||||
|
||||
app.ServeFiles("/", assetsBox) // serve files from the public directory
|
||||
}
|
||||
|
||||
return app
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gobuffalo/buffalo"
|
||||
"github.com/gomods/athens/pkg/storage"
|
||||
)
|
||||
|
||||
func feedHandler(s storage.Backend) func(c buffalo.Context) error {
|
||||
return func(c buffalo.Context) error {
|
||||
if _, err := getSyncPoint(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
feed := make(map[string][]string)
|
||||
|
||||
return c.Render(http.StatusOK, olympus.JSON(feed))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"github.com/gobuffalo/buffalo"
|
||||
)
|
||||
|
||||
func homeHandler(c buffalo.Context) error {
|
||||
return c.Render(200, olympus.HTML("index.html"))
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"github.com/gobuffalo/buffalo"
|
||||
)
|
||||
|
||||
func getSyncPoint(c buffalo.Context) (string, error) {
|
||||
syncpoint := c.Param("syncpoint")
|
||||
if syncpoint == "" {
|
||||
return "", nil
|
||||
}
|
||||
return syncpoint, nil
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"github.com/gobuffalo/buffalo/render"
|
||||
"github.com/gobuffalo/packr"
|
||||
)
|
||||
|
||||
var olympus *render.Engine
|
||||
var assetsBox = packr.NewBox("../public")
|
||||
|
||||
func init() {
|
||||
olympus = render.New(render.Options{
|
||||
// HTML layout to be used for all HTML requests:
|
||||
HTMLLayout: "application.html",
|
||||
JavaScriptLayout: "application.js",
|
||||
|
||||
// Box containing all of the templates:
|
||||
TemplatesBox: packr.NewBox("../templates/olympus"),
|
||||
AssetsBox: assetsBox,
|
||||
|
||||
// Add template helpers here:
|
||||
Helpers: render.Helpers{},
|
||||
})
|
||||
}
|
||||
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 208 KiB After Width: | Height: | Size: 208 KiB |
|
Before Width: | Height: | Size: 210 KiB After Width: | Height: | Size: 210 KiB |
|
Before Width: | Height: | Size: 274 KiB After Width: | Height: | Size: 274 KiB |
|
Before Width: | Height: | Size: 206 KiB After Width: | Height: | Size: 206 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 130 KiB |
|
Before Width: | Height: | Size: 203 KiB After Width: | Height: | Size: 203 KiB |
|
Before Width: | Height: | Size: 236 KiB After Width: | Height: | Size: 236 KiB |
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 94 KiB |
|
Before Width: | Height: | Size: 370 KiB After Width: | Height: | Size: 370 KiB |
|
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 164 KiB |
|
Before Width: | Height: | Size: 137 KiB After Width: | Height: | Size: 137 KiB |
|
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 115 KiB |
|
Before Width: | Height: | Size: 146 KiB After Width: | Height: | Size: 146 KiB |
|
Before Width: | Height: | Size: 146 KiB After Width: | Height: | Size: 146 KiB |
|
Before Width: | Height: | Size: 200 KiB After Width: | Height: | Size: 200 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 73 KiB |
|
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 115 KiB |
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 67 KiB |
|
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 112 KiB |
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 116 KiB |
|
Before Width: | Height: | Size: 129 KiB After Width: | Height: | Size: 129 KiB |
|
Before Width: | Height: | Size: 156 KiB After Width: | Height: | Size: 156 KiB |
|
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 118 KiB |
|
Before Width: | Height: | Size: 155 KiB After Width: | Height: | Size: 155 KiB |
|
Before Width: | Height: | Size: 161 KiB After Width: | Height: | Size: 161 KiB |
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
|
Before Width: | Height: | Size: 166 KiB After Width: | Height: | Size: 166 KiB |
|
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 226 KiB After Width: | Height: | Size: 226 KiB |
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 131 KiB After Width: | Height: | Size: 131 KiB |
|
Before Width: | Height: | Size: 454 KiB After Width: | Height: | Size: 454 KiB |
|
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 92 KiB |
|
Before Width: | Height: | Size: 147 KiB After Width: | Height: | Size: 147 KiB |
|
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 126 KiB |
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
|
Before Width: | Height: | Size: 182 KiB After Width: | Height: | Size: 182 KiB |
|
Before Width: | Height: | Size: 442 KiB After Width: | Height: | Size: 442 KiB |
|
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 185 KiB After Width: | Height: | Size: 185 KiB |
|
Before Width: | Height: | Size: 215 KiB After Width: | Height: | Size: 215 KiB |
|
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 128 KiB |
|
Before Width: | Height: | Size: 140 KiB After Width: | Height: | Size: 140 KiB |
|
Before Width: | Height: | Size: 141 KiB After Width: | Height: | Size: 141 KiB |
|
Before Width: | Height: | Size: 209 KiB After Width: | Height: | Size: 209 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 625 KiB After Width: | Height: | Size: 625 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 294 KiB After Width: | Height: | Size: 294 KiB |
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
|
Before Width: | Height: | Size: 313 KiB After Width: | Height: | Size: 313 KiB |
|
Before Width: | Height: | Size: 113 KiB After Width: | Height: | Size: 113 KiB |
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 208 KiB After Width: | Height: | Size: 208 KiB |
|
Before Width: | Height: | Size: 950 B After Width: | Height: | Size: 950 B |
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 424 KiB After Width: | Height: | Size: 424 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 174 KiB After Width: | Height: | Size: 174 KiB |
|
Before Width: | Height: | Size: 838 KiB After Width: | Height: | Size: 838 KiB |
|
Before Width: | Height: | Size: 838 KiB After Width: | Height: | Size: 838 KiB |
@@ -1,6 +1,6 @@
|
||||
development:
|
||||
dialect: "mysql"
|
||||
database: vgoprox
|
||||
database: olympusdb
|
||||
host: 127.0.0.1
|
||||
port: 3307
|
||||
user: vgp
|
||||
@@ -8,7 +8,7 @@ development:
|
||||
|
||||
test:
|
||||
dialect: "mysql"
|
||||
database: vgoprox
|
||||
database: olympusdb
|
||||
host: 127.0.0.1
|
||||
port: 3306
|
||||
user: vgp
|
||||
@@ -16,7 +16,7 @@ test:
|
||||
|
||||
production:
|
||||
dialect: "mysql"
|
||||
database: vgoprox
|
||||
database: olympusdb
|
||||
host: {{ env "DB_HOST" }}
|
||||
port: {{ env "DB_PORT" }}
|
||||
user: {{ env "DB_USER" }}
|
||||