Merge branch 'doc' into master 77/214177/1 master
authorPawel Wieczorek <p.wieczorek2@samsung.com>
Wed, 18 Sep 2019 16:32:07 +0000 (18:32 +0200)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Wed, 18 Sep 2019 16:37:01 +0000 (18:37 +0200)
Change-Id: I7d91b0d81f8d61c151d5e8693430c5e73a995e58

1  2 
Makefile

diff --cc Makefile
+++ b/Makefile
@@@ -12,49 -10,24 +12,57 @@@ rwildcard=$(foreach d,$(wildcard $1*),$
  WELES_FILES = $(filter-out *_test.go, $(call rwildcard, , *.go))
  
  SERVER_MAIN = cmd/weles-server/main.go
 -SERVER_BIN = $(BIN_DIR)/weles-server
 +SERVER_BIN = $(BIN_DIR)/weles
 +
 +BUILD_DOCKER_IMAGE = weles-build-img
 +BUILD_DOCKER_CONTAINER = weles-build
  
 -.PHONY: weles
 -weles: vendor $(WELES_FILES)
 -      go build -o $(SERVER_BIN) $(SERVER_MAIN)
+ DOC_DIR = doc
+ SPHINX_DOCKER_IMAGE = weles-doc-image
+ SPHINX_DOCKER_CONTAINER = weles-doc-container
+ SPHINX_DOCKER_CONTAINER_WORKDIR = /doc
+ SWAGGER_DOCKER_IMAGE = swaggerapi/swagger-codegen-cli
+ SWAGGER_DOCKER_CONTAINER = weles-swagger-container
+ SWAGGER_DOCKER_CONTAINER_WORKDIR = /local
 +.PHONY: all
 +all: docker-build
 +
 +.PHONY: clean
 +clean: clean-docker-build
 +
 +.PHONY: docker-build
 +docker-build: $(SERVER_BIN)
 +      docker rm $(BUILD_DOCKER_CONTAINER)
 +
 +$(SERVER_BIN): docker-container | $(BIN_DIR)
 +      docker cp "$(BUILD_DOCKER_CONTAINER):/$(@F)" $(@)
 +
 +.PHONY: docker-container
 +docker-container: docker-build-img
 +      docker create --name "$(BUILD_DOCKER_CONTAINER)" "$(BUILD_DOCKER_IMAGE)"
 +
 +.PHONY: docker-build-img
 +docker-build-img:
 +      docker build --tag "$(BUILD_DOCKER_IMAGE)" .
 +
 +$(BIN_DIR):
 +      mkdir -p "$(BIN_DIR)"
 +
 +.PHONY: clean-docker-build
 +clean-docker-build:
 +      -docker rm $(BUILD_DOCKER_CONTAINER)
 +      -docker rmi $(BUILD_DOCKER_IMAGE)
 +      -rm -f "$(SERVER_BIN)"
 +      -rmdir "$(BIN_DIR)"
  
 -# server recipe generates Weles server code. dep ensure is run after swagger
 -# generation to update Gopkg.lock with packages needed to build server.
  .PHONY: server
 -server:  swagger.yml COPYING
 +server: vendor $(WELES_FILES)
 +      go build -o $(SERVER_BIN) $(SERVER_MAIN)
 +
 +# dep ensure is run after swagger generation to update Gopkg.lock with packages needed to build server
 +.PHONY: swagger-server-generate
 +swagger-server-generate:  swagger.yml COPYING
        ./$(DEV_TOOLS_DIR)/swagger generate server \
                -A weles \
                -f ./swagger.yml \
                --compatibility-mode=modern
        dep ensure
  
- .PHONY: swagger-docs-html
- swagger-docs-html: swagger.yml
-       mkdir -p doc/build/swagger
 +.PHONY: swagger-models-generate
 +swagger-models-generate:  swagger.yml COPYING
 +      ./$(DEV_TOOLS_DIR)/swagger generate model \
 +              -f ./swagger.yml \
 +              -m ../weles \
 +              -s ./server \
 +              -r ./COPYING \
 +
+ .PHONY: docs
+ docs: docs-swagger docs-sphinx
+ .PHONY: clean-docs
+ clean-docs: clean-docs-swagger clean-docker-swagger clean-docs-sphinx clean-docker-sphinx
+ .PHONY: docs-sphinx
+ docs-sphinx: docker-image-sphinx
        docker run \
                --rm \
-               -v $$PWD:/local \
-               --user `id -u $$USER`:`id -g $$USER` \
-               swaggerapi/swagger-codegen-cli \
+               --volume "`pwd`:${SPHINX_DOCKER_CONTAINER_WORKDIR}" \
+               --user "`id -u $$USER`:`id -g $$USER`" \
+               --name "${SPHINX_DOCKER_CONTAINER}" "${SPHINX_DOCKER_IMAGE}" \
+               make -C "${SPHINX_DOCKER_CONTAINER_WORKDIR}/${DOC_DIR}" html
+ .PHONY: docker-image-sphinx
+ docker-image-sphinx:
+       docker build -t "${SPHINX_DOCKER_IMAGE}" ${DOC_DIR}
+ .PHONY: clean-docs-sphinx
+ clean-docs-sphinx:
+       -rm -r "${DOC_DIR}/build"
+ .PHONY: clean-docker-sphinx
+ clean-docker-sphinx:
+       -docker rm "${SPHINX_DOCKER_CONTAINER}"
+       -docker rmi "${SPHINX_DOCKER_IMAGE}"
+ # docs-swagger generates API documentation in HTML format, to be used by
+ # Sphinx.
+ .PHONY: docs-swagger
+ docs-swagger: swagger.yml
+       mkdir -p ${DOC_DIR}/source/_static/swagger
+       docker run \
+               --rm \
+               -v "`pwd`:${SWAGGER_DOCKER_CONTAINER_WORKDIR}" \
+               --user "`id -u $$USER`:`id -g $$USER`" \
+               --name "${SWAGGER_DOCKER_CONTAINER}" \
+               "${SWAGGER_DOCKER_IMAGE}"\
                generate \
-                       -i local/swagger.yml \
+                       -i "${SWAGGER_DOCKER_CONTAINER_WORKDIR}/swagger.yml" \
                        -l html \
-                       -o /local/doc/build/swagger/
+                       -o "${SWAGGER_DOCKER_CONTAINER_WORKDIR}/${DOC_DIR}/source/_static/swagger/"
+ .PHONY: clean-docs-swagger
+ clean-docs-swagger:
+       -rm -rf doc/source/_static/swagger
+ .PHONY: clean-docker-swagger
+ clean-docker-swagger:
+       -docker rm "${SWAGGER_DOCKER_CONTAINER}"
+       -docker rmi "${SWAGGER_DOCKER_IMAGE}"
  
 -
  vendor: Gopkg.lock
        dep ensure -v -vendor-only