Dockerfile 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. COPY /api ./api
  12. RUN --mount=type=cache,target=$GOPATH/pkg/mod \
  13. go mod download
  14. # Go build environment
  15. # --------------------
  16. FROM base AS build-go
  17. RUN --mount=type=cache,target=/root/.cache/go-build \
  18. --mount=type=cache,target=$GOPATH/pkg/mod \
  19. go build -ldflags '-w -s' -a -o ./bin/app ./cmd/app && \
  20. go build -ldflags '-w -s' -a -o ./bin/migrate ./cmd/migrate && \
  21. go build -ldflags '-w -s' -a -o ./bin/ready ./cmd/ready
  22. # Go test environment
  23. # -------------------
  24. FROM base AS porter-test
  25. RUN --mount=type=cache,target=/root/.cache/go-build \
  26. --mount=type=cache,target=$GOPATH/pkg/mod \
  27. go test ./...
  28. # Webpack build environment
  29. # -------------------------
  30. FROM node:latest as build-webpack
  31. WORKDIR /webpack
  32. COPY ./dashboard ./
  33. RUN npm i
  34. ENV NODE_ENV=production
  35. RUN npm run build
  36. # Deployment environment
  37. # ----------------------
  38. FROM alpine
  39. RUN apk update
  40. COPY --from=build-go /porter/bin/app /porter/
  41. COPY --from=build-go /porter/bin/migrate /porter/
  42. COPY --from=build-go /porter/bin/ready /porter/
  43. COPY --from=build-webpack /webpack/build /porter/static
  44. ENV DEBUG=false
  45. ENV STATIC_FILE_PATH=/porter/static
  46. ENV SERVER_PORT=8080
  47. ENV SERVER_TIMEOUT_READ=5s
  48. ENV SERVER_TIMEOUT_WRITE=10s
  49. ENV SERVER_TIMEOUT_IDLE=15s
  50. ENV COOKIE_SECRETS=secret
  51. ENV SQL_LITE=true
  52. ENV ADMIN_INIT=false
  53. EXPOSE 8080
  54. CMD /porter/migrate && /porter/app