-
Notifications
You must be signed in to change notification settings - Fork 1
/
file.Docker.html
160 lines (114 loc) · 5.75 KB
/
file.Docker.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
File: Using Docker
— Documentation by YARD 0.9.37
</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/common.css" type="text/css" />
<script type="text/javascript">
pathId = "Docker";
relpath = '';
</script>
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
</head>
<body>
<div class="nav_wrap">
<iframe id="nav" src="file_list.html?1"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="_index.html">Index</a> »
<span class="title">File: Using Docker</span>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="class_list.html">
<svg width="24" height="24">
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
</svg>
</a>
</div>
<div class="clear"></div>
</div>
<div id="content"><div id='filecontents'><h1 id="using-docker">Using Docker</h1>
<p>Do you want to help with Rouge development but aren't too keen on needing to
install Ruby and whatever dependencies are required by Rouge?
<a href="https://www.docker.com/">Docker</a> to the rescue!</p>
<p>Docker can be used as a way install Ruby, Rouge and the development dependencies
in a self-contained environment for development. In addition to providing an
alternative for users who don't want to install Ruby, it's also a good choice
for users with an existing installation of Ruby with which they don't want to
interfere.</p>
<h2 id="prerequisites">Prerequisites</h2>
<p>This guide assumes you have Docker and Git installed.</p>
<p>For a guide on installing Docker, we recommend <a href="https://docs.docker.com/get-started/">Docker's official
documentation</a>. For a guide on installing Git, take a look at
<a href="https://help.github.com/en/articles/set-up-git">GitHub's documentation</a>.</p>
<h2 id="installing">Installing</h2>
<h3 id="downloading-rouge">Downloading Rouge</h3>
<p>Clone the project first, and navigate into your clone:</p>
<pre class="code bash"><code class="bash">git clone https://github.com/rouge-ruby/rouge.git
cd rouge
</code></pre>
<h3 id="configuring-the-container">Configuring the Container</h3>
<p>The following line of code sets up Docker with Ruby and Rouge's development
dependencies:</p>
<pre class="code bash"><code class="bash">docker run -t -v $PWD:/app -v /tmp/vendor:/vendor -w /app -e BUNDLE_PATH=/vendor ruby bundle
</code></pre>
<p>Pretty sweet. Let's unpack this:</p>
<ul>
<li><p><code>docker run -it</code>: Runs the command in a new container. <code>-t</code> is not strictly
necessary but allows nice colors in the output.</p></li>
<li><p><code>-v $PWD:app</code>: Maps the current folder into the <code>/app</code> path within the
container. Used in conjunction with <code>-w</code> (see below), this allows the
container to run as if it were inside this directory.</p></li>
<li><p><code>-v /tmp/vendor:/vendor</code>: Maps an arbitrary <code>vendor</code> folder into the <code>/vendor</code>
path within the container. This is to persist the installed dependencies
across Docker commands, otherwise you would have to re-install each time as
containers are ephemeral by nature.</p></li>
<li><p><code>-e BUNDLE_PATH=/vendor</code>: Sets an environment variable inside the container
that tells Bundler to lookup the dependencies from the <code>/vendor</code> path (that
we've mapped to our host machine with the previous line)</p></li>
<li><p><code>ruby</code>: Tells Docker which image to use for the container. The <code>ruby</code> image is
part of the official library of "base" Docker images.</p></li>
<li><p><code>bundle</code>: Runs the <code>bundle</code> command within the container.</p></li>
</ul>
<h2 id="executing-commands">Executing Commands</h2>
<h3 id="running-rake">Running Rake</h3>
<p>Just replace the <code>bundle</code> command with <code>rake</code>:</p>
<pre class="code bash"><code class="bash">docker run -t -v $PWD:/app -v /tmp/vendor:/vendor -w /app -e BUNDLE_PATH=/vendor ruby rake
</code></pre>
<h3 id="running-rack">Running Rack</h3>
<p>Similarly, we can run Rack by replacing <code>bundle</code> with <code>rackup</code>:</p>
<pre class="code bash"><code class="bash">docker run -t -v $PWD:/app -v /tmp/vendor:/vendor -w /app -e BUNDLE_PATH=/vendor -p 9292:9292 ruby bundle exec rackup --host 0.0.0.0
</code></pre>
<p>The additional command line flags are:</p>
<ul>
<li><p><code>-p 9292:9292</code>: Exposes port 9292 of the container to the same port on the
host.</p></li>
<li><p><code>bundle exec rackup --host 0.0.0.0</code>: Runs Rack and asks it to listen on all
addresses. Without this it will only listen on the <code>localhost</code> of the
container and we won't be able to access the server from the host machine.</p></li>
</ul>
<p>You should be able to visit <a href="http://localhost:9292">http://localhost:9292</a> at this point.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Now that you've got Docker set up, perhaps you'd like to work on
a lexer by following our <a href="LexerDevelopment.md">guide</a>.</p>
</div></div>
<div id="footer">
Generated on Fri Sep 20 21:00:09 2024 by
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.37 (ruby-3.3.0).
</div>
</div>
</body>
</html>