forked from oppia/oppia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubuntu_dockerfile
232 lines (217 loc) · 8.24 KB
/
ubuntu_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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# Copyright 2019 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##########################################################################
# INSTRUCTIONS:
#
# This Dockerfile allows for an easy installation of Oppia for Windows
# users and a more reliable testing environment for running test scripts.
#
# Current known limitations:
# - no support for run_e2e_tests.sh
# - run_frontend_tests.py might not run correctly every time
#
# For more detailed instructions, go to the Windows page on here:
# https://github.com/oppia/oppia/wiki/Installing-Oppia
#
##########################################################################
###################### TO SET UP THE OPPIA REPOSITORY ####################
##########################################################################
#
########## START DOCKER
#
# STEP 1
# Download Docker Desktop for Windows here:
# https://hub.docker.com/editions/community/docker-ce-desktop-windows
#
# STEP 2
# Start Docker by clicking on the Docker application (a Docker icon should
# appear in your taskbar tray).
#
########## BUILD THE DOCKER IMAGE
#
# STEP 3
# Build the Docker image from the Oppia root folder (note the "." at the
# end of the command):
#
# docker build -t {image_name} -f ubuntu_dockerfile .
# where you should replace {image_name} with whatever you want to call
# your Docker image (say oppia_image).
#
# Expect up to a 2 minute delay until the first line of output is printed.
# Runtime: 15-25 minutes
#
# If this is not your first time running this command, add --no-cache flag
# to rebuild from the beginning:
# docker build -t {image_name} -f ubuntu_dockerfile . --no-cache
#
########## BUILD A DOCKER CONTAINER BASED ON IMAGE
#
# STEP 4
# Create a Docker container using the Docker image:
#
# docker run -u 0 -it -p 8181:8181 --name {container_name} {image_name}:latest bash
# where you should replace {container_name} with whatever you want to
# call your Docker container (say oppia_container) and {image_name}
# with the name of your Docker image.
#
# STEP 5
# At this point, a container is built with your current oppia directory.
# Now you should have a new terminal prompt "root@...". This is a Linux
# terminal. Type “exit” to return to your Command Prompt.
#
##########################################################################
######################## TO START THE OPPIA SERVER #######################
##########################################################################
#
########## ENSURE CONTAINER IS RUNNING
#
# STEP 1
# Run:
#
# docker ps
#
# If this outputs a container, move on to step 3.
# Note: the {container_name} in the following steps can be found under the
# “NAMES” column of the output of “docker ps”.
#
# If this does not output a container, move on to step 2.
#
# STEP 2
# Run:
#
# docker ps -a
#
# If this outputs names of containers, find the NAME of the most recent
# container and run:
# docker start {container_name}
#
# If this does not output names of containers, run:
# docker images
# to get the name of a previously built image and follow step 4 from the
# prerequisite instructions.
#
# Then return to step 1 to ensure that the container is running.
#
########## UPDATE THE FILES IN THE CONTAINER WITH YOUR LOCAL REPO
#
# STEP 3
# Update the container to have your most recent code. Skip this step if
# you have not made any changes to your local repo.
# Note: Please keep in mind the direction of the slashes ( ‘/’ vs ‘\’).
#
# If you remember what files/directories you have edited, run:
# docker cp {path\to\src} {container_name}:/home/oppia/{path/to/dest}
# where {path\to\src} can be the relative path to a file or folder
# and {path/to/dest} is the path within the /home/oppia directory
# in the container.
# ex: docker cp .\core\domain\. oppia_container:/home/oppia/core/domain/
#
# If you do not remember what files you have edited, run:
# docker cp .\. {container_name}:/home/oppia/
# in the oppia root directory to copy over the entire oppia/ directory
# into the container.
# Note: This will take ~10 minutes to copy over all of the files.
#
########## START BASH AND RUN THE START SCRIPT
#
# STEP 4
# Start bash in the updated Docker container:
#
# docker exec -it {container_name} bash
#
# STEP 5
# Now you should have a new terminal prompt "root@...". Run the start.sh
# script:
#
# python -m scripts.start
#
# Runtime: 10-20 minutes
# The script opens a server at localhost:8181. After the terminal prints
# "INFO ... http://0.0.0.0:8181" or "+ 27 hidden modules", open
# localhost:8181 in your local computer browser. If the Oppia server does
# not load, restart this step.
#
##########################################################################
########################## TO RUN FRONTEND TESTS #########################
##########################################################################
#
# STEP 1
# Start bash in the Docker image (follow steps 1-4 above).
#
# STEP 2
# Run the run_frontend_tests.py script:
#
# python -m scripts.run_frontend_tests
#
# Runtime: 3-7 minutes
# If this outputs an error ("failed before timeout of 2000ms"), continue
# to STEP 3.
# If this runs correctly (displays "SUCCESS"), do not go onto STEP 3.
#
# STEP 3
# Compile the frontend tests and then run the tests:
#
# ./node_modules/typescript/bin/tsc --project .
# ./node_modules/karma/bin/karma start ./core/tests/karma.conf.ts
#
# If this outputs an error, try STEP 2 again.
# If this runs correctly, you will see a SIGKILL at the end. That is okay.
##########################################################################
FROM ubuntu:latest
# Install packages needed in Dockerfile
RUN apt-get update && \
apt-get install -y sudo && \
apt-get install -y vim && \
apt-get install -y wget && \
apt-get install -y nodejs && \
apt-get install -y npm && \
apt-get install -y yes && \
apt-get clean
# Create oppia directory in Docker container
RUN mkdir /home/oppia
# Install prerequisites. The yes package responds "yes" to all prompts.
COPY ./scripts/install_prerequisites.sh /home/oppia/scripts/
RUN yes | bash /home/oppia/scripts/install_prerequisites.sh
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f
# Setup JAVA_HOME
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
ENV PATH $PATH:$JAVA_HOME/bin
RUN export JAVA_HOME
# Install dumb-init (Signal handling of SIGINT/SIGTERM/SIGKILL and all other unhandled signals)
# When a process is executed in a Docker container, it is given a PID of 1. Linux kernels give
# special permissions to the process with a PID of 1. In particular, if the process does not handle
# a specific signal, then it will not respond to that signal. Unhandled signals for processes of
# PID other than 1 are set to the default response for the signal. So, we install dumb-init as a
# reliable process for the Linux kernel to give special permissions to. dumb-init then executes all
# other processes as child processes (PID other than 1), such that their unhandled signals are
# automatically handled as expected.
RUN wget https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb
RUN dpkg -i dumb-init_*.deb
ENTRYPOINT ["dumb-init"]
# Install packages needed for Google Chrome
RUN apt-get update && \
apt-get install -y fonts-liberation libappindicator3-1 libgtk-3-0 libxss1 lsb-release xdg-utils
# Install Google Chrome for frontend tests
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN sudo dpkg -i google-chrome-stable_current_amd64.deb
# Copy oppia files into container
COPY . /home/oppia/
# Allow docker to have sudo privileges
RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo
USER docker
WORKDIR /home/oppia/