Using Dev Proxy in your GitHub Actions workflow on an Ubuntu hosted VM
In my previous blog post, I explained how you could use the Microsoft’s Dev Proxy in a GitHub Actions workflow on a macOS runner. In this blog post, I will show you how to use the Dev Proxy in your GitHub Actions workflow on an Ubuntu runner.
Most of the steps are the same, except how you trust the root certificate.
Installing and running the Dev Proxy
Like the macOS runner, you can install the bash script provided in the Dev Proxy documentation on the Ubuntu runner. To include this into your GitHub Actions workflow, you can use the following step:
Install and run the Dev Proxy - GitHub Actions steps
1
2
3
4
5
- name:Install Dev Proxyrun:bash -c "$(curl -sL https://aka.ms/devproxy/setup.sh)"- name:Run Dev Proxyrun:./devproxy/devproxy &
Once the Dev Proxy is installed, you can run it, but you cannot yet intercept HTTPS traffic. That is where the next step comes in. You need to trust the root certificate.
Trust the root certificate
Similar to the macOS configuration, we must trust the self-signed certificate the Dev Proxy created. Here are the steps to achieve the certificate trust on an Ubuntu runner:
Run Dev Proxy - GitHub Actions step
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- name:Install the Dev Proxy's certificatetimeout-minutes:1run:| echo "Export the Dev Proxy's Root Certificate"
openssl pkcs12 -in ~/.config/dev-proxy/rootCert.pfx -clcerts -nokeys -out dev-proxy-ca.crt -passin pass:""
echo "Installing the Dev Proxy's Root Certificate"
sudo cp dev-proxy-ca.crt /usr/local/share/ca-certificates/
echo "Updating the CA certificates"
sudo update-ca-certificates
echo "Certificate trusted."
# Set the system proxy settings (optional)
echo "http_proxy=http://127.0.0.1:8000" >> $GITHUB_ENV
echo "https_proxy=http://127.0.0.1:8000" >> $GITHUB_ENV
info
The commands used in the above GitHub Actions step are very similar to how it is configured on a Docker container. You can find the official documentation for the Docker container in Configure Dev Proxy certificate in your Docker container documentation section.
After running this step, you can start intercepting HTTPS traffic with the Dev Proxy.
The complete GitHub Actions workflow
Below, you can find the complete GitHub Actions workflow file, which includes the installation of the Dev Proxy and the trust of the root certificate.
name:Ubuntu Dev Proxyon:push:branches:- main- devworkflow_dispatch:jobs:test:timeout-minutes:60runs-on:ubuntu-lateststeps:- uses:actions/checkout@v4- uses:actions/setup-node@v4- name:Install Dev Proxyrun:bash -c "$(curl -sL https://aka.ms/devproxy/setup.sh)"- name:Run Dev Proxyrun:./devproxy/devproxy &- name:Install the Dev Proxy's certificatetimeout-minutes:1run:| echo "Export the Dev Proxy's Root Certificate"
openssl pkcs12 -in ~/.config/dev-proxy/rootCert.pfx -clcerts -nokeys -out dev-proxy-ca.crt -passin pass:""
echo "Installing the Dev Proxy's Root Certificate"
sudo cp dev-proxy-ca.crt /usr/local/share/ca-certificates/
echo "Updating the CA certificates"
sudo update-ca-certificates
echo "Certificate trusted."
# Set the system proxy settings (optional)
echo "http_proxy=http://127.0.0.1:8000" >> $GITHUB_ENV
echo "https_proxy=http://127.0.0.1:8000" >> $GITHUB_ENV# Include the additional steps you want to run after the Dev Proxy started- name:Test the Dev Proxyrun:| curl -ix http://127.0.0.1:8000 https://jsonplaceholder.typicode.com/posts
# When you used the system proxy settings, you don't need to specify the proxy in the curl command
curl -i https://jsonplaceholder.typicode.com/posts
With this setup, you can use the Dev Proxy in your GitHub Actions workflow on a Ubuntu runner.