This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Dockerfile
138 lines (93 loc) · 3.98 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
134
135
136
137
138
################################################################################
# Build Base Image
################################################################################
# Start from a rust base image
FROM rust:1.70.0 as base
# Set the current directory
WORKDIR /app
# Copy everthing that is not dockerignored to the image
COPY . .
# Prepare
RUN rustup toolchain install stable
################################################################################
# Build Frontend - Rust Part
################################################################################
# Start from base image
FROM base as frontend-rust-analyzer
# Prepare
RUN rustup toolchain install nightly-2022-05-24
RUN rustup component add rust-src --toolchain nightly-2022-05-24-x86_64-unknown-linux-gnu
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# Build
RUN cd crates/rust_analyzer_wasm && wasm-pack build --target web --out-dir ../../packages/ink-editor/pkg
# Start from base image
FROM base as frontend-bindings
# Build
RUN make generate-bindings
# Start from base image
FROM base as frontend-change-json
# Build
RUN make generate-change-json
################################################################################
# Build Frontend - TypeScript Part
################################################################################
# Start from base image
FROM base as frontend-builder
# Install Yarn & NPM dependencies
RUN apt-get --yes update
RUN apt-get --yes upgrade
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION v18.16.1
RUN mkdir -p /usr/local/nvm && apt-get update && echo "y" | apt-get install curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
RUN /bin/bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm use --delete-prefix $NODE_VERSION"
ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION/bin
ENV PATH $NODE_PATH:$PATH
RUN npm install --global yarn
RUN make install
# Copy generated Rust components to Frontend folder
COPY --from=frontend-bindings /app/packages/_generated/commontypes /app/packages/_generated/commontypes
COPY --from=frontend-change-json /app/packages/_generated/change /app/packages/_generated/change
COPY --from=frontend-rust-analyzer /app/packages/ink-editor/pkg /app/packages/ink-editor/pkg
# Set ENV vars
ARG COMPILE_URL=/compile
ARG TESTING_URL=/test
ARG GIST_LOAD_URL=/gist/load
ARG GIST_CREATE_URL=/gist/create
# Build Frontend
RUN make playground-build
################################################################################
# Build Backend
################################################################################
# Start from base image
FROM base as backend-builder
# Build
RUN rustup default stable
RUN make backend-build-prod
################################################################################
# Compose final image
################################################################################
FROM debian:bullseye-slim
COPY --from=frontend-builder /app/packages/playground/dist /app/packages/playground/dist
COPY --from=backend-builder /app/target/release/backend /app/target/release/backend
COPY ./scripts /app/scripts
COPY ./config/versions.json /app/config/versions.json
# Install Docker
# see: https://www.how2shout.com/linux/install-docker-ce-on-debian-11-bullseye-linux/
RUN apt-get update && apt-get install --yes \
apt-transport-https ca-certificates curl gnupg lsb-release
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | \
gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
RUN echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | \
tee /etc/apt/sources.list.d/docker.list >/dev/null
RUN apt-get --yes update
RUN apt-get --yes install docker-ce docker-ce-cli \
containerd.io jq
# Provide startup scripts
COPY sysbox/on-start.sh /usr/bin
RUN chmod +x /usr/bin/on-start.sh
# Entrypoint
ENTRYPOINT [ "on-start.sh" ]