Skip to content

Commit

Permalink
Initial app packaging (#12, #14, #15)
Browse files Browse the repository at this point in the history
* Initial app packaging (WIP)

* Image rename

* Toolchain is Gnu

* Use alternative capabilities: configuration schema

* Install Rust in setup.ps1

* Install step rather than init step

* Fix path

* Fix name of gelfAddress setting

* Output verbose logs from cargo build

* Continue on errors so that cargo output is visible

* Redirect cargo's STDERR

* Write events to STDERR as valid CLEF

* Very simple pygelf example

* Use grayscale Seq logo for package icon

* Publish to NuGet
  • Loading branch information
nblumhardt committed Jan 22, 2019
1 parent b7e663b commit 66d4dcc
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 14 deletions.
45 changes: 45 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Seq.Input.Gelf.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Seq.Input.Gelf</id>
<version>$version$</version>
<authors>Datalust and Contributors</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Receive GELF event payloads via UDP.</description>
<language>en-US</language>
<projectUrl>https://github.com/datalust/sqelf</projectUrl>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
<iconUrl>https://raw.githubusercontent.com/datalust/sqelf/master/asset/seq-input-gelf.png</iconUrl>
<tags>seq-app</tags>
</metadata>
<files>
<file src="seq-input-gelf.d.json" target="" />
<file src="target\x86_64-pc-windows-msvc\release\sqelf.exe" target="win-x64" />
<file src="target\x86_64-unknown-linux-gnu\release\sqelf" target="linux-x64\sqelf" />
</files>
</package>
13 changes: 13 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ environment:
init:
- git config --global core.longpaths true

install:
- ps: ./ci/setup.ps1
- ps: $env:Path = "C:\Users\appveyor\.cargo\bin;$env:Path"

build_script:
- ps: ./ci/build.ps1 -shortver "$($env:APPVEYOR_BUILD_VERSION)"

artifacts:
- path: publish\*

deploy:
- provider: NuGet
api_key:
secure: ksmDWNHXO2Sh0FDXjJ+vj2a6ICn1bc2XQuA3hQ1N26Sel6kOwP/W8Z9u0y6JNQbg
skip_symbols: true
artifact: /Seq.Input.Gelf.*\.nupkg/
on:
branch: /^(master|dev|release/.*)$/
Binary file added asset/seq-input-gelf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions asset/seq-input-gelf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 38 additions & 10 deletions ci/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function Write-BeginStep($invocation)
Write-Output "###########################################################"
Write-Output ""
}

function Initialize-Docker
{
Write-BeginStep $MYINVOCATION
Expand All @@ -29,10 +28,16 @@ function Initialize-Docker
}
}

function Initialize-HostShare
function Initialize-Filesystem
{
Write-BeginStep $MYINVOCATION

if (Test-Path .\publish) {
Remove-Item .\publish -Recurse
}

mkdir .\publish

if ($IsCIBuild)
{
$hostShare = "X:\host"
Expand All @@ -47,7 +52,7 @@ function Initialize-HostShare
}
}

function Invoke-NativeBuild
function Invoke-LinuxBuild
{
Write-BeginStep $MYINVOCATION

Expand All @@ -65,16 +70,39 @@ function Invoke-NativeBuild
}
}

function Build-Container
function Invoke-DockerBuild
{
Write-BeginStep $MYINVOCATION

& docker build --file dockerfiles/Dockerfile -t sqelf-ci:latest .
if ($LASTEXITCODE) { exit 1 }
}

function Invoke-WindowsBuild
{
Write-BeginStep $MYINVOCATION

# Cargo writes to STDERR
$ErrorActionPreference = "SilentlyContinue"

cargo build --release --target=x86_64-pc-windows-msvc
if ($LASTEXITCODE) { exit 1 }

$ErrorActionPreference = "Stop"
}

function Invoke-NuGetPack($version)
{
Write-BeginStep $MYINVOCATION

& .\tool\nuget.exe pack .\Seq.Input.Gelf.nuspec -version $version -outputdirectory .\publish
if ($LASTEXITCODE) { exit 1 }
}

function Publish-Container($version)
{
Write-BeginStep $MYINVOCATION

& docker tag sqelf-ci:latest datalust/sqelf-ci:$version
if ($LASTEXITCODE) { exit 1 }

Expand All @@ -91,15 +119,15 @@ function Publish-Container($version)
$ErrorActionPreference = "Stop"
Push-Location "$PSScriptRoot/../"

$version = "$shortver.0"

Initialize-Docker
Initialize-HostShare
Invoke-NativeBuild
Build-Container
Initialize-Filesystem
Invoke-LinuxBuild
Invoke-DockerBuild
Invoke-WindowsBuild
Invoke-NuGetPack $shortver

if ($IsPublishedBuild) {
Publish-Container $version
Publish-Container $shortver
}
else {
Write-Output "Not publishing Docker container"
Expand Down
9 changes: 9 additions & 0 deletions ci/setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$ErrorActionPreference = "Stop"

$RequiredRustToolchain = "stable"

Invoke-WebRequest -OutFile ./rustup-init.exe -Uri https://win.rustup.rs
$ErrorActionPreference = "Continue"
& ./rustup-init.exe --default-host x86_64-pc-windows-msvc --default-toolchain $RequiredRustToolchain -y
if ($LASTEXITCODE) { exit 1 }
$ErrorActionPreference = "Stop"
11 changes: 11 additions & 0 deletions examples/pygelf-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Example logging with https://github.com/keeprocking/pygelf
# First, `pip install pygelf`

from pygelf import GelfUdpHandler
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
logger.addHandler(GelfUdpHandler(host='127.0.0.1', port=12201))

logger.info('Hello, Seq+GELF!')
22 changes: 22 additions & 0 deletions seq-input-gelf.d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://getseq.net/schema/app-definition/v3",
"name": "GELF Input",
"description": "Accept Graylog Extended Log Format (GELF) payloads over UDP. Requires Seq 5.1+ for optimal performance.",
"capabilities": ["input"],
"platform": {
"win-x64": {
"executable": "win-x64\\sqelf.exe"
},
"linux-x64": {
"executable": "linux-x64/sqelf"
}
},
"settings": {
"gelfAddress": {
"displayName": "GELF address",
"helpText": "The socket address (IP address and port) on which the input will listen for UDP GELF payloads. The default is `0.0.0.0:12201`.",
"isOptional": true
}
}
}

4 changes: 4 additions & 0 deletions sqelf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ version = "1"

[dependencies.failure]
version = "0.1"

[dependencies.chrono]
version = "0.4"
features = ["serde"]
35 changes: 35 additions & 0 deletions sqelf/src/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use chrono::{DateTime, Utc};
use std::fmt::Display;

#[derive(Serialize)]
struct DiagnosticEvent<'a> {
#[serde(rename="@t")]
timestamp: DateTime<Utc>,

#[serde(rename="@l")]
level: &'static str,

#[serde(rename="@mt")]
message_template: &'static str,

#[serde(rename="@x")]
error: Option<&'a str>,
}

impl<'a> DiagnosticEvent<'a> {
pub fn new(level: &'static str, error: Option<&'a str>, message_template: &'static str) -> DiagnosticEvent<'a> {
DiagnosticEvent {
timestamp: Utc::now(),
message_template,
level,
error,
}
}
}

pub fn emit_err(error: &impl Display, message_template: &'static str) {
let err_str = format!("{}", error);
let evt = DiagnosticEvent::new("ERROR", Some(&err_str), &message_template);
let json = serde_json::to_string(&evt).expect("infallible JSON");
eprintln!("{}", json);
}
2 changes: 1 addition & 1 deletion sqelf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod io;
pub mod process;
pub mod receive;
pub mod server;
mod diagnostics;

use std::error;

Expand All @@ -24,7 +25,6 @@ impl Config {

fn main() -> Result<(), Box<error::Error>> {
let config = Config::get();
eprintln!("{:#?}", config);

// The receiver for GELF messages
let receive = {
Expand Down
Loading

0 comments on commit 66d4dcc

Please sign in to comment.