-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (44 loc) · 1.05 KB
/
Copy pathDockerfile
File metadata and controls
58 lines (44 loc) · 1.05 KB
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
FROM golang:1.12.0-alpine
# Get OS/build dependencies for cgo
RUN apk --update upgrade
RUN apk add bash
RUN apk add sqlite
RUN apk add gcc
RUN apk add g++
RUN apk add git mercurial
# Get and install cgo driver
RUN go get github.com/mattn/go-sqlite3
RUN go install -i github.com/mattn/go-sqlite3
# Set workdir
WORKDIR /app
# Remove apk cache
RUN rm -rf /var/cache/apk/*
# env vars
ENV GO111MODULE=on
ENV CGO_ENABLED=1
ENV GOFLAGS=-mod=vendor
ENV TMPL_DIR=/app/tmpl
# Move source files
COPY . .
# Since this wasn't in the repo, create it here...will not persist between image builds
RUN touch db/data.db
# Run the tests
RUN go test ./...
# Build the app
RUN go build -v -mod=vendor ./cmd/api
# New container in which this will run
FROM alpine
RUN apk --no-cache add ca-certificates
WORKDIR /app
# Copy necessary files
COPY --from=0 /app/tmpl ./tmpl
COPY --from=0 /app/api .
COPY --from=0 /app/db ./db
COPY --from=0 /app/sql ./sql
COPY --from=0 /app/static ./static
CMD ["./api"]
ENV TMPL_DIR=/app/tmpl
# Port
EXPOSE 8080
# Run command to start service
CMD ["./api"]