From 1ad470309b3a002bc201e61428192b02803158a5 Mon Sep 17 00:00:00 2001 From: dcbr <15089458+dcbr@users.noreply.github.com> Date: Sat, 13 Apr 2024 18:57:47 +0200 Subject: [PATCH] Add devcontainer configuration for codespace support (#138) --- .devcontainer/devcontainer.json | 42 ++++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 33 +++++++++++++++++++++++++ next.config.js | 6 +++++ 3 files changed, 81 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..c40ffcd --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,42 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node-postgres +{ + "name": "spliit", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": { + // "ghcr.io/frntn/devcontainers-features/prism:1": {} + // }, + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "cp container.env.example .env && npm install", + "postAttachCommand": { + "npm": "npm run dev" + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // This can be used to network with other containers or with the host. + "forwardPorts": [3000, 5432], + "portsAttributes": { + "3000": { + "label": "App" + }, + "5432": { + "label": "PostgreSQL" + } + }, + + // Configure tool-specific properties. + "customizations": { + "codespaces": { + "openFiles": [ + "README.md" + ] + } + } + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..b776ce8 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,33 @@ +version: '3.8' + +services: + app: + image: mcr.microsoft.com/devcontainers/typescript-node:latest + + volumes: + - ../..:/workspaces:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:db + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + db: + image: postgres:latest + restart: unless-stopped + volumes: + - postgres-data:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: 1234 + POSTGRES_USER: postgres + POSTGRES_DB: postgres + + # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + +volumes: + postgres-data: diff --git a/next.config.js b/next.config.js index 89faa5d..551a900 100644 --- a/next.config.js +++ b/next.config.js @@ -23,6 +23,12 @@ const nextConfig = { images: { remotePatterns }, + // Required to run in a codespace (see https://github.com/vercel/next.js/issues/58019) + experimental: { + serverActions: { + allowedOrigins: ['localhost:3000'], + }, +}, } module.exports = nextConfig