From 92443bb6a5ff3ed66457149a509401986a82e570 Mon Sep 17 00:00:00 2001 From: ANKIT VARSHNEY <132201033+AVtheking@users.noreply.github.com> Date: Sun, 24 Nov 2024 03:30:43 +0530 Subject: [PATCH] Devcontainer (#2429) * added installation script * shell.nix file * nix script * nix flakes * made script cross-platform * test * test * test * test * test * test * test * test * fix nix flake * fix * fix * fix * fix * added dev container for devpods * fix * fix * fix * fix * fix * temp fix * temp fix * temp fix * temp fix * temp fix * shell.nix file * removed nix file * fix * docker file * fix * fix * fix * fix * made changes * Update INSTALLATION.md * Update INSTALLATION.md * made changes * Update INSTALLATION.md * fix docker file --- .devcontainer/Dockerfile | 24 +++++++++++ .devcontainer/devcontainer.json | 36 +++++++++++++++++ .devcontainer/docker-compose.yaml | 34 ++++++++++++++++ .husky/pre-commit | 2 - Dockerfile.dev | 2 +- INSTALLATION.md | 67 +++++++++++++++++++++++++++++++ 6 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yaml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..b92cb42751 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,24 @@ +# Use Debian Bookworm as the base image +FROM ubuntu:latest as builder + +# Update package list and install dependencies +RUN apt-get update && \ + apt-get install -y \ + git \ + vim \ + curl \ + gnupg2 \ + lsb-release \ + ca-certificates + +# Install Node.js (latest LTS version) and npm +RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ + apt-get install -y nodejs + +# Install additional developer tools (optional) +RUN apt-get install -y \ + neovim \ + gh # GitHub CLI + +# Default command (to keep the container running) +CMD ["tail", "-f", "/dev/null"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..89af2b369c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,36 @@ +{ + "name": "talawa api dev environment", + "dockerComposeFile": "docker-compose.yaml", + "service": "devcontainer", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + // Settings to apply to the workspace. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + "settings": { + "terminal.integrated.shell.linux": "/bin/bash", + "typescript.tsdk": "node_modules/typescript/lib", + "database.host": "mongodb", + "redis.host": "redis-stack-server" + }, + // List of extensions to install inside the container + "extensions": [ + "dbaeumer.vscode-eslint", + "ms-azuretools.vscode-docker", + "esbenp.prettier-vscode", + "redhat.vscode-yaml" + ] + } + }, + // Set up forward ports + "forwardPorts": [ + 4000, // Server port + 27017, // MongoDB port + 6379 // Redis port + ], + // Post-create commands to run after creating the container + "postCreateCommand": "npm install", + + // Volumes from docker-compose are already included + "shutdownAction": "stopCompose" +} diff --git a/.devcontainer/docker-compose.yaml b/.devcontainer/docker-compose.yaml new file mode 100644 index 0000000000..253b59f966 --- /dev/null +++ b/.devcontainer/docker-compose.yaml @@ -0,0 +1,34 @@ +services: + mongodb: + image: mongo:latest + ports: + - 27017:27017 + volumes: + - mongodb-data:/data/db + + redis-stack-server: + image: redis/redis-stack-server:latest + ports: + - 6379:6379 + volumes: + - redis-data:/data + + devcontainer: + build: + context: . + dockerfile: Dockerfile + ports: + - "${SERVER_PORT:-4000}:4000" + volumes: + - ../..:/workspaces:cached + depends_on: + - mongodb + - redis-stack-server + environment: + - MONGO_DB_URL=mongodb://mongodb:27017 + - REDIS_HOST=redis-stack-server + - REDIS_PORT=6379 + +volumes: + mongodb-data: + redis-data: diff --git a/.husky/pre-commit b/.husky/pre-commit index 71b41a852c..faf9de7244 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,10 +1,8 @@ -#!/usr/bin/env sh # Disable the hooks in CI [ -n "$CI" ] && exit 0 # Change to the current directory -. "$(dirname -- "$0")/_/husky.sh" # Checks code for typescript type errors and throws errors if found. npm run typecheck diff --git a/Dockerfile.dev b/Dockerfile.dev index 93e0564184..3fda0f43c2 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -11,4 +11,4 @@ COPY . . EXPOSE 4000 -CMD ["npm", "run", "dev"] +CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/INSTALLATION.md b/INSTALLATION.md index 7eee20568f..76934db198 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -15,6 +15,7 @@ This document provides instructions on how to set up and start a running instanc - [Install node.js](#install-nodejs) - [Install TypeScript](#install-typescript) - [Install Required Packages](#install-required-packages) + - [Installation Using Devpod](#install-using-devpod) - [Installation Using Docker](#installation-using-docker) - [Run the Talawa-API Setup](#run-the-talawa-api-setup) - [Install the Docker Application](#install-the-docker-application) @@ -309,6 +310,72 @@ We have created a setup script to make configuring Talawa-API easier. ``` npm run setup ``` +# Install Using Devpod + +This guide provides a step-by-step guide to setting up a Talawa-Api server using Devpod. + +## Setting Up Talawa-Api with Devpod (CLI Version) + +1. **Install Devpod CLI**: + - Download and install the Devpod CLI from [Devpod CLI Installation Guide](https://devpod.sh/docs/getting-started/install#optional-install-devpod-cli). + +2. **Add a Provider**: + - Use Docker or a compatible provider like Podman or Colima. + - Install Docker from their [official documentation](https://docs.docker.com/engine/install/). + - Add a provider using the CLI by following [this guide](https://devpod.sh/docs/getting-started/quickstart-devpod-cli#add-a-provider). + +3. **Create a Workspace**: + - Run the following command in your terminal to start the workspace: + ```bash + devpod up https://github.com/PalisadoesFoundation/talawa-api@develop + ``` + - For more information on creating a workspace, refer to the [Devpod CLI workspace guide](https://devpod.sh/docs/developing-in-workspaces/create-a-workspace#git-repository). + +4. **Select Your IDE**: + - To choose your ide refer to [Devpod CLI ide guide](https://devpod.sh/docs/developing-in-workspaces/connect-to-a-workspace#vs-code) + +5. **Set Up Talawa-Api**: + - Once your IDE is open and the workspace is ready, set up the environment by running: + ```bash + npm run setup + ``` + - Start the Talawa API server by running: + ```bash + npm run dev + ``` + +## Setting Up Talawa-Api with Devpod (GUI Version) + +1. **Install Devpod GUI Application**: + - Download and install the Devpod GUI from [Devpod GUI Installation Guide](https://devpod.sh/docs/getting-started/install). + +2. **Add a Provider**: + - Use Docker or a compatible provider like Podman or Colima. + - Install Docker from their [official documentation](https://docs.docker.com/engine/install/). + - Add a provider using the GUI app by following [this guide](https://devpod.sh/docs/getting-started/quickstart-vscode#add-a-provider). + +3. **Create a Workspace**: + - Open the Devpod GUI application. + - Start a new workspace by entering the following URL in the GUI: + ``` + https://github.com/PalisadoesFoundation/talawa-api@develop + ``` + - For more information on starting a workspace in the GUI, refer to [this guide](https://devpod.sh/docs/getting-started/quickstart-vscode#start-a-workspace-with-vs-code). + +4. **Select Your IDE**: + - In the Devpod GUI, select your desired IDE from the available options. + +5. **Set Up Talawa-Api**: + - Once your IDE is open and the workspace is ready, set up the environment by running: + ```bash + npm run setup + ``` + - Start the Talawa API server by running: + ```bash + npm run dev + ``` + + ## Install the Docker Application