Skip to content

Commit

Permalink
Overridable OpenAPI Spec (#140)
Browse files Browse the repository at this point in the history
* Add merging of 2 Go maps recursively.

* Add overrides

* Fix linter errors.

* Add openapi overriding into helm charts.

* Add openapi compiling into build api step.

* Remove overriding settings.

* Rename api override helm value key.

* Update name

* Make builds more consistent, allow openapi bundle file name to be passed

* Add envvars needed for swagger-ui.

* Fix spec file argument name.

* Fix err, shift env to api dockerfile

* Fix api docker vs full turing docker image env

* Change CI config from buildtime docker env to runtime.

* Reworked configuration and how openapi specs are used.

* fix linting errors.

* Fix indentation, prevent creation of override spec if empty override.

* Refactor serving openapi yaml to generic name and small fixes.

* Refactor spec file merging.

* Fix compile errors.

* Run fmt.

* Fix nil pointer and fix ci
  • Loading branch information
ashwinath authored Jan 17, 2022
1 parent 4e09722 commit 1de5d83
Show file tree
Hide file tree
Showing 31 changed files with 3,547 additions and 97 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

!api/**
!ui/build/**
!docker-entrypoint.sh
!docker-entrypoint.sh
!scripts/swagger-ui-generator/**
8 changes: 1 addition & 7 deletions .github/workflows/turing-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ jobs:
name: turing-ui-dist
path: ui/build

- name: Download Swagger UI Dist
uses: actions/download-artifact@v2
with:
name: swagger-ui-dist
path: api/api/swagger-ui-dist

- name: Build and Publish Turing Docker image
env:
DOCKER_REGISTRY: ${{ inputs.container_registry }}/${{ github.repository_owner }}
Expand All @@ -89,4 +83,4 @@ jobs:
run: |
docker image load --input turing-api.${{ inputs.api_version }}.tar
make build-image
docker push ${{ env.DOCKER_REGISTRY }}/turing:${{ env.OVERWRITE_VERSION }}
docker push ${{ env.DOCKER_REGISTRY }}/turing:${{ env.OVERWRITE_VERSION }}
31 changes: 8 additions & 23 deletions .github/workflows/turing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,6 @@ jobs:
path: ui/build/
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}

build-swagger-ui:
runs-on: ubuntu-latest
defaults:
run:
working-directory: api/api
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Build static Swagger UI dist
run: make swagger-ui-dist

- name: Publish Artifact
uses: actions/upload-artifact@v2
with:
name: swagger-ui-dist
path: api/api/swagger-ui-dist/
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}

build-api:
runs-on: ubuntu-latest
needs:
Expand Down Expand Up @@ -352,17 +333,22 @@ jobs:
- name: Check out code
uses: actions/checkout@v2

- name: Download Turing API Docker tar archieve
- name: Set up Go 1.14
uses: actions/setup-go@v2
with:
go-version: "1.14"

- name: Download Turing API Docker tar archive
uses: actions/download-artifact@v2
with:
name: turing-api.${{ env.TURING_API_VERSION }}.tar

- name: Download Turing Router Docker tar archieve
- name: Download Turing Router Docker tar archive
uses: actions/download-artifact@v2
with:
name: turing-router.${{ env.TURING_ROUTER_VERSION }}.tar

- name: Download Cluster Init Docker tar archieve
- name: Download Cluster Init Docker tar archive
uses: actions/download-artifact@v2
with:
name: cluster-init.${{ env.CLUSTER_INIT_VERSION }}.tar
Expand Down Expand Up @@ -554,7 +540,6 @@ jobs:
- build-router
- build-api
- build-ui
- build-swagger-ui
- release-rules
- test-e2e
uses: gojek/turing/.github/workflows/turing-publish.yaml@main
Expand Down
22 changes: 16 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@ FROM ${TURING_API_IMAGE}
ARG TURING_USER=${TURING_USER:-turing}
ARG TURING_USER_GROUP=${TURING_USER_GROUP:-app}

ENV TURINGUICONFIG_SERVINGDIRECTORY "/app/turing-ui"

USER root
RUN apk add --no-cache bash
USER ${TURING_USER}

ARG TURING_UI_DIST_PATH=ui/build
ARG SWAGGER_UI_DIST_PATH=api/api/swagger-ui-dist
# Override the swagger ui config
ENV OPENAPICONFIG_SWAGGERUICONFIG_SERVINGDIRECTORY "/app/swagger-ui"
ENV OPENAPICONFIG_YAMLSERVINGURL "/static/openapi.bundle.yaml"

ENV TURINGUICONFIG_SERVINGDIRECTORY "./turing-ui"
ENV OPENAPICONFIG_SWAGGERUICONFIG_SERVINGDIRECTORY "./swagger-ui"
# Build swagger ui deps
COPY ./scripts/swagger-ui-generator /app/swagger-ui-generator
RUN cd /app/swagger-ui-generator && ./swagger-ui-generator.sh \
--spec-url ${OPENAPICONFIG_YAMLSERVINGURL} \
--output ${OPENAPICONFIG_SWAGGERUICONFIG_SERVINGDIRECTORY}
RUN rm -rf /app/swagger-ui-generator

# Switch back to turing user
USER ${TURING_USER}
ARG TURING_UI_DIST_PATH=ui/build

COPY --chown=${TURING_USER}:${TURING_USER_GROUP} ${TURING_UI_DIST_PATH} ${TURINGUICONFIG_SERVINGDIRECTORY}/
COPY --chown=${TURING_USER}:${TURING_USER_GROUP} ${SWAGGER_UI_DIST_PATH} ${OPENAPICONFIG_SWAGGERUICONFIG_SERVINGDIRECTORY}/

COPY ./docker-entrypoint.sh ./

ENV TURING_UI_DIST_DIR ${TURINGUICONFIG_SERVINGDIRECTORY}


ENTRYPOINT ["./docker-entrypoint.sh"]
3 changes: 2 additions & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ENV PROJECT_ROOT=github.com/gojek/turing/api/turing
WORKDIR /app
COPY . .

# Build Turing binary
RUN go build \
-mod=vendor \
-o ./bin/${API_BIN_NAME} \
Expand All @@ -31,8 +32,8 @@ RUN addgroup -S ${TURING_USER_GROUP} \
&& chown -R ${TURING_USER}:${TURING_USER_GROUP} /app

COPY --chown=${TURING_USER}:${TURING_USER_GROUP} --from=api-builder /app/bin/* /app
COPY --chown=${TURING_USER}:${TURING_USER_GROUP} --from=api-builder /app/api /app/api
COPY --chown=${TURING_USER}:${TURING_USER_GROUP} --from=api-builder /app/db-migrations /app/db-migrations
COPY --chown=${TURING_USER}:${TURING_USER_GROUP} --from=api-builder /app/api/openapi.bundle.yaml /app/api/openapi.bundle.yaml

USER ${TURING_USER}
WORKDIR /app
Expand Down
3 changes: 1 addition & 2 deletions api/api/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
openapi.bundle.yaml
swagger-ui-dist/
swagger-ui-dist/
6 changes: 4 additions & 2 deletions api/api/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

all: swagger-ui-dist

.PHONY: bundle-openapi
bundle-openapi:
@docker run --rm \
Expand All @@ -16,5 +18,5 @@ bundle-openapi:
.PHONY: swagger-ui-dist
swagger-ui-dist: bundle-openapi
@../../scripts/swagger-ui-generator/swagger-ui-generator.sh \
--spec-file openapi.bundle.yaml \
--output swagger-ui-dist
--spec-url "/static/openapi.bundle.yaml" \
--output swagger-ui-dist
Loading

0 comments on commit 1de5d83

Please sign in to comment.