iScsc / iscsc.fr

The iScsc website, build with passion by wannabe devs 🔥
GNU General Public License v3.0
4 stars 12 forks source link

Create a containerize environment for development workflow #86

Closed ctmbl closed 1 year ago

ctmbl commented 1 year ago

Close #64

This PR adds Dockerfiles and docker-compose file as well as a nginx conf template for development mode. The main differences with the prod mode are:

What solutions I chose

What still needs to be done/doesn't satisfy me

Appendices

(1)

iscscfr-node-app-dev-1   | MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://www.mongodb.com/docs/atlas/security-whitelist/
iscscfr-node-app-dev-1   |     at Connection.openUri (/backend/node_modules/mongoose/lib/connection.js:825:32)
iscscfr-node-app-dev-1   |     at /backend/node_modules/mongoose/lib/index.js:414:10
iscscfr-node-app-dev-1   |     at /backend/node_modules/mongoose/lib/helpers/promiseOrCallback.js:41:5
iscscfr-node-app-dev-1   |     at new Promise (<anonymous>)
iscscfr-node-app-dev-1   |     at promiseOrCallback (/backend/node_modules/mongoose/lib/helpers/promiseOrCallback.js:40:10)
iscscfr-node-app-dev-1   |     at Mongoose._promiseOrCallback (/backend/node_modules/mongoose/lib/index.js:1288:10)
iscscfr-node-app-dev-1   |     at Mongoose.connect (/backend/node_modules/mongoose/lib/index.js:413:20)
iscscfr-node-app-dev-1   |     at Object.<anonymous> (/backend/app.js:23:4)
iscscfr-node-app-dev-1   |     at Module._compile (node:internal/modules/cjs/loader:1254:14)
iscscfr-node-app-dev-1   |     at Module._extensions..js (node:internal/modules/cjs/loader:1308:10) {
iscscfr-node-app-dev-1   |   reason: TopologyDescription {
iscscfr-node-app-dev-1   |     type: 'ReplicaSetNoPrimary',
iscscfr-node-app-dev-1   |     servers: Map(3) {
iscscfr-node-app-dev-1   |       'ac-a2ywkbi-shard-00-01.a11re32.mongodb.net:27017' => [ServerDescription],
iscscfr-node-app-dev-1   |       'ac-a2ywkbi-shard-00-02.a11re32.mongodb.net:27017' => [ServerDescription],
iscscfr-node-app-dev-1   |       'ac-a2ywkbi-shard-00-00.a11re32.mongodb.net:27017' => [ServerDescription]
iscscfr-node-app-dev-1   |     },
iscscfr-node-app-dev-1   |     stale: false,
iscscfr-node-app-dev-1   |     compatible: true,
iscscfr-node-app-dev-1   |     heartbeatFrequencyMS: 10000,
iscscfr-node-app-dev-1   |     localThresholdMS: 15,
iscscfr-node-app-dev-1   |     setName: 'atlas-s2e0y3-shard-0',
iscscfr-node-app-dev-1   |     maxElectionId: null,
iscscfr-node-app-dev-1   |     maxSetVersion: null,
iscscfr-node-app-dev-1   |     commonWireVersion: 0,
iscscfr-node-app-dev-1   |     logicalSessionTimeoutMinutes: null
iscscfr-node-app-dev-1   |   },
iscscfr-node-app-dev-1   |   code: undefined
iscscfr-node-app-dev-1   | }

(2)

iscscfr-react-app-dev-1  | Proxy error: Could not proxy request /api/articles from localhost:3000 to http://localhost:3001.
iscscfr-react-app-dev-1  | See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).
ctmbl commented 1 year ago

I was getting with nginx container the following error:

iscscfr-nginx-1          | 2023/03/30 13:57:46 [emerg] 9#9: host not found in upstream "react-app" in /etc/nginx/nginx.conf:40

00d0912 have fixed it but still the backend doesn't reach mongo DB

ctmbl commented 1 year ago

This PR will stay idle for a while because we'll be working on two major changes that'll affect it:

ctmbl commented 1 year ago

This PR is not a draft anymore! @atxr @amtoine

gbrivady commented 1 year ago

Can you add in the readme how to launch the container for development mode? My guess is that it isnt much different from production mode, but as of now the readme still has the old instructions with node etc...

ctmbl commented 1 year ago

@gbrivady good point! tks for noticing it I completely forgot to update the readme, but as you guessed it's really simple just run docker-compose --env-file .env.development -f docker-compose-dev.yml up optionally you can add -d for detach mode (running in background) and --build for rebuilding the images (which will be done anyway if you're running it for the first time)

I'll uipdate the README.md really soon!

atxr commented 1 year ago

Let's wait for #95 here

gbrivady commented 1 year ago

@gbrivady good point! tks for noticing it I completely forgot to update the readme, but as you guessed it's really simple just run docker-compose --env-file .env.development -f docker-compose-dev.yml up optionally you can add -d for detach mode (running in background) and --build for rebuilding the images (which will be done anyway if you're running it for the first time)

I'll uipdate the README.md really soon!

Got a bunch of errors when I tried your command:

time="2023-05-04T19:08:13+02:00" level=warning msg="The \"REACT_LOCAL_PORT\" variable is not set. Defaulting to a blank string."
time="2023-05-04T19:08:13+02:00" level=warning msg="The \"REACT_LOCAL_PORT\" variable is not set. Defaulting to a blank string."
time="2023-05-04T19:08:13+02:00" level=warning msg="The \"SERVER_NAME\" variable is not set. Defaulting to a blank string."     
time="2023-05-04T19:08:13+02:00" level=warning msg="The \"MODE\" variable is not set. Defaulting to a blank string."
time="2023-05-04T19:08:13+02:00" level=warning msg="The \"DB_PORT\" variable is not set. Defaulting to a blank string."
time="2023-05-04T19:08:13+02:00" level=warning msg="The \"DB_PORT\" variable is not set. Defaulting to a blank string."
time="2023-05-04T19:08:13+02:00" level=warning msg="The \"DB_PORT\" variable is not set. Defaulting to a blank string."
1 error(s) decoding:

* error decoding 'Ports': No port specified: :<empty>

I think I might have issues with my .env file; maybe there is a way to fix it without resending me a complete dev one?

atxr commented 1 year ago

Yes indeed, looks like the port is missing in your env file Nevertheless, we should wait for #95 before working on this one because it might change some stuff. I think @ctmbl will share his .env to us once everything is ready

ctmbl commented 1 year ago

@amtoine @atxr @gbrivady

95 has been merged, so could we start reviewing this one? 🙂

ctmbl commented 1 year ago

I don't understand everything

No problem! the point isn't to be an epxert on everything but: 1- to learn some things 2- to ask the naive/right questions in order for me to question my choices and know what I did wrong or what's unclear!

but in frontend/package-lock.json half of the time you replace "dev" : true, with "devOptionnal" : true, And the rest of the time you just delete it : it is normal ?

Very good question in fact! I wondered too why this change occurred and lost almost 1hour figuring it out 🥲 After reading a bit of npm documentation this is simply because for the new dependency I added in 301f26c these subdependencies become Optional, so the mega changes to the package-lock.json Tks for bringing up the issue!

ctmbl commented 1 year ago

@Laudut

atxr commented 1 year ago

Will do this evening 🚒

ctmbl commented 1 year ago

@atxr tks!

atxr commented 1 year ago

Thanks to b0ab27d, everything is working on my side! Let's merge this :field_hockey:

gbrivady commented 1 year ago

Had to try twice to make it work, but with the help of @ctmbl to clean and re-install everything it is working, so I'm going to suppose it was an error on my side.

Anyway thanks for the scripts and the updated readme, much better and simpler that way to test everything!

Good to go for me then :rocket: