Debugging Angular application in Azure Dev Spaces and VS Code

1/28/2019

I am trying to get the right "Recipe" to debug an Azure Dev Spaces. I am getting close but I keep running into various errors. I hope we can get to a solution so it can help others who are stuck with the same issue. So far this is what I have:

This is my Docker File:

FROM node
ENV PORT 80
WORKDIR /app
COPY package*.json ./
RUN npm install -g @angular/cli
RUN npm install
COPY . .

EXPOSE 80 49153
CMD ["npm", "start"]

This is the pre-launch task in tasks.json

 {
  "label": "azds: prelaunch-ng-serve",
  "command": "azds",
  "args": ["up", "--port=54783:80", "--keep-alive"],
  "options": {
    "cwd": "${workspaceFolder}"
  },
  "problemMatcher": []
}

This is the launch.json configuration:

 {
  "name": "Launch ng-serve (AZDS)",
  "type": "node",
  "request": "launch",
  "protocol": "legacy",
  "preLaunchTask": "azds: prelaunch-ng-serve",
  "cwd": "${workspaceFolder}",
  "address": "127.0.0.1",
  "port": 54783,
  "localRoot": "${workspaceFolder}/.",
  "remoteRoot": "/app"
},

If I test the above using Docker Compose it works perfectly. My issue is deploying and testing the app in Azure Dev Spaces.

When I initiate a debug session this is what I get:

Step 1/9 : FROM node
Step 2/9 : ENV PORT 80
Step 3/9 : WORKDIR /app
Step 4/9 : COPY package*.json ./
Step 5/9 : RUN npm install -g @angular/cli
Step 6/9 : RUN npm install
Step 7/9 : COPY . .
Step 8/9 : EXPOSE 4200 49153
Step 9/9 : CMD ["npm", "start"]
Built container image in 1m 29s
Waiting for container...10s
Service 'dpclient' port 'http' is available at http://xxxx.eastus.aksapp.io/
Service 'dpclient' port 80 (http) is available at http://localhost:54783
Port forward 54783:80 failed.

I confirm that the pod is running, but the web page returns:

This page isn’t working localhost sent an invalid response. ERR_INVALID_HTTP_RESPONSE

I also get an error from VS Code:

Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: socket hang up)

Frequently, I get a timeout when npm install executes:

Step 1/9 : FROM node
Step 2/9 : ENV PORT 80
Step 3/9 : WORKDIR /app
Step 4/9 : COPY package*.json ./
Step 5/9 : RUN npm install -g @angular/cli
Step 6/9 : RUN npm install
Waiting for container...

I think this is because it takes a bit for npm install to execute. I increased the timeout values in the Azure Portal kubernetes Frontend IP Configuration to 4 minutes. That didn't fix the issue.

I also tried adding a timeout value to launch.json:

{ "name": "Launch ng-serve (AZDS)", "type": "node", "request": "launch", "protocol": "legacy", "preLaunchTask": "azds: prelaunch-ng-serve", "cwd": "${workspaceFolder}", "address": "127.0.0.1", "port": 54783, "localRoot": "${workspaceFolder}/.", "remoteRoot": "/app", "timeout": 18000 }

Does anyone see any obvious errors above? Maybe if sommeone has this working they can provide a working "recipe"?

Thanks :-)

-- MrTouya
angular
azure-kubernetes
kubernetes

1 Answer

3/8/2019

I see at least one issue with your current Dev env setup. Your launch.json configuration settings does not seem to match DevSpace release values.

In your Dockerfile you are exposing following ports:

Step 8/9 : EXPOSE 4200 49153

whereas by default azds prep --global creates for you a Kubernetes deployment template file, which is telling other systems, that your container exposes port 80, so please check the following file and adjust it accordingly:

(./charts/---app_name---/templates/deployment.yaml):

   spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP

Because of it you can`t create a tunneled connection (["args": ["up", "--port=54783:80", "--keep-alive"]) to the Angular POD, backed by K8S service on port 80 and Ingress (service port can be adjusted in values.yaml file).

I did adjustments of ng server port in my Angluar project to make it working with Dev Space out-of-the-box, and to avoid messing up later on with output artifacts (helm chart) of azds prep command:

 -- package.json  --

{
  "name": "webfrontend",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --port 80",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

And here is the output of my docker build inside Dev Space:

Waiting for container image build...4s
Building container image...
Step 1/8 : FROM node:lts
Step 2/8 : ENV PORT 80
Step 3/8 : EXPOSE 80
Step 4/8 : WORKDIR /app
Step 5/8 : COPY package.json .
Step 6/8 : RUN npm install
Step 7/8 : COPY . .
Step 8/8 : CMD ["npm", "start"]
Built container image in 6s
Waiting for container...10s
Service 'webfrontend' port 'http' is available at http://angular-dev.webfrontend.xxxyyyzzz.yyy.azds.io/
Service 'webfrontend' port 80 'http' is available at http://localhost:53097
-- Nepomucen
Source: StackOverflow