screwdriver-cd / screwdriver

An open source build platform designed for continuous delivery.
http://screwdriver.cd
Other
1.02k stars 169 forks source link

API 404s #2832

Open agardnerIT opened 1 year ago

agardnerIT commented 1 year ago

What happened: Trying to follow the sd-in-a-box example. The only modification I made was pointing the docker-compose.yaml environment variables to a public URL rather than 172...

CONTAINER ID   IMAGE                              COMMAND                  CREATED          STATUS         PORTS                                             NAMES
07e7878b7174   screwdrivercd/ui:stable            "/usr/local/openrest…"   7 minutes ago    Up 7 minutes   0.0.0.0:9000->80/tcp, :::9000->80/tcp             root_ui_1
caa85bff4a25   screwdrivercd/store:stable         "docker-entrypoint.s…"   7 minutes ago    Up 7 minutes   0.0.0.0:9002->80/tcp, :::9002->80/tcp             root_store_1
be30e2b0273a   screwdrivercd/screwdriver:stable   "docker-entrypoint.s…"   12 minutes ago   Up 7 minutes   8080/tcp, 0.0.0.0:9001->80/tcp, :::9001->80/tcp   root_api_1

When I do CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 07e7878b7174 screwdrivercd/ui:stable "/usr/local/openrest…" 7 minutes ago Up 7 minutes 0.0.0.0:9000->80/tcp, :::9000->80/tcp root_ui_1 caa85bff4a25 screwdrivercd/store:stable "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 0.0.0.0:9002->80/tcp, :::9002->80/tcp root_store_1 be30e2b0273a screwdrivercd/screwdriver:stable "docker-entrypoint.s…" 12 minutes ago Up 7 minutes 8080/tcp, 0.0.0.0:9001->80/tcp, :::9001->80/tcp root_api_1

The UI is available on 9000 but the API isn't.

Even when I do curl http://localhost:9000/v4/auth/login/web or curl http://localhost:9000/v4/contexts I get a 404

Strangely the logs show it works.

api_1    | {"level":"info","message":"Server running at https://475ca132-e2d6-47e8-bf77-5cff35e0f14b-10-244-3-57-9001.papa.r.killercoda.com","timestamp":"2023-02-10T02:30:42.075Z"}
api_1    | 230210/023043.823, (1675996243823:be30e2b0273a:18:ldxww08b:10000) [response,api,auth,context] https://475ca132-e2d6-47e8-bf77-5cff35e0f14b-10-244-3-57-9001.papa.r.killercoda.com: get /v4/auth/contexts {} 200 (8ms)

But https://475ca132-e2d6-47e8-bf77-5cff35e0f14b-10-244-3-57-9001.papa.r.killercoda.com/v4/auth/contexts gives: {"statusCode":404,"error":"Not Found","message":"Not Found"}

What you expected to happen:

How to reproduce it:

Start the docker-compose version and the API endpoints aren't available.

jithine commented 1 year ago

your logs suggest API should be running on 9001 instead of 9000

agardnerIT commented 1 year ago

image

????

jithine commented 1 year ago

I think before making UI -> API work, need to make sure API is running as expected. v4/auth/contexts should work. It doesn't seem to be the case here. Does your API application logs show any errors ? If not, then I would check if routing setup properly ? Perhaps the requests are not reaching your API pod at all.

agardnerIT commented 1 year ago

Going to https://...:9001/v4/auth/contexts gives: [{"context":"github:github.com","displayName":"github","autoDeployKeyGeneration":false}]

$ docker logs screwdriver_api_1 --follow

> screwdriver-api@4.1.297 start /usr/src/app/node_modules/screwdriver-api
> ./bin/server

(sequelize) Warning: SQLite does not support 'INTEGER' with UNSIGNED or ZEROFILL. Plain 'INTEGER' will be used instead. 
>> Check: https://www.sqlite.org/datatype3.html
Coverage plugin undefined is not supported
{"level":"info","message":"Datastore ddl sync enabled: true","timestamp":"2023-02-23T23:11:24.158Z"}
(sequelize) Warning: SQLite does not support TEXT with options. Plain `TEXT` will be used instead. 
>> Check: https://www.sqlite.org/datatype3.html
{"level":"info","message":"Server running at https://fe09b482-685c-41cf-a3e2-6c7a3315293c-10-244-5-138-9001.papa.r.killercoda.com","timestamp":"2023-02-23T23:11:25.499Z"}
230223/231326.340, (1677194006340:0cb0416d9400:25:lehpxnsa:10000) [response] https://fe09b482-685c-41cf-a3e2-6c7a3315293c-10-244-5-138-9001.papa.r.killercoda.com: get / {} 404 (19ms)
230223/231343.250, (1677194023250:0cb0416d9400:25:lehpxnsa:10001) [response,api,auth,context] https://fe09b482-685c-41cf-a3e2-6c7a3315293c-10-244-5-138-9001.papa.r.killercoda.com: get /v4/auth/contexts {} 200 (13ms)
230223/231343.820, (1677194023820:0cb0416d9400:25:lehpxnsa:10002) [response] https://fe09b482-685c-41cf-a3e2-6c7a3315293c-10-244-5-138-9001.papa.r.killercoda.com: options /v4/banners {} 204 (5ms)
230223/231427.463, (1677194067463:0cb0416d9400:25:lehpxnsa:10003) [response] https://fe09b482-685c-41cf-a3e2-6c7a3315293c-10-244-5-138-9001.papa.r.killercoda.com: get /login {} 404 (1ms)
230223/231438.354, (1677194078354:0cb0416d9400:25:lehpxnsa:10004) [response,api,auth,context] https://fe09b482-685c-41cf-a3e2-6c7a3315293c-10-244-5-138-9001.papa.r.killercoda.com: get /v4/auth/contexts {} 200 (2ms)
230223/231501.676, (1677194101676:0cb0416d9400:25:lehpxnsa:10005) [response,api,auth,context] https://fe09b482-685c-41cf-a3e2-6c7a3315293c-10-244-5-138-9001.papa.r.killercoda.com: get /v4/auth/contexts {} 200 (5ms)

Edit: When I click the "login with SCM" button on the web, I see the 404 in browser AND I see the 404 in the API log container:

$ docker logs screwdriver_api_1 --follow
...
230223/231751.536, (1677194271536:0cb0416d9400:25:lehpxnsa:10009) [response] https://fe09b482-685c-41cf-a3e2-6c7a3315293c-10-244-5-138-9001.papa.r.killercoda.com: get /v4/auth/login/web {} 404 (2ms)

curling localhost from API pod

docker exec -it screwdriver_api_1 curl http://localhost:80/v4/auth/contexts
[{"context":"github:github.com","displayName":"github","autoDeployKeyGeneration":false}]

docker exec -it screwdriver_api_1 curl http://localhost:9000/v4/auth/contexts
curl: (7) Failed to connect to localhost port 9000: Connection refused

docker exec -it screwdriver_api_1 curl http://localhost:9001/v4/auth/contexts
curl: (7) Failed to connect to localhost port 9000: Connection refused
jithine commented 1 year ago

So API is working at port 80 in local host. I think since you are seeing login with SCM message, that means, UI -> API connection or rather browser to API connection is not working

what is browser developer tools showing for the API request ? Any CORS error?

From your browser is 9001 port request working ?

jithine commented 1 year ago

outside of the docker pod from your localhost, if you access API via 9001 port does it work ? ie http://localhost:9001/v4/auth/contexts if above request is working, then CORS would be the next thing to check.

agardnerIT commented 1 year ago

You're right. It's CORS.

The whole reason I'm working on this is to contribute an in-browser version of screwdriver back to the project. Here's the demo setup I'm working on.

I'll reach out to the Killercoda folk and see if it is their layer causing this and if so, if there is any way to fix.

Meanwhile I'll keep digging into the screwdriver code to see if there's anything in there I could adjust. If you happen to know, let me know :)

[Error] Access-Control-Allow-Origin cannot contain more than one origin.
[Error] XMLHttpRequest cannot load https://94e41a30-c40a-4757-99fa-eca0009642bd-10-244-5-209-9001.papa.r.killercoda.com/v4/auth/contexts due to access control checks.
[Error] Failed to load resource: Access-Control-Allow-Origin cannot contain more than one origin. (contexts, line 0)
[Error] Access-Control-Allow-Origin cannot contain more than one origin.
[Error] XMLHttpRequest cannot load https://94e41a30-c40a-4757-99fa-eca0009642bd-10-244-5-209-9001.papa.r.killercoda.com/v4/banners due to access control checks.
[Error] Failed to load resource: Access-Control-Allow-Origin cannot contain more than one origin. (banners, line 0)
jithine commented 1 year ago

Is that browser logs ?

Looks like the public API server location is 94e41a30-c40a-4757-99fa-eca0009642bd-10-244-5-209-9001.papa.r.killercoda.com is that static ?

API has a setting for allowing extra cors domains - https://github.com/screwdriver-cd/screwdriver/blob/30ee897ee8f1af239e6ca2b27c216bc2794772ef/config/default.yaml#L323 exposed via env variable https://github.com/screwdriver-cd/screwdriver/blob/30ee897ee8f1af239e6ca2b27c216bc2794772ef/config/custom-environment-variables.yaml#L422

agardnerIT commented 1 year ago

Yes, those are the browser logs. The URI is unique each time you re-run the killercoda tutorial but there's a way to grab that and I'm using sed to replace within the docker-compose.yml file.

I'm not sure which section that env var goes into (api, ui, and / or store) but I've added in all 3:

services:
  api:
    environment:
      ECOSYSTEM_ALLOW_CORS: [the-unique-url-9001.papa.r.killercoda.com]
  ...
  ui:
    environment:
      ECOSYSTEM_ALLOW_CORS: [the-unique-url-9001.papa.r.killercoda.com]
  store:
    environment:
      ECOSYSTEM_ALLOW_CORS: [the-unique-url-9001.papa.r.killercoda.com]

and I'm now getting 502 errors in the browser. Have I mentioned that I hate debugging CORS? :)

jithine commented 1 year ago

I believe that should go to API config. 502 usually means the server is crashing. Likely the config is messed up. Values should be strings.

adong commented 1 year ago

@agardnerIT

Please join us at slack at https://screwdriver-cd.slack.com, or use the invite https://slack.screwdriver.cd.

I wanted to create some video tutorials, just haven't got the time to do it.