From 04a94d2546ec1c26354dc0ad066e6729b2ffd2e2 Mon Sep 17 00:00:00 2001 From: yaziming Date: Wed, 3 Jun 2020 19:05:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91Docker=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/.air.conf | 47 ++++++++++++ workspace/docker-compose.yml | 97 +++++++++++++++++++++++++ workspace/dockerfiles/golang/Dockerfile | 9 +++ workspace/dockerfiles/node/Dockerfile | 5 ++ 4 files changed, 158 insertions(+) create mode 100644 backend/.air.conf create mode 100644 workspace/docker-compose.yml create mode 100644 workspace/dockerfiles/golang/Dockerfile create mode 100644 workspace/dockerfiles/node/Dockerfile diff --git a/backend/.air.conf b/backend/.air.conf new file mode 100644 index 00000000..a6d35204 --- /dev/null +++ b/backend/.air.conf @@ -0,0 +1,47 @@ +# Config file for [Air](https://github.com/cosmtrek/air) in TOML format + +# Working directory +# . or absolute path, please note that the directories following must be under root. +root = "." +tmp_dir = "/tmp" + +[build] +# Just plain old shell command. You could use `make` as well. +cmd = "go build -o ../tmp/main ./ " +# Binary file yields from `cmd`. +bin = "../tmp/main" +# Customize binary. +full_bin = "../tmp/main start" +# Watch these filename extensions. +include_ext = ["go", "tpl", "tmpl", "html"] +# Ignore these filename extensions or directories. +exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"] +# Watch these directories if you specified. +include_dir = [] +# Exclude files. +exclude_file = [] +# This log file places in your tmp_dir. +log = "air.log" +# It's not necessary to trigger build each time file changes if it's too frequent. +delay = 1000 # ms +# Stop running old binary when build errors occur. +stop_on_error = true +# Send Interrupt signal before killing process (windows does not support this feature) +send_interrupt = false +# Delay after sending Interrupt signal +kill_delay = 500 # ms + +[log] +# Show log time +time = false + +[color] +# Customize each part's color. If no color found, use the raw app log. +main = "magenta" +watcher = "cyan" +build = "yellow" +runner = "green" + +[misc] +# Delete tmp directory on exit +clean_on_exit = true \ No newline at end of file diff --git a/workspace/docker-compose.yml b/workspace/docker-compose.yml new file mode 100644 index 00000000..57854cbf --- /dev/null +++ b/workspace/docker-compose.yml @@ -0,0 +1,97 @@ +version: "3.3" +services: + + master: + build: + context: dockerfiles/golang + command: "air -c .air.conf" + volumes: + - ../backend:/backend + - ./log/master.log:/tmp/air.log + depends_on: + - mongo + - redis + ports: + - 8000:8000 + environment: + CRAWLAB_MONGO_HOST: "mongo" + CRAWLAB_REDIS_ADDRESS: "redis" + CRAWLAB_SERVER_MASTER: "Y" + CRAWLAB_SERVER_REGISTER_TYPE: "customName" + CRAWLAB_SERVER_REGISTER_CUSTOMNODENAME: "master_1" + CRAWLAB_SERVER_PORT: 8000 + worker-1: + build: + context: dockerfiles/golang + command: "air -c .air.conf" + depends_on: + - mongo + - redis + + ports: + - 8001:8000 + volumes: + - ../backend:/backend + - ./log/worker-1.log:/tmp/air.log + environment: + CRAWLAB_MONGO_HOST: "mongo" + CRAWLAB_REDIS_ADDRESS: "redis" + CRAWLAB_SERVER_MASTER: "N" + CRAWLAB_SERVER_PORT: 8001 + CRAWLAB_SERVER_REGISTER_TYPE: "customName" + CRAWLAB_SERVER_REGISTER_CUSTOMNODENAME: "worker_1" + worker-2: + build: + context: dockerfiles/golang + command: "air -c .air.conf" + # volumes: + # - ../backend:/backend + # - ./log/master.log:/tmp/air.log + depends_on: + - mongo + - redis + ports: + - 8002:8000 + volumes: + - ../backend:/backend + - ./log/worker-2.log:/tmp/air.log + environment: + CRAWLAB_MONGO_HOST: "mongo" + CRAWLAB_REDIS_ADDRESS: "redis" + CRAWLAB_SERVER_MASTER: "N" + CRAWLAB_SERVER_PORT: 8002 + CRAWLAB_SERVER_REGISTER_TYPE: "customName" + CRAWLAB_SERVER_REGISTER_CUSTOMNODENAME: "worker_2" + frontend: + build: + context: ./dockerfiles/node + args: + - NPM_REGISTRY="http://registry.npm.taobao.org/" + container_name: crawlab_frontend + ports: + - 8080:8080 + volumes: + - ../frontend:/frontend + command: + - /bin/sh + - -c + - | + yarn install + yarn run serve + depends_on: + - master + mongo: + image: mongo:latest + restart: always + # volumes: + # - "/opt/crawlab/mongo/data/db:/data/db" # make data persistent 持久化 + ports: + - "27017:27017" # expose port to host machine 暴露接口到宿主机 + redis: + image: redis:latest + restart: always + # command: redis-server --requirepass "password" # set redis password 设置 Redis 密码 + # volumes: + # - "/opt/crawlab/redis/data:/data" # make data persistent 持久化 + ports: + - "6379:6379" # expose port to host machine 暴露接口到宿主机 \ No newline at end of file diff --git a/workspace/dockerfiles/golang/Dockerfile b/workspace/dockerfiles/golang/Dockerfile new file mode 100644 index 00000000..e2549194 --- /dev/null +++ b/workspace/dockerfiles/golang/Dockerfile @@ -0,0 +1,9 @@ +FROM golang:buster +RUN go env -w GOPROXY=https://goproxy.io,https://goproxy.cn && \ + go env -w GO111MODULE="on" +WORKDIR /tools +RUN go get github.com/cosmtrek/air +WORKDIR /backend +RUN rm -rf /tools +VOLUME /backend +EXPOSE 8080 \ No newline at end of file diff --git a/workspace/dockerfiles/node/Dockerfile b/workspace/dockerfiles/node/Dockerfile new file mode 100644 index 00000000..ba6db226 --- /dev/null +++ b/workspace/dockerfiles/node/Dockerfile @@ -0,0 +1,5 @@ +FROM node:latest +WORKDIR frontend +ARG NPM_REGISTRY="http://www.npmjs.org" +RUN npm config set registry ${NPM_REGISTRY} +