The server for Open Course World
at tangled-test 61 lines 2.1 kB view raw
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 26# only scripts that can be used in production are listed here. 27# in dev, the entire scripts/ directory is mounted. 28COPY \ 29 ./scripts/db-console.sh \ 30 ./scripts/env.sh \ 31 ./scripts/migrate.sh \ 32 ./scripts/util.sh \ 33 /app/scripts/ 34 35CMD bash 36 37FROM debian:bookworm-slim 38RUN apt update && apt install -y curl postgresql-client 39 40ARG TARGETARCH 41RUN echo "TARGETARCH:[$TARGETARCH]" 42ENV COCKROACH_VERSION=v22.2.6.linux-$TARGETARCH 43ENV CRDB_CKSM_ARM64=aa3b695171235d143d8d0dc6ebdbec9908b7009b0e6f5b2f750cb3126d7e9298 44ENV CRDB_CKSM_AMD64=de670f9823d0794880ef0c72dfec213470cf6ea3fc96ed27e1706170bae6573b 45 46# install the cockroach-sql standalone binary 47RUN curl -q https://binaries.cockroachdb.com/cockroach-sql-$COCKROACH_VERSION.tgz | \ 48 tar -xzvf - -C /usr/local/bin --strip-components 1 cockroach-sql-$COCKROACH_VERSION/cockroach-sql \ 49 && if [ $TARGETARCH = "arm64" ]; then checksum=$CRDB_CKSM_ARM64; elif [ $TARGETARCH = "amd64" ]; then checksum=$CRDB_CKSM_AMD64; fi \ 50 && echo "$checksum /usr/local/bin/cockroach-sql" | sha256sum --check 51 52COPY --from=builder /go/bin/migrate /bin/migrate 53COPY --from=builder /app/server /bin/server 54COPY --from=builder /app/serve_cache /bin/serve_cache 55COPY --from=builder /app/db/migrations /app/db/migrations 56COPY --from=builder /app/scripts /app/scripts 57 58ENV IS_DOCKER=1 59ENV DB_CONSOLE_TYPE=cockroach-sql 60 61CMD /bin/server