Continued work on docker builds

This commit is contained in:
Ben Yanke
2018-04-19 17:55:47 -05:00
parent f039bbb964
commit f076f868dc
6 changed files with 68 additions and 6 deletions
+44 -6
View File
@@ -1,9 +1,47 @@
FROM golang:latest
#################
# Build Step
#################
FROM golang:latest as build
MAINTAINER Ben Yanke <ben@benyanke.com>
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]
RUN mkdir /app /tmp/gocode
ADD . /app/
WORKDIR /app
# Required Envs for GO
ENV GOPATH=/tmp/gocode
# Install deps
RUN go get -d ./...
# Build
# RUN rm -f /app/bin/glauth64 && GOOS=linux GOARCH=amd64 go build -o /app/bin/glauth64 glauth.go bindata.go ldapbackend.go webapi.go configbackend.go
RUN GOOS=linux GOARCH=amd64 go build -o /app/bin/glauth64 glauth.go bindata.go ldapbackend.go webapi.go configbackend.go
# RUN for GOOS in darwin linux; do
# for GOARCH in 386 amd64; do
# go build -v -o /app/bin/glauth-$GOOS-$GOARCH
# done
# done
#################
# Test Step
#################
FROM golang:alpine as run
MAINTAINER Ben Yanke <ben@benyanke.com>
RUN apk --no-cache add ca-certificates
ADD sample-simple.cfg /app/sample-simple.cfg
WORKDIR /app
COPY --from=build /app/bin/glauth64 /app/glauth64
# CMD /app/glauth64 -c /app/sample-simple.cfg
CMD ["/app/glauth64", "-c", "/app/sample-simple.cfg"]
+16
View File
@@ -0,0 +1,16 @@
# Example file
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
# docker build -t alexellis2/href-counter:latest .
FROM golang:1.7.3
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html
COPY app.go .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=0 /go/src/github.com/alexellis/href-counter/app .
CMD ["./app"]
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Executable
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
img="glauth-dev"
sudo docker build -f Dockerfile -t $img .
sudo docker run $img
sudo docker rmi -f $img