update from sparkleup
This commit is contained in:
parent
62afa5b291
commit
d51eb82a76
|
@ -48,24 +48,19 @@ cd drone
|
|||
<p>Add the following into this new file, changing the highlighted values as required:</p>
|
||||
<div class="codehilite"><pre><span></span><code><span class="nt">version</span><span class="p">:</span><span class="w"> </span><span class="s">"3"</span><span class="w"></span>
|
||||
|
||||
<span class="nt">networks</span><span class="p">:</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">drone</span><span class="p">:</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">external</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">false</span><span class="w"></span>
|
||||
|
||||
<span class="nt">services</span><span class="p">:</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">server</span><span class="p">:</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">drone/drone:2</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">container_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">server</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">environment</span><span class="p">:</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_GITEA_SERVER=https://<^>your_gitea_domain<^></span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_GITEA_CLIENT_ID=<^>gitea_client_ID<^></span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_GITEA_CLIENT_SECRET=<^>gitea_client_secret<^></span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_RPC_SECRET=<^>sammy-says<^></span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_SERVER_HOST=<^>your_drone_domain<^></span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_GITEA_SERVER=https://mscottclary-test.do-community.com</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_GITEA_CLIENT_ID=06e6fcce-4b10-40f3-9672-8190849e6e02</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_GITEA_CLIENT_SECRET=hAihmhcdag9kXvQQdGh2XfIZHzKXIBJAxRJirvAXUIKu</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_RPC_SECRET=sammy-says</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_SERVER_HOST=mscottclary-drone.do-community.com</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_SERVER_PROTO=https</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_TLS_AUTOCERT=true</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">networks</span><span class="p">:</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">drone</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_AGENTS_ENABLED=true</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">volumes</span><span class="p">:</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./drone:/data</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">ports</span><span class="p">:</span><span class="w"></span>
|
||||
|
@ -75,13 +70,11 @@ cd drone
|
|||
<span class="w"> </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">drone/drone-runner-docker:1</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">container_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">runner</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">environment</span><span class="p">:</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_RPC_PROTO=https</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_RPC_HOST=<^>your_drone_domain<^></span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_RPC_SECRET=<^>sammy-says<^></span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_RPC_PROTO=http</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_RPC_HOST=server</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_RPC_SECRET=sammy-says</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_RUNNER_CAPACITY=2</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DRONE_RUNNER_NAME=gitea-runner</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">networks</span><span class="p">:</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">drone</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">volumes</span><span class="p">:</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/var/run/docker.sock:/var/run/docker.sock</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">ports</span><span class="p">:</span><span class="w"></span>
|
||||
|
@ -91,7 +84,6 @@ cd drone
|
|||
<p>Let’s walk through what this file does:</p>
|
||||
<ul>
|
||||
<li><code>version: "3"</code>: this lets Docker Compose know what version of configuration file this is.</li>
|
||||
<li><code>networks</code>: this section declares the networking setup of our collection of containers. In this case a <code>drone</code> network is created, but is not exposed.</li>
|
||||
<li><code>services</code>: for each of the containers that we have, we set up environment variables available to the service, assign volumes for data that’s stored on the host, and expose various ports. Here are our services:<ul>
|
||||
<li><code>server</code>: this service uses the <code>drone/drone:2</code> image, meaning that it runs the drone server itself. The environment variables passed in provide the service with information such as how to connect to and authorize with Gitea, a secret for the <strong>remote procedure calls</strong> (RPC), and with <code>DRONE_TLS_AUTOCERT</code>, we let the drone server provision a SSL certificate using Let’s Encrypt. The container exposes port 80 for HTTP and port 443 for HTTPS. The local directory <code>drone</code> will be mapped to the container’s <code>/data</code> directory, allowing all of Drone’s information to be stored locally, meaning that it can be backed up and persist across containers.</li>
|
||||
<li><code>runner</code>: this service uses the <code>drone/drone-runner-docker:1</code> image, meaning that it will be in control of provisioning Docker containers for running tests on your code. This runner is what connects to the <code>server</code> container using RPC over port 3000 to start runs and report on the results. Because of this, <code>/var/run/docker.sock</code> is mapped as a volume. This special file is the means by which the runner process can communicate with Docker to start these containers.</li>
|
||||
|
@ -136,10 +128,52 @@ cd drone
|
|||
<$></p>
|
||||
<p>Once you grant permission, you will be returned to your Drone dashboard, where you will see a list of your repositories.</p>
|
||||
<h2 id="step-4-setting-up-a-project-for-cicd">Step 4 — Setting Up a Project for CI/CD</h2>
|
||||
<p>For this tutorial, we will be testing Drone’s continuous integration capabilities for automatically running tests. In order to do so, create a sample repository in Gitea. Clone that repository to your development machine and move into the project directory:</p>
|
||||
<div class="codehilite"><pre><span></span><code>git clone git@<^>your_gitea_domain<^>:sammy/drone-test.git
|
||||
cd drone-test
|
||||
</code></pre></div>
|
||||
|
||||
<p>Create a new file named <code>drone_test.py</code> and enter the following into it:</p>
|
||||
<div class="codehilite"><pre><span></span><code><span class="k">assert</span> <span class="mi">1</span> <span class="o">==</span> <span class="mi">1</span>
|
||||
</code></pre></div>
|
||||
|
||||
<p>Save and exit the file, then add it to your repository and push your changes:</p>
|
||||
<div class="codehilite"><pre><span></span><code>git commit -am "Added test file"
|
||||
git push origin main
|
||||
</code></pre></div>
|
||||
|
||||
<p>Now, return to your Drone dashboard and click on the repository.</p>
|
||||
<p><$>[note]
|
||||
<strong>Note:</strong> If your repository does not appear in the list, you may need to click the <strong>Sync</strong> button in the upper right corner of the dashboard.
|
||||
<$></p>
|
||||
<p>In the settings tab, click <strong>+ Activate Repository</strong>. This will tell Drone that it should be watching for changes from that repository.</p>
|
||||
<p>Now that Drone is active for your test project, you will need to create a <strong>pipeline</strong>. Pipelines describe the steps that Drone should take in order to test your software. These are stored in a file named <code>.drone.yml</code>.</p>
|
||||
<p>In your dev checkout of the project, create a new file named <code>.drone.yml</code> and add the following to it:</p>
|
||||
<div class="codehilite"><pre><span></span><code><span class="nn">---</span><span class="w"></span>
|
||||
<span class="nt">kind</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">pipeline</span><span class="w"></span>
|
||||
<span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">docker</span><span class="w"></span>
|
||||
<span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">default</span><span class="w"></span>
|
||||
|
||||
<span class="nt">steps</span><span class="p">:</span><span class="w"></span>
|
||||
<span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">test</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">python</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nt">commands</span><span class="p">:</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">python drone_test.py</span><span class="w"></span>
|
||||
</code></pre></div>
|
||||
|
||||
<p>Let’s take a look at what this file does. After the header of <code>---</code>, we see that the type of configuration we are working with is a pipeline that runs on Docker containers. It has one step named <code>test</code> using the official <code>python</code> image, and when that container runs and checks out your repository, it will run the command <code>python drone_test.py</code>. Since this file contains a simple assertion that 1 is, indeed, equal to 1, the tests should pass.</p>
|
||||
<p>Save and exit this file, then add it to your repository and push your changes as you did before.</p>
|
||||
<p>Visit your Drone dashboard in the browser once more and click on your active repository. You should see that it has started running your pipeline. If it has not started yet, feel free to click the <strong>+ New Build</strong> button in the upper right corner. When you click on the build, you will be presented with a few of the logs from that build updated in real time as your project is cloned and then your <code>test</code> step run. Since it turns out that 1 does, in fact, equal 1, your tests should pass and you will receive a green check mark.</p>
|
||||
<p>What about 2, though? Check if 1 is equal to 2 by editing <code>drone_test.py</code> and updating the assertion to look like this:</p>
|
||||
<div class="codehilite"><pre><span></span><code><span class="k">assert</span> <span class="mi">1</span> <span class="o">==</span> <span class="mi">2</span>
|
||||
</code></pre></div>
|
||||
|
||||
<p>Commit and push your work as you did before, and then return to your Drone dashboard. Thankfully, 1 does not equal 2, and so our test fails as expected.</p>
|
||||
<p>These results are also visible in Gitea, where you can see whether a particular commit broke the build. Visit your repo in Gitea and click on the <strong>Commits</strong> link above the file listing. You should see all of your commits that went into creating this test project. Before the commit where you checked whether 1 was equal to 2, you should see a red **</p>
|
||||
<h2 id="conclusion">Conclusion</h2>
|
||||
</article>
|
||||
<footer>
|
||||
<p>Page generated on 2022-06-29</p>
|
||||
<p>Page generated on 2022-06-30</p>
|
||||
</footer>
|
||||
</main>
|
||||
<script type="text/javascript">
|
||||
|
|
Loading…
Reference in New Issue