microsoft / dev-proxy

Dev Proxy is an API simulator that helps you effortlessly test your app beyond the happy path.
https://aka.ms/devproxy
MIT License
508 stars 59 forks source link

Publish as a Docker container #12

Open waldekmastykarz opened 2 years ago

waldekmastykarz commented 2 years ago

To further simplify acquisition, we’ll publish the proxy as a Docker container so that customers can pull it from Docker hub without having to run custom executables on their host. This allows them to isolate the runtime but also have a shared instance of the proxy running for the whole dev team.

LucDrenth commented 6 months ago

Any updates on this?

waldekmastykarz commented 6 months ago

Not at the moment. Would you prefer to use Dev Proxy inside a Docker container rather than having it on the host?

LucDrenth commented 6 months ago

Yes that would be ideal for our setup. I tried running it from a docker container myself but I can't get it to work yet. When running devproxy it starts a process but I'm not getting any output and the proxy is not working.

waldekmastykarz commented 6 months ago

Got it. Could you please share with us your Dockerfile and some more information about how you've been trying to use Dev Proxy (OS setup, type of app, etc.)?

LucDrenth commented 6 months ago

I'm trying to mock responses from the Microsoft Graph API.

Dockerfile

FROM amd64/ubuntu:focal

WORKDIR /src

RUN apt -y update 
RUN apt -y upgrade 
RUN apt install -y \
    curl \
    unzip

COPY install.sh ./
RUN chmod +x ./install.sh

ENTRYPOINT [ "./install.sh" ]

install.sh


#!/bin/bash

/bin/bash -c "$(curl -sL https://aka.ms/devproxy/setup.sh)"
source ~/.bashrc

# Prevents error "Couldn't find a valid ICU package" when running devproxy
export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1

# TODO: Binary is not available in path for some reason so we need to specify use the binary location
./devproxy/devproxy
waldekmastykarz commented 6 months ago

Thanks! Is Dev Proxy running (I can see you're launching it at the end but want to double check it's working)? Is the app calling Microsoft Graph in the same Docker container as Dev Proxy or another (or on your host)?

LucDrenth commented 6 months ago

dev proxy is running, as in I can cntrl+c my way out of it. But it does not give any output so it seems like its stuck at startup. If I run the example curl command to call the proxy from inside the container I get a ‘connection refused’ error.

Eventually I’ll want to call the app from outside of the container, in which case I’ll need to expose the port or setup a network. But for now I’d like to just get a basic working version inside a docker container.

Thanks for the quick responses btw!

waldekmastykarz commented 6 months ago

Cool, thanks for all the information. Let me see if I can replicate this and I'll get back to you

waldekmastykarz commented 6 months ago

It's working for me just fine. Here's what I've done:

The default Dev Proxy config file is setup to intercept requests to https://jsonplaceholder.typicode.com/*. If you want to intercept calls to Microsoft Graph, you can use the Microsoft 365 specific preset, like devproxy --config-file ~appFolder/presets/m365.json

Hope this helps!

LucDrenth commented 6 months ago

This is not working on my machine (macbook M2). I'm trying exactly what you've done, with the only difference being that I add --platform linux/amd64 at the end of the docker run command. I'm guessing its an issue with me being on a macbook.

I'm curious what the last output of your container is. Mine looks like

Dev Proxy v0.16.1 installed!

To get started, run:
    source ~/.bashrc
    devproxy -h
waldekmastykarz commented 6 months ago

Is your install.sh file ending with ./devproxy/devproxy as you shared above?

For me, the output ends with Dev Proxy running (information about the IP address and the port it's using).

waldekmastykarz commented 6 months ago

I've got an M2 MBAir so can try it there too

LucDrenth commented 6 months ago

Yes my install script ends with running devproxy. I’m also not getting any output when running devproxy after manually logging in to the container. The curl to the proxy is not working.

waldekmastykarz commented 6 months ago

Let me see if I can repro that on my M2

waldekmastykarz commented 6 months ago

I can repro your issue on my M2: basically Dev Proxy is stuck starting when ran in Docker on an M2. Let's take it up as a separate issue that we'll investigate. Thanks for bringing it up

waldekmastykarz commented 6 months ago

Hey @LucDrenth, I found a solution. Check out #639 for more info.

Also, I updated the base image to arm64v8/ubuntu:focal to avoid the warning about incompatible architecture.