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

Configuration to work with GitHub Codespaces #3493

Open
wants to merge 1 commit into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"name": "LiteFarm Codespace",
"image": "mcr.microsoft.com/devcontainers/base:bookworm",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "18.16.1",
"installYarnUsingApt": false
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},
"customizations": {
"vscode": {
"settings": {
"cSpell.language": "pl,en",
"cSpell.words": ["LiteFarm"],
"cSpell.overrides": [
{
"filename": "packages/api/src/jobs/locales/en/*.*",
"language": "en"
},
{
"filename": "packages/api/src/jobs/locales/pl/*.*",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This probably comes from your organization's specific setup, but we don't currently support pl locale -- could we remove references to this? Actually, I'm thinking it might be better to remove the extensions from this file altogether, since we don't currently have a unified criteria on extensions to use as a team and it's up to each developer to use the tools they deem necessary

Copy link
Author

Choose a reason for hiding this comment

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

Yes and no. We were working on polish translation to LiteFarm and it is almost done: https://github.com/Lukasiewicz-Instytut-Lotnictwa/LiteFarm/tree/feature/GL-4-polish-translation.
Expect a pull request soon. But of course this is not important. It just helps to find spelling errors in translation files when working with Visual Studio Code.

"language": "pl"
},
{
"filename": "packages/api/src/templates/locales/en.json",
"language": "en"
},
{
"filename": "packages/api/src/templates/locales/pl.json",
"language": "pl"
},
{
"filename": "packages/webapp/public/locales/en/*.*",
"language": "en"
},
{
"filename": "packages/webapp/public/locales/pl/*.*",
"language": "pl"
}
],
"cSpell.ignorePaths": [
"package-lock.json",
"node_modules",
"**/node_modules",
"vscode-extension",
".git/objects",
".vscode",
".vscode-insiders",
".gradle",
".svn",
"logs",
".cache"
],
"files.defaultLanguage": "en",
"vscode.php-language-features": false,
"vscode.php": false,
"vscode.swift": false,
"vscode.rust": false,
"vscode.ruby": false,
"vscode.r": false,
"vscode.pug": false,
"vscode.objective-c": false,
"vscode.make": false,
"vscode.lua": false,
"vscode.less": false,
"vscode.go": false,
"vscode.dart": false,
"vscode.fsharp": false,
"vscode.coffeescript": false,
"vscode.csharp": false,
"vscode.vb": false,
"vscode.latex": false,
"vscjava.vscode-maven": false
},
"extensions": [
"streetsidesoftware.code-spell-checker",
"streetsidesoftware.code-spell-checker-polish",
"streetsidesoftware.code-spell-checker-british-english",
"redhat.vscode-yaml",
"shd101wyy.markdown-preview-enhanced"
]
}
},
"forwardPorts": [3000, 5001, 5433, 9000, 8088],
"portsAttributes": {
"3000": {
"label": "Frontend (React)"
},
"5001": {
"label": "Backend (Express)"
},
"5433": {
"label": "Postgres"
},
"9000": {
"label": "MinIO"
},
"8088": {
"label": "Imaginary"
}
},
"postCreateCommand": "bash .devcontainer/post-create.sh",
"postStartCommand": "bash .devcontainer/post-start.sh"
}
37 changes: 37 additions & 0 deletions .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

DIR=`pwd`
echo "Current directory: $DIR"

nvm use

# Install the root package dependencies
npm install

# Install the API package dependencies
cd $DIR/packages/api
npm install

# Install the API package dependencies
cd $DIR/packages/webapp
pnpm install

# Install the shared package dependencies
cd $DIR/packages/shared
npm install

# Copy the default environment files
cp $DIR/packages/api/.env.default $DIR/packages/api/.env
cp $DIR/packages/webapp/.env.default $DIR/packages/webapp/.env

if [ -x "$(command -v docker-compose)" ]; then
docker-compose up --detach
else
docker compose up --detach
fi
Comment on lines +27 to +31
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please explain what this block should be doing? It seems it does the same in both cases of the condition

Copy link
Author

Choose a reason for hiding this comment

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

In my computer (Debian Bookworm) there is command docker-compose and when I try to run docker compose (without -) then I have an error:

$ docker compose
docker: 'compose' is not a docker command.

On the other hand in GitHub Codespaces there is command docker compose.

Command docker-compose is the old docker script command and as I know it is not maintained anymore but exists on some systems (like mine Debian).
Command docker compose is the new docker script and should be use.

In summary this is only for backward compatibility.

I use this script to start development on my local computer (it works not only in GitHub Codespaces).
Of course it can be removed in favour of the new version docker compose.

(I'm not sure why Debian Bookworm has such old version of Docker - 20.10 vs current 27.)


sleep 10

# Set up the PostgreSQL database used by the app
cd $DIR/packages/api
npm run migrate:dev:db
7 changes: 7 additions & 0 deletions .devcontainer/post-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

if [ -x "$(command -v docker-compose)" ]; then
docker-compose up --detach
else
docker compose up --detach
fi
Comment on lines +3 to +7
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this redundant since it's in the post-create script?

Copy link
Author

Choose a reason for hiding this comment

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

At first I had this only in post-start.sh because it is needed to start docker each time the machine starts, but I forgotten that I need to start once npm run migrate:dev:db. Without this script application isn't working correctly.

Script post-create.sh is executed only once, when the machine is created and it the right place to execute npm run migrate:dev:db, but to run this the database needs to be started and so docker compose up --detach is required.
Maybe it would be better to call sh ./post-start.sh instead of this if.

I'm not sure, if there should be another check if docker isn't running. Because on the first time post-create.sh is executed and then post-start.sh (two scripts, one after other). And then (everyother start of the machine) only post-start.sh. But at the first time (when machine is created) docker compose up is called two times. Not sure if this ends with error which of course can be ignored but is not nice. Let me check this...

Copy link
Author

Choose a reason for hiding this comment

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

Running multiple times docker compose up doesn't throws any errors it just displays that everything is running, then it is better to leave it this way, without checking it in the shell script.

In summary this block in post-create.sh script can be replaced with call to sh ./post-start.sh script, but I'm not sure what is the working directory, then it would be better to call it this way:

# Get script directory
DIR="$(cd "$(dirname "$0")" && pwd)"

# Start Docker before running: npm run migrate:dev:db
sh "$DIR/post-start.sh"

The DIR variable can be set at the start of post-create.sh script, because it could be used in fututre in other places (?).

100 changes: 100 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"devDependencies": {
"concurrently": "^9.0.1",
"husky": "^7.0.4",
"lerna": "^5.0.0",
"lint-staged": "^13.2.2",
Expand All @@ -14,7 +15,8 @@
"ngrok": "ngrok start --config=./ngrok/ngrok.yml --all",
"ngrok:setup": "node ./ngrok/ngrok-setup.js",
"ngrok:api": "ngrok start --config=./ngrok/ngrok.yml api",
"ngrok:webapp": "ngrok start --config=./ngrok/ngrok.yml webapp"
"ngrok:webapp": "ngrok start --config=./ngrok/ngrok.yml webapp",
"dev": "concurrently -n api,webapp \"cd packages/api && npm run nodemon\" \"cd packages/webapp && pnpm dev\""
},
"type": "module",
"jest": {
Expand Down