Browse Source

Update docker file to support go modules build.

Alex Myasoedov 4 years ago
parent
commit
ae63721e69
3 changed files with 17 additions and 6 deletions
  1. 0 1
      .dockerignore
  2. 17 4
      Dockerfile
  3. 0 1
      Makefile

+ 0 - 1
.dockerignore

@@ -6,4 +6,3 @@ Readme.md
 slides/
 node_modules/
 vendor/
-*.go

+ 17 - 4
Dockerfile

@@ -1,8 +1,21 @@
+FROM golang:1.12 AS compiler
+
+WORKDIR $GOPATH/src/github.com/msoedov/hacker-slides
+
+ENV GO111MODULE on
+COPY . .
+RUN GOOS=linux CGO_ENABLE=0 go build  -a -tags netgo -ldflags '-w -extldflags "-static"' -o app *.go
+RUN cp app /bin/app
+
+
 FROM alpine:3.8
 
-WORKDIR /app
+WORKDIR /srv
 
-COPY . /app
 ENV GIN_MODE=release
-
-CMD ./main $PORT
+RUN mkdir slides
+COPY --from=compiler /bin/app /bin/app
+COPY static static
+COPY templates templates
+COPY initial-slides.md initial-slides.md
+CMD app $PORT

+ 0 - 1
Makefile

@@ -7,7 +7,6 @@ repo:
 	@echo $(DOCKER_IMAGE)
 
 build:
-	@GOOS=linux CGO_ENABLE=0 go build main.go
 	@docker build -t $(DOCKER_IMAGE) .
 	@docker tag $(DOCKER_IMAGE) $(REPO)