1FROM golang:1.10 as builder
2
3# Set up workdir
4WORKDIR /go/src/github.com/cayleygraph/cayley
5
6# Restore vendored dependencies
7RUN curl -L https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 -o /usr/local/bin/dep && \
8    chmod +x /usr/local/bin/dep
9COPY Gopkg.toml Gopkg.lock ./
10RUN dep ensure --vendor-only
11
12# This will be used to init cayley and as config file in the final image.
13# Make sure you start every path with %PREFIX% to make it available in both
14# the builder image and the final image.
15RUN echo '{"store":{"backend":"bolt","address":"%PREFIX%/data/cayley.db"}}' > config.json
16
17# Create filesystem for minimal image
18RUN mkdir -p /fs/assets
19RUN mkdir -p /fs/bin
20RUN mkdir -p /fs/data
21RUN mkdir -p /fs/etc
22RUN sed 's_%PREFIX%__g' config.json > /fs/etc/cayley.json
23
24ENV PATH /fs/bin:$PATH
25
26# Copy CA certs from builder image to the filesystem of the cayley image
27RUN mkdir -p /fs/etc/ssl/certs
28RUN cp /etc/ssl/certs/ca-certificates.crt /fs/etc/ssl/certs/ca-certificates.crt
29
30RUN mkdir -p /fs/lib/x86_64-linux-gnu
31RUN cp /lib/x86_64-linux-gnu/libc-* /fs/lib/x86_64-linux-gnu/
32
33# Add assets to target fs
34COPY docs /fs/assets/docs
35COPY static /fs/assets/static
36COPY templates /fs/assets/templates
37
38# Add and build static linked version of cayley
39# This will show warnings that glibc is required at runtime which can be ignored
40COPY . .
41RUN go build \
42  -ldflags="-linkmode external -extldflags -static -X github.com/cayleygraph/cayley/version.GitHash=$(git rev-parse HEAD | cut -c1-12)" \
43  -a \
44  -installsuffix cgo \
45  -o /fs/bin/cayley \
46  -v \
47  ./cmd/cayley
48
49RUN sed 's_%PREFIX%_/fs_g' config.json > /etc/cayley.json
50RUN cayley init --config /etc/cayley.json
51
52
53FROM scratch
54LABEL maintainer="Yannic Bonenberger" \
55           email="contact@yannic-bonenberger.com"
56
57# Expose the port and volume for configuration and data persistence. If you're
58# using a backend like bolt, make sure the file is saved to this directory.
59COPY --from=builder /fs /
60VOLUME ["/data"]
61
62EXPOSE 64210
63
64# Adding everything to entrypoint allows us to init+load+serve
65# with default containers parameters:
66#   i.e.: `docker run quay.io/cayleygraph/cayley --init -i /data/my_data.nq`
67ENTRYPOINT ["cayley", "http", "--assets", "/assets", "--host", ":64210"]
68