stripe / vscode-stripe

Stripe for Visual Studio Code
MIT License
122 stars 30 forks source link

Stripe Extension not working inside a container running the stripe cli #493

Open miomech opened 2 years ago

miomech commented 2 years ago

ISSUE: The stripe vscode extension does not work (nothing happens when you click on any "event" buttons such as "Trigger new default event", "Create new customized event". "Start streaming events" hangs indefinitely.

The following issue is displayed within vscode devtools when clicking the buttons: [Extension Host] Error fetching CLI version TypeError: g is not a function at h.checkCLIVersion (/home/devuser/.vscode-server/extensions/stripe.vscode-stripe-2.0.10/src/stripeClient.ts:179:11) at processTicksAndRejections (internal/process/task_queues.js:93:5)

When pressing "Start streaming API logs" also hangs indefinitely. and shows the following in vscode devtools: [Extension Host] Error fetching CLI version TypeError: g is not a function at h.checkCLIVersion (/home/devuser/.vscode-server/extensions/stripe.vscode-stripe-2.0.10/src/stripeClient.ts:179:11) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:93:5)

TESTED: The extension is working perfectly fine within windows 11 and WSL (Debian). but fails within the container. here is my docker file

# Start with base image (python 3)
FROM python:3.10.1-buster

ARG USERNAME
ARG USER_UID
ARG USER_GID=$USER_UID
ARG STRIPE_CLI_VERSION

# ***** Install & cleanup all unused packages *******
# Switch to using bash instead of the sh shell
SHELL ["/bin/bash", "-c"]
# Update all packages in the container
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
    apt-get install apt-utils curl dialog openssh-client wget build-essential sudo bash-completion --no-install-recommends  -yq \
    # Cleanup any unused packages
    && apt-get upgrade -y \
    && apt-get autoremove -y

# ***** Register Github as an allowed key *******
# Prevent the "git clone" operation from failing with an "unknown host key" error.
RUN mkdir -m 700 /root/.ssh; \
    touch -m 600 /root/.ssh/known_hosts; \
    ssh-keyscan github.com > /root/.ssh/known_hosts

# ***** Create non root user and enable sudo *******
# Create the user and group and enable sudo
RUN groupadd --gid ${USER_GID} ${USERNAME} \
    && useradd --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME}\
    && echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \
    && chmod 0440 /etc/sudoers.d/${USERNAME}
# Create the application folder and set permissions
RUN mkdir /home/${USERNAME}/app \
    && chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}
# Switch to the user that was created
USER ${USERNAME}
# Add the current user's .local folder to the path so installed binaries and python packages can be found
ENV PATH /home/${USERNAME}/.local/bin:$PATH

# ***** Install NVM for nodejs & NPM requirements *******
WORKDIR /home/${USERNAME}
# Set NVM environment variables
ENV NVM_DIR /home/${USERNAME}/.nvm
ARG NODE_VERSION 16.13.1
# Install nvm
RUN mkdir ${NVM_DIR} \
    && curl --silent -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash \
    # Source the shell commands for NVM
    && . ${NVM_DIR}/nvm.sh \
    # Install node and npm
    && nvm install ${NODE_VERSION} \
    && nvm alias default ${NODE_VERSION} \
    && nvm use default
# Add node and npm to path so the commands are available
ENV NODE_PATH $NVM_DIR/v${NODE_VERSION}/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v${NODE_VERSION}/bin:$PATH

# ***** Install The stripe cli tool *******
# Set working directory to the global binariy location
WORKDIR /home/${USERNAME}/.local/bin
# Download the tar.gz package for stripe cli, uncompress and unpack it with tar and gz, then remove tar.gz
RUN wget https://github.com/stripe/stripe-cli/releases/download/v${STRIPE_CLI_VERSION}/stripe_${STRIPE_CLI_VERSION}_linux_x86_64.tar.gz \
    && tar -xvf stripe_${STRIPE_CLI_VERSION}_linux_x86_64.tar.gz \ 
    && rm stripe_${STRIPE_CLI_VERSION}_linux_x86_64.tar.gz \
    && chmod 775 stripe
# Enable stripe cli auto completions
RUN mkdir /home/${USERNAME}/.stripe
WORKDIR /home/${USERNAME}/.stripe
RUN stripe completion --shell bash
RUN echo ". /home/${USERNAME}/.stripe/stripe-completion.bash" >> /home/${USERNAME}/.bashrc \
    && stripe config set --color on

# ***** Install the default python django libraries from requirements.txt ******* 
WORKDIR /home/${USERNAME}/app
# Disable buffering to not cut off any error messages
ENV PYTHONUNBUFFERED 1
# Install a base collection of tools usefull for django development
COPY requirements.txt requirements.txt
RUN pip3 install --upgrade pip\
    && pip install -r requirements.txt\
    && rm requirements.txt

I have also been able to replicate this issue on another one of my computers but in WSL(Debian) only.

nawage commented 1 year ago

I am getting this exact same error trying to run the stripe cli vscode extension inside a docker container.

EDIT: I was able to resolve this error by changing the network of the docker container to "host".