Dockerfile 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # syntax=docker/dockerfile:1.1.7-experimental
  2. # Base Go environment
  3. # -------------------
  4. FROM golang:1.15-alpine as base
  5. WORKDIR /porter
  6. RUN apk update && apk add --no-cache gcc musl-dev git
  7. COPY go.mod go.sum ./
  8. COPY /cmd ./cmd
  9. COPY /internal ./internal
  10. COPY /server ./server
  11. RUN --mount=type=cache,target=$GOPATH/pkg/mod \
  12. go mod download
  13. # Go build environment
  14. # --------------------
  15. FROM base AS build-go
  16. RUN --mount=type=cache,target=/root/.cache/go-build \
  17. --mount=type=cache,target=$GOPATH/pkg/mod \
  18. go build -ldflags '-w -s' -a -o ./bin/app ./cmd/app && \
  19. go build -ldflags '-w -s' -a -o ./bin/migrate ./cmd/migrate
  20. # Go test environment
  21. # -------------------
  22. FROM base AS porter-test
  23. RUN --mount=type=cache,target=/root/.cache/go-build \
  24. --mount=type=cache,target=$GOPATH/pkg/mod \
  25. go test ./...
  26. # Webpack build environment
  27. # -------------------------
  28. FROM node:latest as build-webpack
  29. WORKDIR /webpack
  30. COPY ./dashboard ./
  31. RUN npm i
  32. ENV NODE_ENV=production
  33. RUN npm run build
  34. # Deployment environment
  35. # ----------------------
  36. FROM alpine
  37. RUN apk update
  38. COPY --from=build-go /porter/bin/app /porter/
  39. COPY --from=build-go /porter/bin/migrate /porter/
  40. COPY --from=build-webpack /webpack/build /porter/static
  41. ENV DEBUG=false
  42. ENV STATIC_FILE_PATH=/porter/static
  43. ENV SERVER_PORT=8080
  44. ENV SERVER_TIMEOUT_READ=5s
  45. ENV SERVER_TIMEOUT_WRITE=10s
  46. ENV SERVER_TIMEOUT_IDLE=15s
  47. ENV COOKIE_SECRETS=secret
  48. ENV QUICK_START=true
  49. EXPOSE 8080
  50. CMD /porter/migrate && /porter/app