Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gitpod cloud development evironment #2439

Merged
merged 2 commits into from
Nov 3, 2021
Merged

Conversation

DukeManh
Copy link
Contributor

@DukeManh DukeManh commented Nov 2, 2021

Issue This PR Addresses

Fixes #2427.

I think Gitpod is now fully working as intended.

The cool thing is we don't need gitpod.env anymore. Gitpod now uses env.development as a base and updates the URLs every time a workspace starts.

@gitpod-io
Copy link

gitpod-io bot commented Nov 2, 2021

@DukeManh
Copy link
Contributor Author

DukeManh commented Nov 2, 2021

Hmm, it looks like the frontend is fetching from old workspace urls.
I did try to rebuild nginx when a workspace is restarted but that didn't seem to help.

.gitpod.yml Outdated
npm run start
docker-compose --env-file .env up -d --no-dep nginx
docker-compose --env-file .env up -d
gp await-port 9200 && npm run start
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here that we're waiting on Elasticsearch, so it's clear why you're doing this. Having said that, I'm not clear if we need this. @manekenpix has code in our Elasticsearch client that retries connections.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On some occasions, the npm run start script will cancel itself before Elasticsearch has a chance to start and be connected to. I don't know if the retries are based on a certain number of attempts or after a certain amount of time. For some reason, we usually need to wait longer for Elasticsearch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably file an issue to bump the number of retries we do, see

/**
* Checks elasticsearch's connectivity
*/
const checkConnection = () => client.cluster.health();
const waitOnReady = async () => {
/**
* Elasticsearch needs time after deployment for setting up all its components.
* Here we set a timer using 'setTimeout' and check for connectivity during the countdown so elasticsearch
* has time to be fully prepared to start indexing posts.
*/
const DELAY = process.env.ELASTIC_DELAY_MS || 10000;
let intervalId;
let timerId;
const timer = new Promise((resolve, reject) => {
timerId = setTimeout(() => {
reject(
new Error(
'Unable to connect to Elasticsearch. Use `MOCK_ELASTIC=1` in your `.env` to mock Elasticsearch, or install (see https://github.com/Seneca-CDOT/telescope/blob/master/docs/environment-setup.md)'
)
);
}, DELAY);
});
const connectivity = new Promise((resolve) => {
intervalId = setIntervalAsync(async () => {
try {
await checkConnection();
resolve();
} catch (error) {
logger.info('Attempting to connect to elasticsearch...');
}
}, 500);
});
await Promise.race([timer, connectivity]);
await clearIntervalAsync(intervalId);
clearTimeout(timerId);
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The back-end uses this to determine for how long it should try to connect to ES (it's time, not number of attempts). If it can't connect, the back-end exits, BUT in production/staging we run the back-end in a container with unless-stopped, so it tries again after shutting down.

.gitpod.yml Outdated
command: |
docker-compose --env-file config/env.gitpod up -d
npm run start
docker-compose --env-file .env up -d --no-dep nginx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why you're running docker-compose multiple times here?

What if we use npm run dev instead of building the nginx-based frontend?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we really need to do is rework our microservices so that we're building and putting in a container registry from CI vs. always building them from scratch. cc @raygervais for any ideas on how to approach this in a follow-up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #2264

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we use npm run dev instead of building the nginx-based frontend?

That's a very good idea. I didn't think of that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we really need to do is rework our microservices so that we're building and putting in a container registry from CI.

Current build time is somewhere around 20 minutes, which is unbearable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20 min!? Yeah, we need to pull cached builds vs. creating our own.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@humphd, is there any way I can start all services except the frontend? Or I'd have to list all services by hand.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware of a way to do this without saying what you want. What you did is how I'd do it.

eval $(gp env -e WEB_URL=$(gp url 8000))
eval $(gp env -e API_HOST=$(gp url 8443))

sed -r \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever!

@cindyorangis
Copy link
Contributor

I'm testing it out on my machine too but I've been hitting this CORS error all day. Even in the AWS issues #2398 #2390 that are kinda similar to this PR here. No idea if it's on my end or what.

2021-11-02 13_31_14-

In your sed replacement command, there's one line that remained 'localhost'

ALLOWED_APP_ORIGINS=https://8000-lavender-lemur-niijfpmt.ws-us17.gitpod.io http://localhost:8888

@DukeManh
Copy link
Contributor Author

DukeManh commented Nov 2, 2021

@cindyledev, notice the urls different, they are ...lavender.. gitpod.io vs ..apricot..gitpod.io. So I think the problem is our Next is using the previous URLs passed to it, not the latest ones because workspace URLs are not stable.

In your sed replacement command, there's one line that remained 'localhost'

I wonder if this would affect anything? I'm currently replacing localhost:3000/8000/8443 only.

@cindyorangis
Copy link
Contributor

@cindyledev, notice the urls different, they are ...lavender.. gitpod.io vs ..apricot..gitpod.io. So I think the problem is our Next is using the previous URLs passed to it, not the latest ones because workspace URLs are not stable.

In your sed replacement command, there's one line that remained 'localhost'

I wonder if this would affect anything? I'm currently replacing localhost:3000/8000/8443 only.

I'm able to hit

https://3000-lavender-lemur-niijfpmt.ws-us17.gitpod.io

and

https://8443-lavender-lemur-niijfpmt.ws-us17.gitpod.io/v1/posts

but for some reason, the Next.js frontend is not fetching any data. I wonder where it's trying to get data from...

@humphd
Copy link
Contributor

humphd commented Nov 2, 2021

It should be hitting https://8443-lavender-lemur-niijfpmt.ws-us17.gitpod.io/v1/posts (works for me here).

curl -I https://8443-lavender-lemur-niijfpmt.ws-us17.gitpod.io/v1/posts

HTTP/2 200
access-control-allow-origin: *
content-security-policy: default-src 'self';base-uri 'self';block-all-mixed-content;font-src 'self' https: data:;frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests
content-type: application/json; charset=utf-8
date: Tue, 02 Nov 2021 17:56:32 GMT
etag: W/"c13-qHxwJ9fAjsNjhhlmoCXTbr0teJc"
expect-ct: max-age=0
link: </posts?per_page=30&page=2>; rel="next", </posts?per_page=30&page=147>; rel="prev", </posts?per_page=30&page=1>; rel="first", </posts?per_page=30&page=147>; rel="last"
referrer-policy: no-referrer
strict-transport-security: max-age=15552000; includeSubDomains
x-content-type-options: nosniff
x-dns-prefetch-control: off
x-download-options: noopen
x-permitted-cross-domain-policies: none
x-total-count: 4411
x-xss-protection: 0
content-length: 3091

This has the proper CORS header.

@cindyorangis
Copy link
Contributor

cindyorangis commented Nov 2, 2021

It should be hitting https://8443-lavender-lemur-niijfpmt.ws-us17.gitpod.io/v1/posts (works for me here).

curl -I https://8443-lavender-lemur-niijfpmt.ws-us17.gitpod.io/v1/posts

HTTP/2 200
access-control-allow-origin: *
content-security-policy: default-src 'self';base-uri 'self';block-all-mixed-content;font-src 'self' https: data:;frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests
content-type: application/json; charset=utf-8
date: Tue, 02 Nov 2021 17:56:32 GMT
etag: W/"c13-qHxwJ9fAjsNjhhlmoCXTbr0teJc"
expect-ct: max-age=0
link: </posts?per_page=30&page=2>; rel="next", </posts?per_page=30&page=147>; rel="prev", </posts?per_page=30&page=1>; rel="first", </posts?per_page=30&page=147>; rel="last"
referrer-policy: no-referrer
strict-transport-security: max-age=15552000; includeSubDomains
x-content-type-options: nosniff
x-dns-prefetch-control: off
x-download-options: noopen
x-permitted-cross-domain-policies: none
x-total-count: 4411
x-xss-protection: 0
content-length: 3091

This has the proper CORS header.

Silly question. Would Next.js need access-control-allow-origin: * as well?

@DukeManh
Copy link
Contributor Author

DukeManh commented Nov 2, 2021

My working server with npm run dev here, it's hitting the corrects urls.
https://8000-tan-cuckoo-unufc9u0.ws-us17.gitpod.io/

@cindyorangis
Copy link
Contributor

My working server with npm run dev here, it's hitting the corrects urls. https://8000-tan-cuckoo-unufc9u0.ws-us17.gitpod.io/

I see it!! Wow!

@DukeManh
Copy link
Contributor Author

DukeManh commented Nov 2, 2021

Oops, CI failing.

.gitpod.yml Show resolved Hide resolved
.gitpod.yml Outdated
eval $(gp env -e API_URL=$(gp url 3000))
eval $(gp env -e WEB_URL=$(gp url 8000))
eval $(gp env -e API_HOST=$(gp url 8443))
eval $(gp env -e SERVICES="status image auth search posts feed-discovery users parser planet redis elasticsearch login firebase")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to try and trim this down a bit we could remove planet. It's not needed in development (unless you're specifically working with it), which almost no one will be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trimmed planet.

@humphd
Copy link
Contributor

humphd commented Nov 3, 2021

Can you rebase to pick up the changes I had to make for the parser being disabled?

@DukeManh
Copy link
Contributor Author

DukeManh commented Nov 3, 2021

Let me do that again, I didn't disable the parser.

Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks right to me.

@humphd
Copy link
Contributor

humphd commented Nov 3, 2021

I got this working (my first time using GitPod, so cool)!:

Screen Shot 2021-11-02 at 11 03 10 PM

I ran into a few things:

  1. React warnings Fix React warning on page load #2443
  2. CORS issues on Satellite health checks [Satellite] Add CORS to health checks #2444
  3. Had to manually restart the backend due to elasticsearch not responding in time:
[ 2021-11-03 02:55:55.062 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Loading all feeds into feed queue for processing
[ 2021-11-03 02:55:55.070 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Telescope listening on port 3000
[ 2021-11-03 02:55:55.582 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:55:56.076 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:55:56.580 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:55:57.081 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:55:57.582 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:55:58.084 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:55:58.587 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:55:59.095 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:55:59.594 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:56:00.115 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:56:00.601 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:56:01.105 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:56:01.605 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:56:02.109 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:56:02.609 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:56:03.116 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:56:03.615 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:56:04.114 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:56:04.616 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Attempting to connect to elasticsearch...
[ 2021-11-03 02:56:05.070 ] ERROR (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Unable to connect to Elasticsearch. Use `MOCK_ELASTIC=1` in your `.env` to mock Elasticsearch, or install (see https://github.com/Seneca-CDOT/telescope/blob/master/docs/environment-setup.md)
    Error: Unable to connect to Elasticsearch. Use `MOCK_ELASTIC=1` in your `.env` to mock Elasticsearch, or install (see https://github.com/Seneca-CDOT/telescope/blob/master/docs/environment-setup.md)
        at Timeout._onTimeout (/workspace/telescope/src/backend/utils/indexer.js:145:9)
        at listOnTimeout (node:internal/timers:557:17)
        at processTimers (node:internal/timers:500:7)
[ 2021-11-03 02:56:05.071 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Received UNHANDLED REJECTION, starting shut down
[ 2021-11-03 02:56:05.071 ] ERROR (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01):
    error: {}
[ 2021-11-03 02:56:05.073 ] DEBUG (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Queue feed-queue paused.
[ 2021-11-03 02:56:05.073 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Feed queue shut down.
[ 2021-11-03 02:56:05.074 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Web server shut down.
[ 2021-11-03 02:56:05.074 ] INFO (7775 on ws-f40fc609-55dc-4058-ab0b-8ebddc633b01): Completing shut down.

It would be good to solve this, as most new devs won't have any idea how to solve this.

Also, it's slow to start. We need to improve. But it will work!

Copy link
Contributor

@cindyorangis cindyorangis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this is finally working on my end!!!

@humphd humphd merged commit 555f497 into Seneca-CDOT:master Nov 3, 2021
@DukeManh
Copy link
Contributor Author

DukeManh commented Nov 3, 2021

Merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pass Gitpod urls to the frontend
4 participants