The server for Open Course World
1# This Dockerfile is for both local development and production.
2# See docker-compose.yml for local dev configuration.
3FROM golang:latest AS builder
4RUN go install -tags 'cockroachdb' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
5
6WORKDIR /app
7
8COPY go.mod go.sum ./
9RUN go mod download && go mod verify
10
11COPY main.go /app/main.go
12COPY config /app/config
13COPY db /app/db
14COPY nex /app/nex
15COPY util /app/util
16COPY api /app/api
17COPY orm /app/orm
18
19ENV GOCACHE=/go-cache
20# use a docker cache mount to avoid recompiling all dependencies each time
21RUN --mount=type=cache,target=/go-cache \
22 go build -v -o /app/server *.go
23RUN --mount=type=cache,target=/go-cache \
24 go build -v -o /app/serve_cache util/serve_dump_cache/*.go
25
26CMD bash
27
28FROM debian:bookworm-slim
29RUN apt update && apt install -y curl postgresql-client
30
31ARG TARGETARCH
32ENV COCKROACH_VERSION=v22.2.6.linux-$TARGETARCH
33ENV CRDB_CKSM_ARM64=aa3b695171235d143d8d0dc6ebdbec9908b7009b0e6f5b2f750cb3126d7e9298
34ENV CRDB_CKSM_AMD64=de670f9823d0794880ef0c72dfec213470cf6ea3fc96ed27e1706170bae6573b
35
36# install the cockroach-sql standalone binary
37RUN curl -q https://binaries.cockroachdb.com/cockroach-sql-$COCKROACH_VERSION.tgz | \
38 tar -xzvf - -C /usr/local/bin --strip-components 1 cockroach-sql-$COCKROACH_VERSION/cockroach-sql \
39 && if [ $TARGETARCH = "arm64" ]; then checksum=$CRDB_CKSM_ARM64; elif [ $TARGETARCH = "amd64" ]; then checksum=$CRDB_CKSM_AMD64; fi \
40 && echo "$checksum /usr/local/bin/cockroach-sql" | sha256sum --check
41
42COPY --from=builder /go/bin/migrate /bin/migrate
43COPY --from=builder /app/server /bin/server
44COPY --from=builder /app/serve_cache /bin/serve_cache
45COPY --from=builder /app/db/migrations /app/db/migrations
46
47# only scripts that can be used in production are listed here.
48# in dev, the entire scripts/ directory is mounted.
49COPY \
50 ./scripts/db-console.sh \
51 ./scripts/env.sh \
52 ./scripts/migrate.sh \
53 ./scripts/util.sh \
54 /app/scripts/
55WORKDIR /app
56
57ENV IS_DOCKER=1
58ENV DB_CONSOLE_TYPE=cockroach-sql
59
60CMD /bin/server