diff --git a/README.rst b/README.rst index 9eb51c6..8d47afd 100644 --- a/README.rst +++ b/README.rst @@ -66,6 +66,15 @@ If you want to use a locally present openapi schema, you can skip fetching the o by setting the ``USE_LOCAL_API_JSON`` environment variable. Doing so you have to manually provide the ``api.json`` file containing the openapi schema in the current working directory. +Generate Bindings Using Docker in Docker (dind) +----------------------------------------------- + +Bindings are generated using the openapi-generator-cli docker container. If your environment itself runs in +a docker container, the openapi-generator-cli container has to be started as a sibling container. For +sibling containers, volumes cannot be mounted as usual. They have to be passed through from the parent +container. For this to work you have to set the ``PARENT_CONRAINER_ID`` environment variable to specify the +parent container in a dind environment. + Generating Bindings on a Filesystem Shared With Another Container ----------------------------------------------------------------- diff --git a/generate.sh b/generate.sh index 2fbe110..660c4f3 100755 --- a/generate.sh +++ b/generate.sh @@ -69,6 +69,17 @@ else export VERSION=$(http ${PULP_URL}status/ | jq --arg plugin $COMPONENT_NAME -r '.versions[] | select(.component == $plugin) | .version') fi +# Mount volumes from parent container with `--volumes-from` option if the +# `PARENT_CONTAINER_ID` is set. +if [ -z $PARENT_CONTAINER_ID ] +then + VOLUME_OPTION="--volume ${PWD}:${volume_name}" + VOLUME_DIR="/local" +else + VOLUME_OPTION="--volumes-from ${PARENT_CONTAINER_ID}:rw" + VOLUME_DIR="${PWD}" +fi + echo ::group::BINDINGS if [ $2 = 'python' ] then @@ -76,13 +87,13 @@ then $ULIMIT_COMMAND \ $USER_COMMAND \ --rm \ - -v ${PWD}:$volume_name \ + ${VOLUME_OPTION} \ docker.io/openapitools/openapi-generator-cli:v4.3.1 generate \ - -i /local/api.json \ + -i ${VOLUME_DIR}/api.json \ -g python \ - -o /local/$1-client \ + -o ${VOLUME_DIR}/$1-client \ --additional-properties=packageName=pulpcore.client.$1,projectName=$1-client,packageVersion=${VERSION},domainEnabled=${DOMAIN_ENABLED} \ - -t /local/templates/python \ + -t ${VOLUME_DIR}/templates/python \ --skip-validate-spec \ --strict-spec=false cp python/__init__.py $1-client/pulpcore/ @@ -98,14 +109,14 @@ then $container_exec run \ $ULIMIT_COMMAND \ $USER_COMMAND \ - --rm -v ${PWD}:$volume_name \ + --rm ${VOLUME_OPTION} \ docker.io/openapitools/openapi-generator-cli:v4.3.1 generate \ - -i /local/api.json \ + -i ${VOLUME_DIR}/api.json \ -g ruby \ - -o /local/$1-client \ + -o ${VOLUME_DIR}/$1-client \ --additional-properties=gemName=$1_client,gemLicense="GPLv2+",gemVersion=${VERSION},gemHomepage=https://github.com/pulp/$1 \ --library=faraday \ - -t /local/templates/ruby \ + -t ${VOLUME_DIR}/templates/ruby \ --skip-validate-spec \ --strict-spec=false fi @@ -114,12 +125,12 @@ then $container_exec run \ $ULIMIT_COMMAND \ $USER_COMMAND \ - --rm -v ${PWD}:$volume_name \ + --rm ${VOLUME_OPTION} \ docker.io/openapitools/openapi-generator-cli:v5.2.1 generate \ - -i /local/api.json \ + -i ${VOLUME_DIR}/api.json \ -g typescript-axios \ - -o /local/$1-client \ - -t /local/templates/typescript-axios \ + -o ${VOLUME_DIR}/$1-client \ + -t ${VOLUME_DIR}/templates/typescript-axios \ --skip-validate-spec \ --strict-spec=false fi