<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rich Boniface</title>
    <description>The latest articles on DEV Community by Rich Boniface (@sql_knievel).</description>
    <link>https://dev.to/sql_knievel</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F78838%2Fa4c4a87a-dd8c-4be1-bc8e-c14abb50cf6f.jpg</url>
      <title>DEV Community: Rich Boniface</title>
      <link>https://dev.to/sql_knievel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sql_knievel"/>
    <language>en</language>
    <item>
      <title>How to skip a pytest test when running in Github Actions</title>
      <dc:creator>Rich Boniface</dc:creator>
      <pubDate>Thu, 16 Feb 2023 21:45:14 +0000</pubDate>
      <link>https://dev.to/sql_knievel/how-to-skip-a-pytest-test-when-running-in-github-actions-1m2o</link>
      <guid>https://dev.to/sql_knievel/how-to-skip-a-pytest-test-when-running-in-github-actions-1m2o</guid>
      <description>&lt;p&gt;You're automatically running your project's pytest suite in Github Actions?  That's great!  But what if there's a test in your code that will NEVER work when it runs in Github Actions?  Maybe it depends on some local resource that you have during development.  Maybe it's a long running test that you don't want to chew up Github Actions time with.  Whatever.  You have your reasons.  The point is this: You want to skip this particular test only when the test suite runs in Github Actions.&lt;/p&gt;

&lt;p&gt;NO PROBLEM.&lt;/p&gt;

&lt;p&gt;Github Actions has a boatload of &lt;a href="https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables" rel="noopener noreferrer"&gt;default environment variables&lt;/a&gt; that we can use to check and see if we're running in Github.  Here's one that looks perfect for this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;GITHUB_ACTIONS&lt;/code&gt;  - Always set to "true" when GitHub Actions is running the workflow. You can use this variable to differentiate when tests are being run locally or by GitHub Actions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So we just check that variable and use the handy &lt;a href="https://docs.pytest.org/en/7.1.x/how-to/skipping.html#id1" rel="noopener noreferrer"&gt;@pytest.mark.skipif()&lt;/a&gt; decorator, and here's how we might skip a problematic test in Github Actions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# test_example.py

import os
import pytest

IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true"

@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.")
def test_example():
   # This passes locally, but not in Github Actions
   assert os.getenv('GITHUB_URL') is None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there you have it!  It will run with your local tests, but not on Github Actions, and you don't have to think about it again.&lt;/p&gt;

</description>
      <category>python</category>
      <category>pytest</category>
      <category>github</category>
      <category>githubactions</category>
    </item>
    <item>
      <title>Trying out Splunk in a Docker Container</title>
      <dc:creator>Rich Boniface</dc:creator>
      <pubDate>Sat, 09 Nov 2019 21:34:08 +0000</pubDate>
      <link>https://dev.to/sql_knievel/trying-out-splunk-in-a-docker-container-1771</link>
      <guid>https://dev.to/sql_knievel/trying-out-splunk-in-a-docker-container-1771</guid>
      <description>&lt;h1&gt;
  
  
  Intro
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.splunk.com/"&gt;Splunk&lt;/a&gt; is a nifty system that lets you ingest and parse basically any kind of event-based data and then query it to find trends, alerts, and whatever kind of info you want.  Lots of companies use it to sift through log data to dig out useful information.  Once you learn about it a bit, it's actually much cooler than it sounds at first, and surprisingly versatile.  You can use it to crunch lots of different kinds of data.&lt;/p&gt;

&lt;p&gt;My company has a big Splunk installation, and my boss wanted me to make use of it in a project.  But I'd never used Splunk before so I looked around for some tutorials.  Now, most of the Splunk tutorials you come across either assume you already have a Splunk installation to play on or encourage you to install the Splunk software that Splunk makes available on their website (after you create an account, etc)  I certainly didn't want to go through tutorial exercises on work's production system, and I also didn't feel like installing software on my development machine.  Enter Docker.&lt;/p&gt;

&lt;p&gt;One of the great things about Docker is that it's an easy way to try out software without actually installing anything on your system - let's face it, installing software just for testing is messy at best and dangerous at worst.  Fortunately, Splunk makes a version of Splunk Enterprise available on Docker Hub.  I got it working great for me, but it took a few little tweaks to get it rolling.&lt;/p&gt;

&lt;h1&gt;
  
  
  Fire it Up
&lt;/h1&gt;

&lt;p&gt;I'm going to assume that you know the basics of Docker and that you have it installed on your system.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;a href="https://hub.docker.com/"&gt;Docker Hub&lt;/a&gt; and log into your account.&lt;/li&gt;
&lt;li&gt;Find your way to the page for &lt;a href="https://hub.docker.com/_/splunk-enterprise"&gt;Splunk Enterprise&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;On the right side of the page, you'll see that you have to "buy" the free plan for $0.00.  Go to checkout and go through the motions.  You don't need a credit card or anything - it's free.  Of course, this is just a "trial" version - it starts as a fully-featured Splunk Enterprise, and after a period of time it becomes "Splunk Free" limiting you to 500MB/day.  Still plenty of time to run through a few tutorials.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open a command line.  We need to make sure we're accessing Docker Hub with the credentials we just used to register for the Splunk image and run:&lt;br&gt;&lt;br&gt;
&lt;code&gt;docker login&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Let's download the Splunk image:&lt;br&gt;&lt;br&gt;
&lt;code&gt;docker pull store/splunk/splunk:7.3&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now we can fire up the container.  Three notes: &lt;br&gt;
a. I have picked a silly password, but it conforms to Splunk's password requirements. If you pick your own, that's fine, but if you don't conform to their requirements, the container will automatically shut itself down.&lt;br&gt;
b. In addition to the main interface port of 8000, I've also opened the port 8088 which is used for &lt;a href="https://docs.splunk.com/Documentation/Splunk/7.3.2/Data/UsetheHTTPEventCollector"&gt;HTTP Event Collection&lt;/a&gt; in case you want to play with sending events to Splunk via POST requests.  (I did.)&lt;br&gt;
c. The "start" at the end of the command is necessary. The sample command in their page on Docker Hub doesn't show it.&lt;br&gt;&lt;br&gt;
&lt;code&gt;docker run -d -p 8000:8000 -p 8088:8088 -e SPLUNK_START_ARGS=--accept-license -e SPLUNK_PASSWORD=123ABCdef! store/splunk/splunk:7.3 start&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once we run the container, it spits out a big long hex identifier that is the container ID.  If you check on the container a few times by running &lt;code&gt;docker container ls&lt;/code&gt; it should go from status "starting" to "healthy" within a half minute or so.  Once it's healthy, we can try connecting to it by going to &lt;a href="http://localhost:8000/"&gt;http://localhost:8000/&lt;/a&gt; and using the username &lt;strong&gt;admin&lt;/strong&gt; and and the password you passed as the "SPLUNK_PASSWORD" above, in my example &lt;strong&gt;123ABCdef!&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now you should be logged into your local Splunk instance and able to do whatever you want.  &lt;strong&gt;BE AWARE THAT THIS INSTANCE IS COMPLETELY EPHEMERAL&lt;/strong&gt; which is to say there is no permanent storage outside of this container - if you load data into it, play around with it, shut it down and drop the container, your data and reports will be &lt;strong&gt;GONE&lt;/strong&gt;.  This is strictly for playing around with Splunk and NOT for doing any kind of REAL deployment.  That is well beyond the scope of what we're doing here.  We just want a Splunk instance to mess with and then throw away.&lt;/p&gt;

&lt;p&gt;At this point you could just go ahead and jump into &lt;a href="https://docs.splunk.com/Documentation/Splunk/7.3.2/SearchTutorial/NavigatingSplunk"&gt;Splunk's Official Tutorial&lt;/a&gt; - just remember when you're following the tutorial you're running "Splunk Enterprise" here and not "Splunk Cloud".  They'll give you some &lt;a href="https://docs.splunk.com/Documentation/Splunk/7.3.2/SearchTutorial/GetthetutorialdataintoSplunk"&gt;sample data to upload&lt;/a&gt; and off you go!&lt;/p&gt;

&lt;h1&gt;
  
  
  Shut it Down
&lt;/h1&gt;

&lt;p&gt;When you're all done and want to get rid of it, you can do &lt;code&gt;docker container ls&lt;/code&gt; to remind yourself of the Container ID.  Then stop it with &lt;code&gt;docker container stop &amp;lt;containerid&amp;gt;&lt;/code&gt; and then finally remove the container with &lt;code&gt;docker container rm &amp;lt;containerid&amp;gt;&lt;/code&gt;&lt;/p&gt;

</description>
      <category>splunk</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
