drux41001 2017-04-13 05:54
浏览 71

在Docker中设置Go Glide

I am building an app with Go and Glide in docker. I also have to use reflex to trigger the compiling automatically.

I can not figure out how to make Glide work out with docker.

Dockerfile

FROM golang:1.8.1-alpine

ENV GOBINARIES /go/bin
ENV BUILDPATH /code
ENV REFLEXURL=http://s3.amazonaws.com/wbm-raff/bin/reflex1.8a
ENV REFLEXSHA=19bdbbb68c869f85ee22a6b7fa9c73f8e5b46d0fe7a73df37e028555a6ba03e8

WORKDIR $GOBINARIES
RUN rm -rf /var/cache/apk/*
RUN wget -q "$REFLEXURL" -O reflex
RUN chmod +x /go/bin/reflex

ENV TOOLS /go/_tools

RUN mkdir -p $BUILDPATH
ENV PORT 5000
EXPOSE $PORT

RUN mkdir -p $TOOLS
ADD build.sh $TOOLS
ADD reflex.conf $TOOLS
RUN chown root $TOOLS/build.sh
RUN chmod +x $TOOLS/build.sh

WORKDIR $BUILDPATH
CMD ["reflex","-c","/go/_tools/reflex.conf"]

build.sh

set -e
echo "[build.sh:building binary]"
cd $BUILDPATH
glide install -s -v
go build -o /servicebin && rm -rf /tmp/*
echo "[build.sh:launching binary]"
/servicebin

reflex.conf

-sr '\.build$' -- sh -c '/go/_tools/build.sh'

docker-compose.yaml

version: '3'
services:
  logen:
    build:
      context: ./Docker
      dockerfile: Dockerfile
    ports:
    - "5000:5000"
    volumes:
    - .:/code

Atom on-save plugin configuration file

[
  {
    "srcDir": ".",
    "destDir": ".",
    "files": "**/*.go",
    "command": "echo $(date) - ${srcFile} > .build"
  }
]

main.go

package main

import (
    "io"
    "log"
    "net/http"
    "os"
  "github.com/astaxie/beego"
)

func hello(w http.ResponseWriter, r *http.Request) {
    io.WriteString(w, "Hello world!1")
}

func main() {
    log.SetOutput(os.Stdout)

    port := ":" + os.Getenv("PORT")
    http.HandleFunc("/", hello)

    log.Printf("
 Application is listening on %v
", port)

    http.ListenAndServe(port, nil)
}

enter image description here

  • 写回答

1条回答 默认 最新

  • dousong5492 2017-04-13 22:19
    关注

    Actually, I do not need to install Glide in the container! Just reflect the vendor folder in host machine to $GOPATH/src in docker-compose.yml. Then the compile will be ok.

    version: '3'
    services:
      logen:
        build:
          context: ./Docker
          dockerfile: Dockerfile
        ports:
        - "5000:5000"
        volumes:
        - .:/code
        - ./vendor:/go/src
    
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路