-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
133 lines (111 loc) · 4.35 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
FROM ubuntu:20.04
# Install dependencies.
RUN apt-get update
# Install `tzdata` separately to avoid interactive input (see https://serverfault.com/questions/949991/how-to-install-tzdata-on-a-ubuntu-docker-image)
RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata
RUN apt-get install -o Acquire::ForceIPv4=true -y \
python3 \
python3-pip \
protobuf-compiler \
curl
# Install a more recent version of Go (`apt-get install golang` yields 1.1 in this environment).
RUN curl -s https://storage.googleapis.com/golang/go1.17.5.linux-amd64.tar.gz -o go1.17.5.linux-amd64.tar.gz
RUN tar -zxf go1.17.5.linux-amd64.tar.gz -C /usr/local/ && rm go1.17.5.linux-amd64.tar.gz
ENV PATH="/usr/local/go/bin:${PATH}"
# Setup $GOBIN and add it to $PATH.
ENV GOBIN=/go/bin
RUN mkdir -p ${GOBIN}
ENV PATH="${GOBIN}:${PATH}"
# Install a more recent version of Node (`apt-get install nodejs` yields 10.19.0 in this environment).
RUN curl -s https://nodejs.org/dist/v14.18.3/node-v14.18.3-linux-x64.tar.xz -o node-v14.18.3-linux-x64.tar.xz
RUN tar -xf node-v14.18.3-linux-x64.tar.xz -C /usr/local/ && rm node-v14.18.3-linux-x64.tar.xz
ENV PATH="/usr/local/node-v14.18.3-linux-x64/bin:${PATH}"
# Install Miniconda.
RUN curl -s https://repo.anaconda.com/miniconda/Miniconda3-py38_4.10.3-Linux-x86_64.sh -o Miniconda3-py38_4.10.3-Linux-x86_64.sh
ENV CONDAROOT=/go/src/thiago.pub/conda
RUN mkdir -p ${CONDAROOT}
RUN bash Miniconda3-py38_4.10.3-Linux-x86_64.sh -b -p ${CONDAROOT} -f
ENV PATH="${CONDAROOT}/bin:${PATH}"
# Install Orekit dependencies.
# Orekit 10.3.1 was installed in this environment by default, but I need 11.0.2.
RUN conda install -y -c conda-forge \
orekit=11.0.2 \
matplotlib \
basemap \
cartopy
# Install Python gRPC and space-related libraries.
# Numba (dep of tletools) needs NumPy 1.21 or less.
RUN pip install \
protobuf \
grpcio \
grpcio-health-checking \
grpcio-reflection \
grpcio-tools \
numpy==1.21 \
TLE-tools \
dash
# Set up workdir.
ENV CODE_ROOT=/go/src/thiago.pub/space-api
RUN mkdir -p ${CODE_ROOT}/logs
RUN mkdir -p ${CODE_ROOT}/celestrak
WORKDIR ${CODE_ROOT}
# Copy code.
COPY google ${CODE_ROOT}/google
COPY proto ${CODE_ROOT}/proto
COPY scripts ${CODE_ROOT}/scripts
COPY src ${CODE_ROOT}/src
COPY tools ${CODE_ROOT}/tools
# Setup Orekit and mpl_toolkits.basemap.
COPY orekit-data.zip ${CODE_ROOT}/
ENV PROJ_LIB=${CODE_ROOT}/proj_lib
RUN mkdir ${PROJ_LIB}
# Set up Node UI.
WORKDIR ${CODE_ROOT}/src/ui
RUN npm install
# Install protoc-gen-go (see https://github.com/grpc-ecosystem/grpc-gateway/)
WORKDIR ${CODE_ROOT}/tools
RUN go mod init github.com/thiagorobert/space-api/go_proto_tools
RUN go mod tidy -compat=1.17
RUN go install \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc
# Generate proto code, setup Go modules, and build Go code.
WORKDIR ${CODE_ROOT}
RUN python3 -m grpc_tools.protoc \
-I=. \
--python_out=./src/python_grpc \
--grpc_python_out=./src/python_grpc \
./google/api/http.proto ./google/api/annotations.proto \
./proto/unary.proto
RUN protoc \
-I=. \
--go_out ./src/go_rest_proxy/autogenerated/ --go_opt paths=source_relative \
--go-grpc_out ./src/go_rest_proxy/autogenerated/ --go-grpc_opt paths=source_relative \
--grpc-gateway_out ./src/go_rest_proxy/autogenerated/ \
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative \
./proto/unary.proto
# Setup required Go modules and build REST proxy.
WORKDIR ${CODE_ROOT}/src/go_rest_proxy/autogenerated/proto/
RUN go mod init github.com/thiagorobert/space-api/autogenerated_proto
RUN go mod tidy
WORKDIR ${CODE_ROOT}
RUN go mod init github.com/thiagorobert/space-api
RUN echo "replace github.com/thiagorobert/space-api/autogenerated_proto => ./src/go_rest_proxy/autogenerated/proto/" >> go.mod
RUN go mod tidy -compat=1.17
RUN go build src/go_rest_proxy/rest_reverse_proxy.go
# Expose requierd ports. This is not required, it's more of a documentation.
# UI
EXPOSE 8080
# REST proxy
EXPOSE 8081
# gRPC server
EXPOSE 9090
# Dash server (to render orbit plots)
EXPOSE 9091
# File server
EXPOSE 9092
# Run script that starts the system (gRPC server, REST proxy, Node UI, file server).
CMD ["/go/src/thiago.pub/space-api/scripts/bootstrap.sh"]