Last active
November 18, 2017 00:57
-
-
Save haitch/68f313ffd955fcf4465777c14bbc0b18 to your computer and use it in GitHub Desktop.
Multi-Stage build for golang and react project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. using golang image to build server side code (echo.labstack.com) | |
FROM golang:1.8 as goBuilder | |
RUN go get -u github.com/golang/dep/cmd/dep | |
WORKDIR /go/src/goApp | |
# optimization for caching layers | |
COPY ["Gopkg.toml", "Gopkg.lock", "./"] | |
RUN dep ensure --vendor-only | |
# coping source file and compile | |
COPY ["*.go", "./"] | |
RUN go install | |
# 2. using node environment to build react project | |
FROM kkarczmarczyk/node-yarn as nodeBuilder | |
WORKDIR /webApp | |
# optimization for caching layers | |
COPY ["package.json", "yarn.lock", "./"] | |
RUN yarn install | |
# coping source file and compile | |
COPY ["src", "./src"] | |
COPY ["public", "./public"] | |
RUN yarn build | |
# 3. final image with no dependency, just binaries | |
FROM alpine | |
# https://stackoverflow.com/questions/34729748/installed-go-binary-not-found-in-path-on-alpine-linux-docker/35613430#35613430 | |
RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 | |
WORKDIR /app | |
COPY --from=goBuilder /go/bin/goApp /app | |
COPY --from=nodeBuilder /webApp/build /app/build | |
ENTRYPOINT ./goApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment