This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit d7a81fb583ace3ed5c995440b1c995c9fadcc8ec
Author: Jesse Rivas <jesse_ri...@comcast.com>
AuthorDate: Mon Apr 16 09:37:45 2018 -0600

    Traffic Ops golang API servers test cleanup
---
 .../swaggerdocs/v13/cors-http-server.py            | 33 ----------------
 .../swaggerdocs/v13/docker-compose.yml             | 15 ++++++++
 .../swaggerdocs/v13/docker/Dockerfile              | 44 ++++++++++++++++++++++
 .../traffic_ops_golang/swaggerdocs/v13/dockgen.sh  |  5 +++
 .../traffic_ops_golang/swaggerdocs/v13/gen_docs.sh |  4 +-
 .../swaggerdocs/v13/swagger-server/Dockerfile      | 29 ++++++++++++++
 .../v13/swagger-server/swagger-server.go           | 24 ++++++++++++
 7 files changed, 119 insertions(+), 35 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/cors-http-server.py 
b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/cors-http-server.py
deleted file mode 100755
index 3c1687f..0000000
--- a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/cors-http-server.py
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/usr/bin/env python
-
-
- # Licensed to the Apache Software Foundation (ASF) under one
- # or more contributor license agreements.  See the NOTICE file
- # distributed with this work for additional information
- # regarding copyright ownership.  The ASF licenses this file
- # to you under the Apache License, Version 2.0 (the
- # "License"); you may not use this file except in compliance
- # with the License.  You may obtain a copy of the License at
- #
- #   http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing,
- # software distributed under the License is distributed on an
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- # KIND, either express or implied.  See the License for the
- # specific language governing permissions and limitations
- # under the License.
-
-from SimpleHTTPServer import SimpleHTTPRequestHandler
-import BaseHTTPServer
-
-#
-# Simple HTTP server that serves up port 8000 with the CORS header enabled
-#
-class CORSRequestHandler (SimpleHTTPRequestHandler):
-    def end_headers (self):
-        self.send_header('Access-Control-Allow-Origin', '*')
-        SimpleHTTPRequestHandler.end_headers(self)
-
-if __name__ == '__main__':
-    BaseHTTPServer.test(CORSRequestHandler, BaseHTTPServer.HTTPServer)
diff --git a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docker-compose.yml 
b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docker-compose.yml
new file mode 100644
index 0000000..ad92633
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docker-compose.yml
@@ -0,0 +1,15 @@
+version: '3.6'
+ 
+services:
+   swagger-generator:
+     build:
+       context: .
+       dockerfile: ./docker/Dockerfile
+     ports:
+       - 8000:8000
+     volumes:
+       - output:/output
+
+volumes:
+    output:
+
diff --git a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docker/Dockerfile 
b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docker/Dockerfile
new file mode 100644
index 0000000..e89ae50
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docker/Dockerfile
@@ -0,0 +1,44 @@
+# 
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+
+#  http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+FROM golang:1.10.1 AS swagger-gen
+
+RUN mkdir /go/src/v13
+WORKDIR /go/src/v13
+ADD . .
+
+RUN mkdir /output
+
+RUN go get -d -v ./...
+RUN go install -v ./...
+RUN go get -u github.com/go-swagger/go-swagger/cmd/swagger
+
+CMD ["./gen_docs.sh"]
+
+FROM golang:1.10.1 AS swagger-server
+
+#RUN mkdir /usr/src/swagger-server
+
+ADD ./swagger-server /usr/src/swagger-server
+WORKDIR /usr/src/swagger-server
+
+
+COPY --from=swagger-gen /output /output
+
+RUN go build 
+CMD ["./swagger-server"]
diff --git a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/dockgen.sh 
b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/dockgen.sh
new file mode 100755
index 0000000..c2bed7f
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/dockgen.sh
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+rm ./swagger.json
+docker build -t tc-swaggerdocs -f Dockerfile-swagger-gen .
+docker run --rm -it -v `(pwd)`:/output tc-swaggerdocs
diff --git a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/gen_docs.sh 
b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/gen_docs.sh
index a7c7154..02ccec2 100755
--- a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/gen_docs.sh
+++ b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/gen_docs.sh
@@ -19,5 +19,5 @@
 
 unset DEBUG
 #export DEBUG=true
-swagger generate spec -o ./swagger.json
-echo "successfully generated the swagger.json file"
+swagger generate spec -o /output/swagger.json
+echo "successfully generated swagger output file: ./swagger.json"
diff --git 
a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/swagger-server/Dockerfile 
b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/swagger-server/Dockerfile
new file mode 100644
index 0000000..8deba91
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/swagger-server/Dockerfile
@@ -0,0 +1,29 @@
+# 
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+
+#  http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+FROM golang:1.10.1 AS swagger-server
+
+WORKDIR /usr/src/app
+COPY /output/swagger.json .
+
+ADD . .
+RUN go build 
+
+COPY --from=swagger-gen /output /output
+
+CMD ["./app"]
diff --git 
a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/swagger-server/swagger-server.go
 
b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/swagger-server/swagger-server.go
new file mode 100644
index 0000000..a873ad7
--- /dev/null
+++ 
b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/swagger-server/swagger-server.go
@@ -0,0 +1,24 @@
+package main
+
+import (
+       "flag"
+       "log"
+       "net/http"
+)
+
+func main() {
+       port := flag.String("p", "8000", "port to serve on")
+       flag.Parse()
+
+       swaggerFile := "swagger.json"
+
+       http.HandleFunc("/swagger.json", func(w http.ResponseWriter, r 
*http.Request) {
+               w.Header().Set("Access-Control-Allow-Credentials", "true")
+               w.Header().Set("Access-Control-Allow-Headers", "Origin, 
X-Requested-With, Content-Type, Accept, Set-Cookie, Cookie")
+               w.Header().Set("Access-Control-Allow-Methods", 
"POST,GET,OPTIONS,PUT,DELETE")
+               w.Header().Set("Access-Control-Allow-Origin", "*")
+               http.ServeFile(w, r, swaggerFile)
+       })
+       log.Printf("Serving %s on HTTP port: %s\n", swaggerFile, *port)
+       log.Fatal(http.ListenAndServe(":"+*port, nil))
+}

-- 
To stop receiving notification emails like this one, please contact
mitchell...@apache.org.

Reply via email to