Skip to content

全栈开发环境配置

  • 基本技术栈:
    前端:react + ts/js + nextjs + ui-lib(antd) + sass;
    后端相关:nodejs, prisma, golang, gin, rust;
    数据库相关:mysql, postgresql, redis;
    部署相关:nginx, docker, docker-compose;
    开发和部署工具: git, vscode, github(github actions), dockerhub, vercel, supabase;
  • 参考repo: https://github.com/tangzixuan/develop-template;

项目环境模版

  • 利用docker, docker-compose的方式,搭建本地开发环境模版,包括前端,后端,数据库,部署等,方便快速开发和部署;

nextjs basic template

yaml
# Dockerfile

# Use node alpine as it's a small node image
FROM node:alpine
RUN npm install -g pnpm

# Create the directory on the node image 
# where our Next.js app will live
RUN mkdir -p /app

# Set /app as the working directory
WORKDIR /app

# to the /app working directory
COPY . /app

RUN npm run bootstrap

# Ensure port 3000 is accessible to our system
EXPOSE 3000

# Run yarn dev, as we would via the command line 
# CMD ["npm", "dev"]
CMD ["pnpm", "dev"]
  • 开发阶段,docker-compose.yml
yaml
version: "3"

services:
  nginx:
    image: nginx
    volumes:
      - type: bind
        source: ./.nginx/nginx.conf
        target: /etc/nginx/conf.d/default.conf
        read_only: true
    ports:
      - 80:80
  fe-next:
    build:
      context: .
      dockerfile: fe-next-dev.Dockerfile
    container_name: fe-next
    restart: always
    volumes:
      - ./:/app
      - /app/node_modules
      - /app/.next
    ports:
      - 3000:3000

nextjs-prisma template

golang-gin-template

yaml
# https://go.dev/dl/
FROM golang:1.20.4

RUN mkdir /app
WORKDIR /app
ADD . /app

RUN go install github.com/cosmtrek/air@latest

ENTRYPOINT air --build.cmd "go build -o bin/main cmd/main.go" --build.bin "./bin/main"
  • dev, docker-compose.yml
yaml
version: '3'
services:
  golang-server-basic-app:
    build: 
      context: .
      dockerfile: golang-server-basic-app-dev.Dockerfile
    container_name: golang-server-basic-app-dev
    # ports:
    #   - "8080:8080" # Web Server
    # 通过挂在本地目录,实现代码修改后自动编译
    volumes:
      - ./:/app
    environment:
      PORT: "8080"