Skip to content

Commit

Permalink
Enable dind
Browse files Browse the repository at this point in the history
  • Loading branch information
goarsna committed Jul 27, 2023
1 parent 42a6459 commit 4510907
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------------------------------------------------------

Expand Down
35 changes: 23 additions & 12 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,31 @@ 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
$container_exec run \
$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/
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4510907

Please sign in to comment.