Skip to content

Commit

Permalink
[online] Remove GENERATOR_HOST defaults (#3289)
Browse files Browse the repository at this point in the history
The defaults configured for GENERATOR_HOST didn't really make sense.
When running the docker container with `-P`, GENERATOR_HOST defaulted to
http://localhost. This caused download links for generated client/server
code to be incorrect. For most cases, there's no reason to provide
GENERATOR_HOST as the code already figures the appropriate
scheme/host/port from the originating request.

GENERATOR_HOST could still be used for more complex deployment
scenarios, for instance if a specific server is configured as a file
server. I haven't tested this scenario, and it may require mounting /tmp
as a volume when running within a container.
  • Loading branch information
jimschubert committed Jul 7, 2019
1 parent 366ca24 commit 51e7005
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .hub.online.dockerfile
Expand Up @@ -28,7 +28,7 @@ WORKDIR ${TARGET_DIR}

COPY --from=builder ${GEN_DIR}/modules/openapi-generator-online/target/openapi-generator-online.jar ${TARGET_DIR}/openapi-generator-online.jar

ENV GENERATOR_HOST=http://localhost
ENV GENERATOR_HOST=""

EXPOSE 8080

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -281,7 +281,7 @@ Example usage:

```sh
# Start container at port 8888 and save the container id
> CID=$(docker run -d -p 8888:8080 -e GENERATOR_HOST=http://localhost:8888 openapitools/openapi-generator-online)
> CID=$(docker run -d -p 8888:8080 openapitools/openapi-generator-online)

# allow for startup
> sleep 10
Expand Down
4 changes: 1 addition & 3 deletions docs/online.md
Expand Up @@ -23,9 +23,7 @@ Example usage:

```bash
# Start container at port 8888 and save the container id
CID=$(docker run -d -p 8888:8080 \
-e GENERATOR_HOST=http://localhost:8888 \
openapitools/openapi-generator-online)
CID=$(docker run -d -p 8888:8080 openapitools/openapi-generator-online)

# allow for startup
sleep 10
Expand Down
4 changes: 3 additions & 1 deletion modules/openapi-generator-online/Dockerfile
Expand Up @@ -6,7 +6,9 @@ COPY target/openapi-generator-online.jar /generator/openapi-generator-online.jar

# GENERATOR_HOST can be used to determine the target location of a download link.
# The default value asumes binding to host via: docker -p 8080:8080 image_name
ENV GENERATOR_HOST=http://localhost:8080
# Generally, this "just works" without GENERATOR_HOST, and this is provided only as
# a workaround if all else fails.
ENV GENERATOR_HOST=""

EXPOSE 8080

Expand Down
9 changes: 6 additions & 3 deletions modules/openapi-generator-online/README.md
Expand Up @@ -46,9 +46,12 @@ docker build -t openapitools/openapi-generator-online:latest .
Now, run the docker image:

```
docker run -d -p 8888:8080 \
-e GENERATOR_HOST=http://localhost:8888 \
openapitools/openapi-generator-online
docker run -d -p 8888:8080 openapitools/openapi-generator-online
```

The `GENERATOR_HOST` variable is used here to ensure download links generated by the API refer to the proper API location.

## Environment

`GENERATOR_HOST` can be set to force the scheme/host/port used for download link generation. In most cases, this environment variable is not
necessary to be set and the download link will be generated to match the originating request. The variable is provided simply as a fallback.

0 comments on commit 51e7005

Please sign in to comment.