From cd148d834e8cec99bfbc6b187a27253118c0171c Mon Sep 17 00:00:00 2001 From: rharkor Date: Fri, 21 Jul 2023 15:28:08 +0000 Subject: [PATCH] feat: dev container --- .devcontainer/Dockerfile | 14 ++++++ .devcontainer/devcontainer.json | 73 ++++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 48 +++++++++++++++++++++ .env | 1 + .github/workflows/cr.yml | 18 ++++++++ .vscode/extensions.json | 3 ++ scripts/install-brew.sh | 7 +++ src/prisma/schema.prisma | 11 +++++ src/prisma/user.prisma | 8 ++++ 9 files changed, 183 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .env create mode 100644 .github/workflows/cr.yml create mode 100644 .vscode/extensions.json create mode 100755 scripts/install-brew.sh create mode 100644 src/prisma/schema.prisma create mode 100644 src/prisma/user.prisma diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..69f4640e --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,14 @@ +FROM mcr.microsoft.com/devcontainers/typescript-node:1-18-bullseye + +# [Optional] Uncomment this section to install additional OS packages. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends git-cola + +# [Optional] Uncomment if you want to install an additional version of node using nvm +# ARG EXTRA_NODE_VERSION=10 +# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" + +# [Optional] Uncomment if you want to install more global node modules +RUN su node -c "npm install -g prisma" + +RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..7ea61ead --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,73 @@ +{ + "name": "next-boilerplate", + + // 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.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": "app", + "runServices": ["redis", "db"], + + // 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": "/workspaces/${localWorkspaceFolderBasename}", + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [3000, 5432, 6379, 6080], + + "portsAttributes": { + "3000": { + "label": "nextjs" + }, + "5432": { + "label": "postgres" + }, + "6379": { + "label": "redis" + }, + "6080": { + "label": "desktop" + } + }, + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "npm install && ./scripts/install-brew.sh", + + // Configure tool-specific properties. + "customizations": { + "postCreateCommand": "npm install && ./scripts/install-brew.sh", + "vscode": { + "extensions": [ + "formulahendry.auto-rename-tag", + "aaron-bond.better-comments", + "WallabyJs.console-ninja", + "EditorConfig.EditorConfig", + "dsznajder.es7-react-js-snippets", + "dbaeumer.vscode-eslint", + "tombonnike.vscode-status-bar-format-toggle", + "github.vscode-github-actions", + "GitHub.copilot", + "GitHub.copilot-chat", + "GitHub.copilot-labs", + "eamodio.gitlens", + "ecmel.vscode-html-css", + "Zignd.html-css-class-completion", + "yzhang.markdown-all-in-one", + "esbenp.prettier-vscode", + "rvest.vs-code-prettier-eslint", + "Prisma.prisma", + "bradlc.vscode-tailwindcss", + "donjayamanne.githistory", + "ms-azuretools.vscode-docker" + ] + } + }, + "features": { + "ghcr.io/devcontainers/features/desktop-lite:1": {} + } + + // 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 00000000..af1d392e --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,48 @@ +version: "3.8" + +services: + app: + build: + context: . + dockerfile: Dockerfile + + volumes: + - ../..:/workspaces:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # 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: postgres + 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.) + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:app + + redis: + image: redis:latest + restart: unless-stopped + volumes: + - redis-data:/data + + # Add "forwardPorts": ["6379"] to **devcontainer.json** to forward Redis locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:app + +volumes: + postgres-data: + redis-data: diff --git a/.env b/.env new file mode 100644 index 00000000..b1f36f0a --- /dev/null +++ b/.env @@ -0,0 +1 @@ +DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public" diff --git a/.github/workflows/cr.yml b/.github/workflows/cr.yml new file mode 100644 index 00000000..e51fac28 --- /dev/null +++ b/.github/workflows/cr.yml @@ -0,0 +1,18 @@ +name: Code Review +permissions: + contents: read + pull-requests: write +on: + pull_request: + types: + - opened + - reopened + - synchronize +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: anc95/ChatGPT-CodeReview@main + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}" diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..7e257db9 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": [] +} \ No newline at end of file diff --git a/scripts/install-brew.sh b/scripts/install-brew.sh new file mode 100755 index 00000000..25b5e96b --- /dev/null +++ b/scripts/install-brew.sh @@ -0,0 +1,7 @@ +#! /bin/sh +sudo chown -R $(whoami) /home/linuxbrew/.linuxbrew +(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /home/$USER/.bashrc +eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" +brew install gcc +brew install pre-commit +pre-commit install -t commit-msg \ No newline at end of file diff --git a/src/prisma/schema.prisma b/src/prisma/schema.prisma new file mode 100644 index 00000000..d205f42a --- /dev/null +++ b/src/prisma/schema.prisma @@ -0,0 +1,11 @@ +// This is your Prisma schema file, +// learn more about it in the docs: https://pris.ly/d/prisma-schema + +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} diff --git a/src/prisma/user.prisma b/src/prisma/user.prisma new file mode 100644 index 00000000..12ea5220 --- /dev/null +++ b/src/prisma/user.prisma @@ -0,0 +1,8 @@ +model User { + id Int @id @default(autoincrement()) + username String @unique + email String @unique + password String + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt +} \ No newline at end of file