<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Docker</title><link>https://jwheel.org/tags/docker/</link><description>Homepage of Justin Wheeler, an Open Source contributor and Free Software advocate from Georgia, USA.</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><managingEditor>Justin Wheeler</managingEditor><lastBuildDate>Sat, 21 Oct 2017 00:00:00 +0000</lastBuildDate><atom:link href="https://jwheel.org/rss/tags/docker/index.xml" rel="self" type="application/rss+xml"/><item><title>Exploring Google Code-In, ListenBrainz easyfix bugs, D3.js</title><link>https://jwheel.org/blog/2017/10/google-code-in-listenbrainz-d3-js/</link><pubDate>Sat, 21 Oct 2017 00:00:00 +0000</pubDate><guid>https://jwheel.org/blog/2017/10/google-code-in-listenbrainz-d3-js/</guid><description><![CDATA[<p><em>This post is part of a series of posts where I contribute to the ListenBrainz project for my independent study at the Rochester Institute of Technology in the fall 2017 semester. For more posts, find them in <a href="/tags/rit-2171/">this tag</a>.</em></p>
<hr>
<p>Last week moved quickly for me in ListenBrainz. I submitted multiple pull requests and participated in the weekly developer&rsquo;s meeting on Monday. I was also invited to take part as a mentor for ListenBrainz for the upcoming round of Google Code-In! In addition to my changes and new role as a mentor, I&rsquo;m researching libraries like D3.js to help build visualizations for music data.  Suddenly, everything started moving fast!</p>

<h2 id="last-week-recap">Last week: Recap&nbsp;<a class="hanchor" href="#last-week-recap" aria-label="Anchor link for: Last week: Recap">🔗</a></h2>
<p>The ListenBrainz team accepted my <a href="https://github.com/metabrainz/listenbrainz-server/pull/257">development environment improvements</a> and <a href="https://github.com/metabrainz/listenbrainz-server/pull/259">documentation</a>. This gave me an opportunity to better explore project documentation tools. I experimented with <a href="http://www.sphinx-doc.org/en/stable/">Sphinx</a> and <a href="https://readthedocs.org/">Read the Docs</a>. Sphinx introduced me to <a href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> for documentation formats. I&rsquo;ve avoided it in favor of Markdown for a long time, but I see where reStructuredText is stronger for advanced documentation.</p>
<p>Since ListenBrainz is a new project, I plan to contribute documentation for any of my work and improve documentation for pre-existing work. One of the goals for this independent study is to make ListenBrainz a viable candidate for a future data analysis course. To make it easy to use and understand, ListenBrainz needs excellent documentation. Since one of my strengths is technical writing, I plan to contribute more documentation this semester.</p>
<p>You can see some of the <a href="https://listenbrainz.readthedocs.io/en/master/">new documentation</a> already!</p>

<h2 id="google-code-in-mentor">Google Code-In mentor&nbsp;<a class="hanchor" href="#google-code-in-mentor" aria-label="Anchor link for: Google Code-In mentor">🔗</a></h2>
<p>The MetaBrainz community manager, <a href="https://musicbrainz.org/user/Freso">Freso Olesen</a>, approached me to mentor for Google Code-In. <a href="https://codein.withgoogle.com/">Google Code-In</a> is an opportunity for teenagers to meaningfully contribute to open source projects. Google describes Google Code-In as…</p>
<blockquote>
<p>Pre-university students ages 13 to 17 are invited to take part in Google Code-in: Our global, online contest introducing teenagers to the world of open source development. With a wide variety of bite-sized tasks, it’s easy for beginners to jump in and get started no matter what skills they have.</p>
<p>Mentors from our participating organizations lend a helping hand as participants learn what it’s like to work on an open source project. Participants get to work on real software and win prizes from t-shirts to a trip to Google HQ!</p>
</blockquote>
<p>MetaBrainz is a participating organization of Google Code-In this cycle. Because of my work with ListenBrainz, I will contribute a few hours a week to help mentor participating students with ListenBrainz. Beginner problems should be easy to help with since I&rsquo;m still beginning too, and as I spend more time with ListenBrainz, I can help with harder problems.</p>
<p>I&rsquo;m excited to give back to one of my favorite open source projects in this way! I&rsquo;m grateful to have this chance to help out during Google Code-In.</p>

<h2 id="choosing-easyfix-bugs">Choosing easyfix bugs&nbsp;<a class="hanchor" href="#choosing-easyfix-bugs" aria-label="Anchor link for: Choosing easyfix bugs">🔗</a></h2>
<p>After I figured out the development environment issues, I went through <a href="https://tickets.metabrainz.org/projects/LB/issues/">open tickets</a> filed against ListenBrainz to find some to work on. I made a preliminary pass through all open tickets and left some comments for more information, when needed. The tickets I highlighted to look into next were</p>
<ul>
<li><a href="https://tickets.metabrainz.org/browse/LB-85"><strong>LB-85</strong></a>: Username in the profile URL should be case insensitive</li>
<li><a href="https://tickets.metabrainz.org/browse/LB-124"><strong>LB-124</strong></a>: Install messybrainz as a a python library from requirements</li>
<li><a href="https://tickets.metabrainz.org/browse/LB-176"><strong>LB-176</strong></a>: Add stats module and begin calculating some user stats from BigQuery</li>
<li><strong><a href="https://tickets.metabrainz.org/browse/LB-206">LB-206</a></strong>: &ldquo;playing_now&rdquo; submissions not showing on profile</li>
<li><a href="https://tickets.metabrainz.org/browse/LB-212"><strong>LB-212</strong></a>: Show the MetaBrainz logo on the listenbrainz footer.</li>
</ul>
<p>Of these five, LB-124 and LB-212 are already closed. While drafting this article, I completed LB-124 in <a href="https://github.com/metabrainz/listenbrainz-server/pull/266">PR #266</a>. This was part of a test to get the documentation building again because of odd import errors. Later, a new student also learning the project for the first time asked to work on LB-212. Since it was a good first task to explore the project code, I passed the ticket to him.</p>
<p>I want to do one more &ldquo;easyfix&rdquo; bug before going into the main part of my independent study timeline. I don&rsquo;t yet feel comfortable with the code and one more bug solved will help. After this, I plan to pursue the heavier lifting of the independent study to explore data operations and queries to make.</p>

<h2 id="researching-d3js">Researching D3.js&nbsp;<a class="hanchor" href="#researching-d3js" aria-label="Anchor link for: Researching D3.js">🔗</a></h2>
<p>Prof. Roberts introduced <a href="https://d3js.org/">D3.js</a> as a library to build interactive, dynamic charts and visual representations of data. I haven&rsquo;t yet looked into much front-end work, but this was a cool project that I wanted to highlight in my weekly report. This feels like it could be a powerful match for ListenBrainz, especially since the data has high detail.</p>

<h2 id="upcoming-activity">Upcoming activity&nbsp;<a class="hanchor" href="#upcoming-activity" aria-label="Anchor link for: Upcoming activity">🔗</a></h2>
<p>This next week, I won&rsquo;t have as much time to contribute to ListenBrainz. On October 21, I&rsquo;m traveling to Raleigh, NC for <a href="https://allthingsopen.org/">All Things Open</a>. On October 24, I <a href="https://allthingsopen.org/speakers/justin-w-flory/">present my talk</a>, &ldquo;<em>What open source and J.K. Rowling have in common</em>&rdquo;. Since I&rsquo;ll be out of Rochester and missing other classwork, I expect less time on my ListenBrainz work.</p>
<p>This next week will be slower than the last two weeks. Hopefully I&rsquo;ll learn something at the conference too to bring back for ListenBrainz.</p>
<p>Until then… keep the FOSS flag high.</p>]]></description></item><item><title>How to set up a ListenBrainz development environment</title><link>https://jwheel.org/blog/2017/10/listenbrainz-development-environment/</link><pubDate>Wed, 04 Oct 2017 00:00:00 +0000</pubDate><guid>https://jwheel.org/blog/2017/10/listenbrainz-development-environment/</guid><description><![CDATA[<p><em>This post is part of a series of posts where I contribute to the ListenBrainz project for my independent study at the Rochester Institute of Technology in the fall 2017 semester. For more posts, find them in <a href="/tags/rit-2171/">this tag</a>.</em></p>
<hr>
<p>One of the first rites of passage when working on a new project is creating your development environment. It always seems simple, but sometimes there are bumps along the way. The first activity I did to begin contributing to ListenBrainz was create my development environment. I wasn&rsquo;t successful with the documentation in the README, so I had to play around and work with the project before I was even running it.</p>
<p>The first part of this post details how to set up your own development environment. Then, the second half talks about the solution I came up with and my first contribution back to the project.</p>

<h2 id="install-dependencies-docker">Install dependencies: Docker&nbsp;<a class="hanchor" href="#install-dependencies-docker" aria-label="Anchor link for: Install dependencies: Docker">🔗</a></h2>
<p>This tutorial assumes you are using a Linux distribution. If you&rsquo;re using a different operating system, install the necessary dependencies or packages with your preferred method.</p>
<p>ListenBrainz ships in Docker containers, which helps create your development environment and later deploy the application. Therefore, to work on the project, you need to install Docker and use containers for building the project. Containers save you from installing all of this on your own workstation! Since I&rsquo;m using Fedora, I run this command.</p>
<pre tabindex="0"><code>sudo dnf install docker docker-compose
</code></pre>
<h2 id="register-a-musicbrainz-application">Register a MusicBrainz application&nbsp;<a class="hanchor" href="#register-a-musicbrainz-application" aria-label="Anchor link for: Register a MusicBrainz application">🔗</a></h2>
<p>Next, you need to register your application and get a OAuth token from MusicBrainz. Using the OAuth token lets you sign into your development environment with your MusicBrainz account. Then, you can import your plays from somewhere else.</p>
<p>To register, visit the <a href="https://musicbrainz.org/account/applications">MusicBrainz applications page</a>. There, look for the option to <a href="https://musicbrainz.org/account/applications/register">register your application</a>. Fill out the form with these three options.</p>
<ul>
<li><strong>Name</strong>: (any name you want and will recognize, I used <code>listenbrainz-server-devel</code>)</li>
<li><strong>Type</strong>: <code>Web Application</code></li>
<li><strong>Callback URL</strong>: <code>http://localhost/login/musicbrainz/post</code></li>
</ul>
<p>After entering this information, you&rsquo;ll have a OAuth client ID and OAuth client secret. You&rsquo;ll use these for configuring ListenBrainz.</p>

<h4 id="update-configpy">Update config.py&nbsp;<a class="hanchor" href="#update-configpy" aria-label="Anchor link for: Update config.py">🔗</a></h4>
<p>With your new client ID and secret, update the ListenBrainz configuration file. If this is your first time configuring ListenBrainz, copy the sample to a live configuration.</p>
<pre tabindex="0"><code>cp listenbrainz/config.py.sample listenbrainz/config.py
</code></pre><p>Next, open the file with your favorite text editor and look for this section.</p>
<pre tabindex="0"><code># MusicBrainz OAuth
MUSICBRAINZ_CLIENT_ID = &#34;CLIENT_ID&#34;
MUSICBRAINZ_CLIENT_SECRET = &#34;CLIENT_SECRET&#34;
</code></pre><p>Update the strings with your client ID and secret. After doing this, your ListenBrainz development environment is able to authenticate and log in from your MusicBrainz login.</p>

<h2 id="initialize-listenbrainz-databases">Initialize ListenBrainz databases&nbsp;<a class="hanchor" href="#initialize-listenbrainz-databases" aria-label="Anchor link for: Initialize ListenBrainz databases">🔗</a></h2>
<p>Your development environment needs some databases present to work. Before proceeding, run these three commands to initialize the databases.</p>
<pre tabindex="0"><code>docker-compose -f docker/docker-compose.yml -p listenbrainz run --rm web python3 manage.py init_db --create-db
docker-compose -f docker/docker-compose.yml -p listenbrainz run --rm web python3 manage.py init_msb_db --create-db
docker-compose -f docker/docker-compose.yml -p listenbrainz run --rm web python3 manage.py init_influx
</code></pre><p>Your development environment is now ready. Now, let&rsquo;s actually see ListenBrainz load locally!</p>

<h2 id="run-the-magic-script">Run the magic script&nbsp;<a class="hanchor" href="#run-the-magic-script" aria-label="Anchor link for: Run the magic script">🔗</a></h2>
<p>Once you have done this, run the <code>develop.sh</code> script in the root of the repository. Using <code>docker-compose</code>, the script creates multiple Docker containers for the different services and parts of the ListenBrainz server. Running this script will start Redis, PostgreSQL, InfluxDB, and web server containers, to name a few. But this also makes it easy to stop them all later.</p>
<pre tabindex="0"><code>./develop.sh
</code></pre><p>You will see the containers build and eventually run. Leave the script running to see your development environment. Later, you can shut it down by pressing <code>CTRL^C</code>. Once everything is running, visit your new site from your browser!</p>
<p><a href="http://localhost/">http://localhost/</a></p>
<p>Now, you are all set to begin making changes and testing them in your development environment!</p>

<h2 id="making-my-first-pull-request">Making my first pull request&nbsp;<a class="hanchor" href="#making-my-first-pull-request" aria-label="Anchor link for: Making my first pull request">🔗</a></h2>
<p>As mentioned earlier, my first attempt at a development environment was unsuccessful. My system kept denying permission to the processes in the containers. After looking at system audit logs and running a temporary <code>setenforce 0</code>, I tried the script one more time. Everything suddenly worked! So the issue was mostly with SELinux.</p>
<p>With my goal to get my environment set up, I figured out a few issues with the configuration offered by the project developers. I eventually made <a href="https://github.com/metabrainz/listenbrainz-server/pull/257">PR #257</a> against <code>listenbrainz-server</code> with my improvements.</p>

<h4 id="labeling-selinux-volume-mounts">Labeling SELinux volume mounts&nbsp;<a class="hanchor" href="#labeling-selinux-volume-mounts" aria-label="Anchor link for: Labeling SELinux volume mounts">🔗</a></h4>
<p>To diagnose the issue, I started with a quick search and found a <a href="https://stackoverflow.com/questions/24288616/permission-denied-on-accessing-host-directory-in-docker">StackOverflow question</a> with my same problem. There, the question was about Docker containers and denied permissions in the container. The answers explained it was an SELinux error and the context for the containers was not set. However, temporarily changing context for a directory didn&rsquo;t seem too effective and doesn&rsquo;t persist across reboots.</p>
<p>Continuing the search, I found an issue filed against <code>docker-compose</code> about the <code>:z</code> and <code>:Z</code> flags for volume mounts. These flags set SELinux context for containers, with the best explanation I found coming from <a href="https://stackoverflow.com/a/35222815/2497452">this StackOverflow answer</a>.</p>
<blockquote>
<p>Two suffixes :z or :Z can be added to the volume mount. These suffixes tell Docker to relabel file objects on the shared volumes. The &lsquo;z&rsquo; option tells Docker that the volume content will be shared between containers. Docker will label the content with a shared content label. Shared volumes labels allow all containers to read/write content. The &lsquo;Z&rsquo; option tells Docker to label the content with a private unshared label.</p>
</blockquote>
<p>Therefore, I added the <code>:z</code> flag to all the volume mounts in the <code>docker-compose.yml</code> file. I submitted a fix upstream for this in <a href="https://github.com/metabrainz/listenbrainz-server/pull/257">listenbrainz-server#257</a>!</p>

<h4 id="correct-the-startup-port">Correct the startup port&nbsp;<a class="hanchor" href="#correct-the-startup-port" aria-label="Anchor link for: Correct the startup port">🔗</a></h4>
<p>In the README, it says the server will start on port 8000, but the <code>docker-compose.yml</code> file actually started the server on port 80. I included a fix for this in <a href="https://github.com/metabrainz/listenbrainz-server/pull/257">my pull request</a> as well.</p>

<h2 id="git-push">git push!&nbsp;<a class="hanchor" href="#git-push" aria-label="Anchor link for: git push!">🔗</a></h2>
<p>This post makes a debugging experience that actually took hours look like it happened in minutes. But after getting over this hurdle, it was awesome to finally see ListenBrainz running locally on my workstation. It was an even better feeling when I could take my improvements and send them back in a pull request to ListenBrainz. Hopefully this will make it easier for others to create their own development environments and start hacking!</p>]]></description></item></channel></rss>