From 64940368688dd7bcb28838a88f2ea5e759cbdcbb Mon Sep 17 00:00:00 2001 From: BH Date: Fri, 30 Jan 2026 16:41:26 +0000 Subject: [PATCH] ci: set up devcontainer with docker-compose --- server/.devcontainer/devcontainer.json | 59 +++++++++++++++++++++++++ server/.devcontainer/docker-compose.yml | 25 +++++++++++ server/.docker/entrypoint.sh | 2 +- server/.dockerignore | 2 +- server/.gitignore | 3 ++ server/.vscode/settings.json | 8 ++++ server/Dockerfile | 23 ++-------- server/biome.json | 6 ++- server/docker-compose.dev.yaml | 25 +++++++++++ server/jest.config.ts | 1 + 10 files changed, 131 insertions(+), 23 deletions(-) create mode 100644 server/.devcontainer/devcontainer.json create mode 100644 server/.devcontainer/docker-compose.yml create mode 100644 server/docker-compose.dev.yaml diff --git a/server/.devcontainer/devcontainer.json b/server/.devcontainer/devcontainer.json new file mode 100644 index 0000000..3ced3c6 --- /dev/null +++ b/server/.devcontainer/devcontainer.json @@ -0,0 +1,59 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose +{ + "name": "Back-end Local Develpoment Enviroment", + + // Update the 'dockerComposeFile' list if you have more compose files or use different names. + // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make. + "dockerComposeFile": [ + "../docker-compose.dev.yaml", + "docker-compose.yml" + ], + + // The 'service' property is the name of the service for the container that VS Code should + // use. Update this value and .devcontainer/docker-compose.yml to the real service name. + "service": "api", + + // The optional 'workspaceFolder' property is the path VS Code should open by default when + // connected. This is typically a file mount in .devcontainer/docker-compose.yml + "workspaceFolder": "/home/node/app", + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + // "installZsh": true, + // "installOhMyZsh": true, + // "installZshConfig": true, + // "configZshAsDefailtShell": true + }, + "ghcr.io/stuartleeks/dev-container-features/shell-history:0": {}, + "ghcr.io/devcontainers-extra/features/zsh-plugins:0": { + "plugins": "git git-flow F-Sy-H zsh-autosuggestions zsh-completions zsh-syntax-highlighting", + "omzPlugins": "https://github.com/z-shell/F-Sy-H https://github.com/zsh-users/zsh-autosuggestions https://github.com/zsh-users/zsh-completions https://github.com/zsh-users/zsh-syntax-highlighting.git" + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment the next line if you want start specific services in your Docker Compose config. + // "runServices": [], + + // Uncomment the next line if you want to keep your containers running after VS Code shuts down. + // "shutdownAction": "none", + + // Uncomment the next line to run commands after the container is created. + + + // Configure tool-specific properties. + "customizations": { + "vscode": { + "extensions": [ + "biomejs.biome" + ] + } + } + + // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "devcontainer" +} diff --git a/server/.devcontainer/docker-compose.yml b/server/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..76a74f9 --- /dev/null +++ b/server/.devcontainer/docker-compose.yml @@ -0,0 +1,25 @@ +services: + # Update this to the name of the service you want to work with in your docker-compose.yml file + api: + # Uncomment if you want to override the service's Dockerfile to one in the .devcontainer + # folder. Note that the path of the Dockerfile and context is relative to the *primary* + # docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile" + # array). The sample below assumes your primary file is in the root of your project. + # + # build: + # context: . + # dockerfile: .devcontainer/Dockerfile + + volumes: + # Update this to wherever you want VS Code to mount the folder of your project + - ..:/workspaces:cached + + # Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust. + # cap_add: + # - SYS_PTRACE + # security_opt: + # - seccomp:unconfined + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + diff --git a/server/.docker/entrypoint.sh b/server/.docker/entrypoint.sh index 01ef405..d61421f 100755 --- a/server/.docker/entrypoint.sh +++ b/server/.docker/entrypoint.sh @@ -7,4 +7,4 @@ npm install npx prisma generate npx prisma migrate dev -npm run dev \ No newline at end of file +tail -f /dev/null \ No newline at end of file diff --git a/server/.dockerignore b/server/.dockerignore index 800ae08..a596da7 100644 --- a/server/.dockerignore +++ b/server/.dockerignore @@ -2,6 +2,6 @@ node_modules dist -.env + generated \ No newline at end of file diff --git a/server/.gitignore b/server/.gitignore index 84c03cc..5a3581f 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -1,6 +1,9 @@ /node_modules .env + + +.docker/postgres # package-lock.json generated \ No newline at end of file diff --git a/server/.vscode/settings.json b/server/.vscode/settings.json index 18bd38e..8936d41 100644 --- a/server/.vscode/settings.json +++ b/server/.vscode/settings.json @@ -36,5 +36,13 @@ "editor.codeActionsOnSave": { "source.organizeImports.biome": "always", "source.fixAll.biome": "always" + }, + "terminal.integrated.defaultProfile.linux": "zsh", + "terminal.integrated.profiles.linux":{ + "zsh": { + "path": "/usr/bin/zsh", + "icon": "terminal-linux" + } } + } diff --git a/server/Dockerfile b/server/Dockerfile index 59a73f9..83e58b0 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,26 +1,11 @@ -# FROM node:lts-alpine -# FROM node:18.1.0 -FROM node:18-alpine3.18 +FROM node:24.0.0-slim -RUN apk add --no-cache bash +USER node -WORKDIR /app +WORKDIR /home/node/app +CMD [ "tail", "-f", "/dev/null" ] -COPY package.json ./ - -COPY prisma ./prisma/ - - - -COPY tsconfig.json ./ - -COPY . . - - -# EXPOSE 5000 - -# CMD ["npm","run","dev"] \ No newline at end of file diff --git a/server/biome.json b/server/biome.json index 19c56ca..0e117f6 100644 --- a/server/biome.json +++ b/server/biome.json @@ -6,11 +6,13 @@ "useIgnoreFile": true }, "files": { - "ignoreUnknown": false + "ignoreUnknown": false, + "includes": ["Dockerfile"] }, "formatter": { "enabled": true, - "indentStyle": "tab" + "indentStyle": "tab", + "lineWidth": 100 }, "linter": { "enabled": true, diff --git a/server/docker-compose.dev.yaml b/server/docker-compose.dev.yaml new file mode 100644 index 0000000..c8da08b --- /dev/null +++ b/server/docker-compose.dev.yaml @@ -0,0 +1,25 @@ +services: + + api: + build: . + command: ./.docker/entrypoint.sh + container_name: nogain-dev-api + ports: + - '5000:5000' + volumes: + - .:/home/node/app + extra_hosts: + - "host.docker.internal:host-gateway" + + + db: + build: .docker/postgres + container_name: nogain-dev-db + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + volumes: + - ./.docker/postgres/data:/var/lib/postgresql/data + ports: + - "5432:5432" \ No newline at end of file diff --git a/server/jest.config.ts b/server/jest.config.ts index c3c1bd1..f0b658d 100644 --- a/server/jest.config.ts +++ b/server/jest.config.ts @@ -194,4 +194,5 @@ export default { // watchman: true, clearMocks: true, + logHeapUsage: true, };