Skip to content

Commit

Permalink
Improvements after review
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubMatejka committed Mar 1, 2022
1 parent 55f8395 commit a755e8c
Show file tree
Hide file tree
Showing 23 changed files with 222 additions and 112 deletions.
4 changes: 2 additions & 2 deletions Dockerfile-api
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ RUN GOOS=linux GOARCH=amd64 go build -v -mod mod -ldflags "-s -w" -o ./templates

FROM scratch
WORKDIR /app
COPY --from=buildContainer /go/src/app/templatesapi .
COPY --from=buildContainer /go/src/app/templatesapi /app/templatesapi

ENV HOST 0.0.0.0
ENV PORT 8000
EXPOSE 8000

CMD ["./templatesapi", "--http-port=8000", "--domain=0.0.0.0:8000"]
CMD ["/app/templatesapi", "--http-port=8000", "--domain=0.0.0.0:8000"]
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,3 @@ fix:
bash ./scripts/fix.sh

ci: mod lint tests

api-generate:
goa gen github.com/keboola/keboola-as-code/design --output ./internal/pkg/template/api
rm -rf ./internal/pkg/template/api/gen/http/cli
rm -rf ./internal/pkg/template/api/gen/http/templates/client
mv ./internal/pkg/template/api/gen/http/openapi* ./api
1 change: 0 additions & 1 deletion api/openapi.json

This file was deleted.

1 change: 0 additions & 1 deletion api/openapi3.json

This file was deleted.

31 changes: 26 additions & 5 deletions design/templates.go → api/templates/design.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// nolint: gochecknoglobals
package design
package templates

import (
_ "goa.design/goa/v3/codegen/generator"
Expand All @@ -9,9 +9,17 @@ import (
var _ = API("templates", func() {
Title("Templates Service")
Description("A service for applying templates to Keboola projects")
Version("1.0")
HTTP(func() {
Path("v1")
})
Server("templates", func() {
Host("localhost", func() {
URI("http://localhost:8000")
Host("production", func() {
URI("https://templates.{stack}")
Variable("stack", String, "Base URL of the stack", func() {
Default("keboola.com")
Enum("keboola.com", "eu-central-1.keboola.com", "north-europe.azure.keboola.com")
})
})
})
})
Expand All @@ -21,14 +29,27 @@ var index = ResultType("application/vnd.templates.index", func() {
TypeName("Index")

Attributes(func() {
Field(1, "api")
Field(2, "documentation")
Field(1, "api", String, "Name of the API", func() {
Example("templates")
})
Field(2, "documentation", String, "Url of the API documentation", func() {
Example("https://templates.keboola.com/v1/documentation")
})
Required("api", "documentation")
})
})

var _ = Service("templates", func() {
Description("Service for applying templates to Keboola projects")

Method("index-root", func() {
HTTP(func() {
// Redirect / -> /v1
GET("//")
Redirect("/v1", StatusMovedPermanently)
})
})

Method("index", func() {
Result(index)
HTTP(func() {
Expand Down
1 change: 1 addition & 0 deletions api/templates/gen/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"swagger":"2.0","info":{"title":"Templates Service","description":"A service for applying templates to Keboola projects","version":"1.0"},"host":"templates.keboola.com","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"get":{"tags":["templates"],"summary":"index-root templates","operationId":"templates#index-root","responses":{"307":{"description":"Temporary Redirect response."}},"schemes":["https"]}},"/v1":{"get":{"tags":["templates"],"summary":"index templates","operationId":"templates#index","responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/TemplatesIndexResponseBody"}}},"schemes":["https"]}},"/v1/health-check":{"get":{"tags":["templates"],"summary":"health-check templates","operationId":"templates#health-check","responses":{"200":{"description":"OK response."}},"schemes":["https"]}}},"definitions":{"TemplatesIndexResponseBody":{"title":"Mediatype identifier: application/vnd.templates.index; view=default","type":"object","properties":{"api":{"type":"string","description":"Name of the API","example":"templates"},"documentation":{"type":"string","description":"Url of the API documentation","example":"https://templates.keboola.com/v1/documentation"}},"description":"IndexResponseBody result type (default view)","example":{"api":"templates","documentation":"https://templates.keboola.com/v1/documentation"},"required":["api","documentation"]}}}
47 changes: 25 additions & 22 deletions api/openapi.yaml → api/templates/gen/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ swagger: "2.0"
info:
title: Templates Service
description: A service for applying templates to Keboola projects
version: ""
host: localhost:8000
version: "1.0"
host: templates.keboola.com
consumes:
- application/json
- application/xml
Expand All @@ -14,6 +14,17 @@ produces:
- application/gob
paths:
/:
get:
tags:
- templates
summary: index-root templates
operationId: templates#index-root
responses:
"307":
description: Temporary Redirect response.
schemes:
- https
/v1:
get:
tags:
- templates
Expand All @@ -25,8 +36,8 @@ paths:
schema:
$ref: '#/definitions/TemplatesIndexResponseBody'
schemes:
- http
/health-check:
- https
/v1/health-check:
get:
tags:
- templates
Expand All @@ -36,32 +47,24 @@ paths:
"200":
description: OK response.
schemes:
- http
/openapi.json:
get:
tags:
- templates
summary: Download ./gen/http/openapi.json
operationId: templates#/openapi.json
responses:
"200":
description: File downloaded
schema:
type: file
schemes:
- http
- https
definitions:
TemplatesIndexResponseBody:
title: 'Mediatype identifier: application/vnd.templates.index; view=default'
type: object
properties:
api:
type: string
example: Fugit numquam quidem.
description: Name of the API
example: templates
documentation:
type: string
example: Accusantium voluptas.
description: Url of the API documentation
example: https://templates.keboola.com/v1/documentation
description: IndexResponseBody result type (default view)
example:
api: Consequatur qui est ipsam provident omnis corporis.
documentation: Incidunt voluptas deserunt rem sapiente.
api: templates
documentation: https://templates.keboola.com/v1/documentation
required:
- api
- documentation
1 change: 1 addition & 0 deletions api/templates/gen/openapi3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"openapi":"3.0.3","info":{"title":"Templates Service","description":"A service for applying templates to Keboola projects","version":"1.0"},"servers":[{"url":"https://templates.{stack}","variables":{"stack":{"enum":["keboola.com","eu-central-1.keboola.com","north-europe.azure.keboola.com"],"default":"keboola.com"}}}],"paths":{"/":{"get":{"tags":["templates"],"summary":"index-root templates","operationId":"templates#index-root","responses":{"307":{"description":"Temporary Redirect response."}}}},"/v1":{"get":{"tags":["templates"],"summary":"index templates","operationId":"templates#index","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Index"},"example":{"api":"templates","documentation":"https://templates.keboola.com/v1/documentation"}}}}}}},"/v1/health-check":{"get":{"tags":["templates"],"summary":"health-check templates","operationId":"templates#health-check","responses":{"200":{"description":"OK response."}}}}},"components":{"schemas":{"Index":{"type":"object","properties":{"api":{"type":"string","description":"Name of the API","example":"templates"},"documentation":{"type":"string","description":"Url of the API documentation","example":"https://templates.keboola.com/v1/documentation"}},"example":{"api":"templates","documentation":"https://templates.keboola.com/v1/documentation"},"required":["api","documentation"]}}},"tags":[{"name":"templates","description":"Service for applying templates to Keboola projects"}]}
46 changes: 29 additions & 17 deletions api/openapi3.yaml → api/templates/gen/openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,25 @@ info:
description: A service for applying templates to Keboola projects
version: "1.0"
servers:
- url: http://localhost:8000
- url: https://templates.{stack}
variables:
stack:
enum:
- keboola.com
- eu-central-1.keboola.com
- north-europe.azure.keboola.com
default: keboola.com
paths:
/:
get:
tags:
- templates
summary: index-root templates
operationId: templates#index-root
responses:
"307":
description: Temporary Redirect response.
/v1:
get:
tags:
- templates
Expand All @@ -20,9 +36,9 @@ paths:
schema:
$ref: '#/components/schemas/Index'
example:
api: Corrupti nisi cumque.
documentation: Est aliquid nihil praesentium similique autem.
/health-check:
api: templates
documentation: https://templates.keboola.com/v1/documentation
/v1/health-check:
get:
tags:
- templates
Expand All @@ -31,29 +47,25 @@ paths:
responses:
"200":
description: OK response.
/openapi.json:
get:
tags:
- templates
summary: Download ./gen/http/openapi.json
operationId: templates#/openapi.json
responses:
"200":
description: File downloaded
components:
schemas:
Index:
type: object
properties:
api:
type: string
example: Exercitationem assumenda quo quidem sapiente harum consequuntur.
description: Name of the API
example: templates
documentation:
type: string
example: Sed dolores sunt dolorem.
description: Url of the API documentation
example: https://templates.keboola.com/v1/documentation
example:
api: Quas voluptatum.
documentation: Eius adipisci possimus dicta.
api: templates
documentation: https://templates.keboola.com/v1/documentation
required:
- api
- documentation
tags:
- name: templates
description: Service for applying templates to Keboola projects
2 changes: 1 addition & 1 deletion cmd/templates/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func handleHTTPServer(ctx context.Context, u *url.URL, templatesEndpoints *templ
)
{
eh := errorHandler(logger)
templatesServer = templatesSvr.New(templatesEndpoints, mux, dec, enc, eh, nil, nil)
templatesServer = templatesSvr.New(templatesEndpoints, mux, dec, enc, eh, nil)
if debug {
servers := goaHTTP.Servers{
templatesServer,
Expand Down
2 changes: 1 addition & 1 deletion cmd/templates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func main() {
switch *hostF {
case "localhost":
{
addr := "http://localhost:80"
addr := "http://localhost:8000"
u, err := url.Parse(addr)
if err != nil {
fmt.Fprintf(os.Stderr, "invalid URL %#v: %s\n", addr, err)
Expand Down
4 changes: 2 additions & 2 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ API development uses [Goa code generator](https://goa.design/).

When you add REST endpoints or change their behavior:

1. Change the API design first in the [design folder](../design)
2. Generate the code by running `make api-generate`
1. Change the API design first in the [api/templates/design.go](../api/templates/design.go)
2. Generate the code by running `bash scripts/generate-api.sh`
3. Implement the interfaces generated to [internal/pkg/template/api/gen/templates/service.go](../internal/pkg/template/api/gen/templates/service.go) (The service implementation is then referenced from the [cmd/templates/main.go](../cmd/templates/main.go))

To run the API locally run `docker-compose run --service-ports api`. The API is exposed to http://localhost:8000/
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions internal/pkg/template/api/gen/http/templates/server/paths.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a755e8c

Please sign in to comment.