Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望提供 .devcontainer 开发环境 #12

Open
ytianxia6 opened this issue Jul 15, 2022 · 0 comments
Open

希望提供 .devcontainer 开发环境 #12

ytianxia6 opened this issue Jul 15, 2022 · 0 comments

Comments

@ytianxia6
Copy link

ytianxia6 commented Jul 15, 2022

如题,希望一起提供 .devcontainer 开发环境,在vscode中开发使用.

贴一个我正在用的参照,使用 vscode的 remote-devcontainer 生成的默认配置修改后使用:

// devcontainer.json

 // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.238.0/containers/go-postgres
{	
	"name": "Go",
	"dockerComposeFile": "docker-compose.yml",
	"service": "app",
	"workspaceFolder": "/workspace",

	// Configure tool-specific properties.
	"customizations": {
		// Configure properties specific to VS Code.
		"vscode": {
			// Set *default* container specific settings.json values on container create.
			"settings": { 
				"go.toolsManagement.checkForUpdates": "local",
				"go.useLanguageServer": true,
				"go.gopath": "/go",
				"go.goroot": "/usr/local/go"
			},
			
			// Add the IDs of extensions you want installed when the container is created.
			"extensions": [
				"golang.Go",
				"plex.vscode-protolint",
				"peterj.proto",
				"xiaoxin-technology.goctl"
			]
		}
	},

	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [5432],

	// Use 'postCreateCommand' to run commands after the container is created.
	// "postCreateCommand": "go version",

	// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
	"remoteUser": "vscode"
}
 
// docker-compose.yml

version: '3.8'

volumes:
  mysql-data:

services:
  app:
    build: 
      context: .
      dockerfile: Dockerfile
      args:
        # [Choice] Go version 1, 1.18, 1.17
        # Append -bullseye or -buster to pin to an OS version.
        # Use -bullseye variants on local arm64/Apple Silicon.
        VARIANT: 1-bullseye
        # Options
        NODE_VERSION: "lts/*"
    env_file:
        # Ensure that the variables in .env match the same variables in devcontainer.json
        - .env

    # Security Opt and cap_add allow for C++ based debuggers to work. 
    # See `runArgs`: https://github.com/Microsoft/vscode-docs/blob/main/docs/remote/devcontainerjson-reference.md
#     security_opt:
#       - seccomp:unconfined
#     cap_add:
#       - SYS_PTRACE

    volumes:
      - ..:/workspace: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

    # Uncomment the next line to use a non-root user for all processes.
    # user: vscode

    # 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: mariadb:latest
    restart: unless-stopped
    volumes:
      - mysql-data:/var/lib/mysql
    env_file:
      # Ensure that the variables in .env match the same variables in devcontainer.json
      - .env



  redis:
    image: redis

  etcd:
    image: bitnami/etcd

# Dockerfile

# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon): 1, 1.18, 1.17, 1-bullseye, 1.18-bullseye, 1.17-bullseye, 1-buster, 1.18-buster, 1.17-buster
ARG VARIANT=1-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT}

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

USER vscode
RUN go env -w GOPROXY=https://goproxy.cn

RUN GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/go-zero/tools/goctl@latest
RUN goctl env check -i -f --verbose  
RUN chmod +x /go/bin/protoc

USER root

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
#     && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment the next lines to use go get to install anything else you need
# USER vscode
# RUN go get -x <your-dependency-or-tool>
# USER root

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant