Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docker/swagger support #243

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
kala
.idea/*
.DS_Store
/vendor
34 changes: 30 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
FROM golang
FROM golang:1.13-alpine as builder

WORKDIR /go/src/github.com/ajvb/kala
# Set the Current Working Directory inside the container
WORKDIR /app

# Copy the source from the current directory to the Working Directory inside the container
COPY . .
RUN go build && mv kala /usr/bin

CMD ["kala", "serve"]
# Build the Go app
RUN go version \
&& export GO111MODULE=on \
&& export GOPROXY=https://goproxy.io \
&& go mod vendor \
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o kala


FROM alpine:latest

WORKDIR /app

# Copy the Pre-built binary file from the previous stage
COPY --from=builder /app/kala .
COPY --from=builder /app/webui ./webui

RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64 \
&& chmod +x /usr/local/bin/dumb-init \
&& cp /app/kala /usr/bin/

EXPOSE 8000

ENTRYPOINT ["dumb-init", "--"]

CMD ["kala", "serve"]

273 changes: 273 additions & 0 deletions api/swagger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
//Package Kala Kala API
//
//Kala API
//
//
// Schemes: http, https
// Host: API_HOST
// BasePath: /api/v1/
// Version: 1.0.1
//
// Consumes:
// - multipart/form-data
// - application/json
//
// Produces:
// - application/json
//
//swagger:meta
package api

//
// swagger:operation POST /job/ jobs createJob
//
// Creating a Job
//
// ---
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: body
// in: body
// required: true
// schema:
// type: object
// required:
// - name
// - type
// properties:
// name:
// type: string
// type:
// type: number
// enum: [0, 1]
// default: 0
// owner:
// type: string
// schedule:
// type: string
// retries:
// type: number
// epsilon:
// type: string
// remote_properties:
// type: object
// properties:
// url:
// type: string
// method:
// type: string
// body:
// type: string
// headers:
// type: array
// items:
// type: object
// properties:
// key:
// type: string
// value:
// type: string
// timeout:
// type: number
// expected_response_codes:
// type: array
// items:
// type: number
// default: [200]
// responses:
// 200:
// description: OK
// 500:
// description: Error
//
//

//
// swagger:operation GET /job jobs getAllJobs
//
// Getting a list of all Jobs
//
// ---
// consumes:
// - application/json
// produces:
// - application/json
// responses:
// 200:
// description: OK
// 500:
// description: Error
//
//

//
// swagger:operation GET /job/{id}/ jobs getJob
//
// Getting a Job
//
// ---
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: id
// in: path
// required: true
// responses:
// 200:
// description: OK
// 500:
// description: Error
//
//

//
// swagger:operation DELETE /job/{id}/ jobs removeJob
//
// Deleting a Job
//
// ---
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: id
// in: path
// required: true
// responses:
// 200:
// description: OK
// 500:
// description: Error
//
//

//
// swagger:operation DELETE /job/all/ jobs removeAllJob
//
// Deleting all Jobs
//
// ---
// consumes:
// - application/json
// produces:
// - application/json
// responses:
// 200:
// description: OK
// 500:
// description: Error
//
//


//
// swagger:operation GET /job/stats/{id}/ jobs statsJob
//
// Getting metrics about a certain Job
//
// ---
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: id
// in: path
// required: true
// responses:
// 200:
// description: OK
// 500:
// description: Error
//
//

//
// swagger:operation POST /job/start/{id}/ jobs startJob
//
// Starting a Job manually
//
// ---
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: id
// in: path
// required: true
// responses:
// 204:
// description: OK
// 500:
// description: Error
//
//

//
// swagger:operation POST /job/disable/{id}/ jobs disableJob
//
// Disabling a Job
//
// ---
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: id
// in: path
// required: true
// responses:
// 204:
// description: OK
// 500:
// description: Error
//
//

//
// swagger:operation POST /job/enable/{id}/ jobs enableJob
//
// Enabling a Job
//
// ---
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: id
// in: path
// required: true
// responses:
// 204:
// description: OK
// 500:
// description: Error
//
//

//
// swagger:operation GET /stats/ stats statsAPP
//
// Getting app-level metrics
//
// ---
// consumes:
// - application/json
// produces:
// - application/json
// responses:
// 200:
// description: OK
// 500:
// description: Error
//
//
4 changes: 4 additions & 0 deletions webui/js/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ var actions = (function() {
});
} else if (val) {
job[key] = val;
if (/(timeout|body|method|url|headers)/i.test(key)) {
job['remote_properties'] = job['remote_properties'] || {};
job['remote_properties'][key] = job[key];
}
}
}
} catch ( err ) {
Expand Down
134 changes: 134 additions & 0 deletions webui/js/swagger/swagger-ui-bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions webui/js/swagger/swagger-ui-bundle.js.map

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions webui/js/swagger/swagger-ui-standalone-preset.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions webui/js/swagger/swagger-ui-standalone-preset.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions webui/js/swagger/swagger-ui.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions webui/js/swagger/swagger-ui.css.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions webui/js/swagger/swagger-ui.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions webui/js/swagger/swagger-ui.js.map

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions webui/swagger.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="js/swagger/swagger-ui.css">
<style>
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

*,
*:before,
*:after {
box-sizing: inherit;
}

body {
margin: 0;
background: #fafafa;
}
</style>
</head>

<body>

<div id="swagger-ui"></div>

<script src="js/swagger/swagger-ui-bundle.js"></script>
<script src="js/swagger/swagger-ui-standalone-preset.js"></script>
<script>
window.onload = function () {

// Begin Swagger UI call region
var ui = SwaggerUIBundle({
url: "./swagger.json",
requestInterceptor: function (request) {
// Replace the default host by the correct one.
// DO NOT CHANGE here without changing application.conf
request.url = request.url.replace("API_HOST", location.host);
return request;
},
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
// End Swagger UI call region

window.ui = ui
}
</script>
</body>
</html>
Loading