railstack/go-on-rails

View on GitHub
lib/generators/templates/Dockerfile.go_app.erb

Summary

Maintainability
Test Coverage
# Multi-stage builds require Docker 17.05 or higher on the daemon and client.
# see: https://docs.docker.com/engine/userguide/eng-image/multistage-build/

# build the go app binary
FROM golang:1.9.2 as builder
WORKDIR /root/
COPY . /root/
<%- if %w[127.0.0.1 localhost].include? @db_config[:host] and @db_config[:driver_name] != "sqlite3" -%>
RUN perl -pi -e "s/tcp\(.*?:/tcp\(db:/; s/host=\S+? /host=db /" src/models/db.go
<%- end -%>
RUN make deps
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o myapp .

# use the binary app to build the target image
FROM alpine:latest
WORKDIR /root/
ADD views /root/views
ADD public /root/public
COPY --from=builder /root/myapp .
CMD ["./myapp"]