This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Dockerfile
72 lines (57 loc) · 1.93 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# syntax = docker/dockerfile:1-experimental
FROM --platform=${BUILDPLATFORM} golang:alpine AS gobase
RUN apk add --no-cache \
ca-certificates \
gcc \
git \
musl-dev \
sqlite \
&& true
RUN env GO111MODULE=on go get -u \
github.com/cortesi/modd/cmd/modd \
golang.org/x/lint/golint \
golang.org/x/tools/cmd/goimports \
&& true
WORKDIR /src
FROM --platform=${BUILDPLATFORM} node:alpine AS nodebase
RUN npm install -g @vue/cli
WORKDIR /src/web
FROM --platform=${BUILDPLATFORM} nodebase AS nodebuilder
COPY web/package*.json /src/web/
RUN yarn install --no-progress
COPY web/ /src/web/
RUN yarn run lint --no-progress
RUN yarn run build --no-progress --production
FROM --platform=${BUILDPLATFORM} gobase AS gobuilder
ENV CGO_ENABLED=0
COPY go.mod go.sum .
RUN --mount=type=cache,target=/root/.cache/go-build go mod download
ARG BUILD_VERSION=master
ARG BUILD_COMMIT=unknown
ARG BUILD_DATE=now
ARG TARGETOS
ARG TARGETARCH
COPY . .
COPY --from=nodebuilder /src/web/dist/ ./web/dist/
RUN --mount=type=cache,target=/root/.cache/go-build golint -set_exit_status ./...
RUN --mount=type=cache,target=/root/.cache/go-build go vet -v ./...
RUN mkdir -p dist
RUN --mount=type=cache,target=/root/.cache/go-build GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -v -x -o dist \
-ldflags "\
-X github.com/nrocco/bookmarks/cmd.version=${BUILD_VERSION} \
-X github.com/nrocco/bookmarks/cmd.commit=${BUILD_COMMIT} \
-X github.com/nrocco/bookmarks/cmd.date=${BUILD_DATE} \
-s -w"
RUN --mount=type=cache,target=/root/.cache/go-build go test -v -short ./...
FROM scratch AS bin
COPY --from=gobuilder /src/dist/ /
FROM alpine:edge
RUN apk add --no-cache \
ca-certificates \
sqlite \
&& true
COPY --from=gobuilder /src/dist/bookmarks /usr/bin/bookmarks
EXPOSE 3000
WORKDIR /var/lib/bookmarks
VOLUME /var/lib/bookmarks
CMD ["bookmarks", "server"]