Skip to content

Commit

Permalink
Merge pull request #75 from tmknight/dev/0.8.2
Browse files Browse the repository at this point in the history
v0.8.2
  • Loading branch information
tmknight authored Feb 10, 2024
2 parents e2878f6 + 9eb46a0 commit c7e2ccb
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

push-to-registry:
name: "Publish Docker image"
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
needs:
- "get-version"
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/github-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ jobs:
ref: refs/tags/${{ needs.get-version.outputs.pkg-version }}
token: ${{ secrets.GITHUB_TOKEN }}

promote-release:
name: "Promote release"
publish-release:
name: "Publish release"
if: ${{ github.event.workflow_run.conclusion == 'success' }}
needs:
- "get-version"
Expand All @@ -88,6 +88,6 @@ jobs:
uses: actions/checkout@v4

- name: "Release draft"
run: gh release edit "${GITHUB_REF#refs/tags/${{ needs.get-version.outputs.pkg-version }}}" --draft=false
run: gh release edit ${{ needs.get-version.outputs.pkg-version }} --draft=false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]

## 0.8.2

### Changed

- Small change to how connection type assessed and reported for the sake of efficiency
- Minor code cleanup

## 0.8.1

### Changed

- Small change to how webhook and/or apprise are called for the sake of efficiency
- Small change to how webhook and apprise are called for the sake of efficiency
- Updated license to GPL-3.0

## 0.8.0
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "docker-autoheal"
version = "0.8.1"
version = "0.8.2"
authors = ["Travis M Knight"]
license = "GPL-3.0"
description = "A cross-platform tool to monitor and remediate unhealthy Docker containers"
Expand Down
33 changes: 14 additions & 19 deletions src/execute/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ pub async fn connect_docker(
// Log final connection paramaters
let msg0 = format!("Monitoring Docker via {}", connection_type);
log_message(&msg0, INFO).await;
match connection_type.as_str() {

// Connect to Docker as specified
let docker = match connection_type.as_str() {
"http" => {
let msg1 = format!("Connecting to {}", tcp_address);
log_message(&msg1, INFO).await;
Docker::connect_with_http(&tcp_address, tcp_timeout, API_DEFAULT_VERSION)
}
"socket" => Docker::connect_with_socket_defaults(),
"ssl" => {
let msg1 = format!("Connecting to {}", tcp_address);
log_message(&msg1, INFO).await;
Expand All @@ -25,27 +29,18 @@ pub async fn connect_docker(
key_path, cert_path, ca_path
);
log_message(&msg2, INFO).await;
Docker::connect_with_ssl(
&tcp_address,
std::path::Path::new(&key_path),
std::path::Path::new(&cert_path),
std::path::Path::new(&ca_path),
tcp_timeout,
API_DEFAULT_VERSION,
)
}
&_ => {}
}
// Connect to Docker as specified
let docker = match connection_type.as_str() {
"http" => Docker::connect_with_http(
&tcp_address,
tcp_timeout,
API_DEFAULT_VERSION,
),
"socket" => Docker::connect_with_socket_defaults(),
"ssl" => Docker::connect_with_ssl(
&tcp_address,
std::path::Path::new(&key_path),
std::path::Path::new(&cert_path),
std::path::Path::new(&ca_path),
tcp_timeout,
API_DEFAULT_VERSION,
),
&_ => Docker::connect_with_local_defaults(),
};

match docker {
Ok(docker) => docker,
Err(e) => {
Expand Down
4 changes: 2 additions & 2 deletions src/execute/looper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub async fn start_loop(

// Determine if stop override label
let s = "autoheal.stop.timeout".to_string();
let autoheal_stop_timeout: isize = match container.labels {
let autoheal_stop_timeout = match container.labels {
Some(label) => match label.get(&s) {
Some(v) => v.parse().unwrap_or(autoheal_stop_timeout),
None => autoheal_stop_timeout,
Expand All @@ -53,7 +53,7 @@ pub async fn start_loop(
let name = name_tmp.trim_matches('/').trim();

// Get id of container
let id: String = match container.id {
let id = match container.id {
Some(id) => id.chars().take(12).collect(),
None => {
let msg0 = String::from("Could not reliably determine container id");
Expand Down
11 changes: 5 additions & 6 deletions src/inquire/environment.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::options::OptionsList;
use crate::{log_message, ERROR, WARNING};
use crate::{log_message, ALLOWED_CONNECTION_TYPES, ERROR, WARNING};

pub struct VariablesList {
pub connection_type: String,
Expand Down Expand Up @@ -29,15 +29,14 @@ fn get_env(key: &str, default: &str) -> String {
pub async fn get_var(opt: OptionsList) -> VariablesList {
let autoheal_connection_type: String = match opt.connection_type {
None => {
let allowed_connection_types: Vec<&str> = vec!["local", "socket", "http", "ssl"];
let env_connection_type = get_env("AUTOHEAL_CONNECTION_TYPE", "local");
match allowed_connection_types.contains(&env_connection_type.as_str()) {
match ALLOWED_CONNECTION_TYPES.contains(&env_connection_type.as_str()) {
true => env_connection_type,
false => {
let msg0 = format!(
"Unexpected connection-type ({}): {}",
allowed_connection_types.join(","),
env_connection_type
"Unexpected connection-type ({}): Expected one of {}",
env_connection_type,
ALLOWED_CONNECTION_TYPES.join(",")
);
log_message(&msg0, ERROR).await;
let msg1 = String::from("Attempting connection via default (local)");
Expand Down
5 changes: 2 additions & 3 deletions src/inquire/options.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::report::logging::print_version;
use crate::{report::logging::print_version, ALLOWED_CONNECTION_TYPES};
use getopts::Options;

pub struct OptionsList {
Expand Down Expand Up @@ -105,11 +105,10 @@ pub fn get_opts(args: Vec<String>) -> OptionsList {
}

// Ensure acceptable connection type arguments
let allowed_connection_types: Vec<&str> = vec!["local", "socket", "http", "ssl"];
match matches.opt_str("c").is_some() {
true => {
let opt_connection_type = matches.opt_str("c").unwrap();
match allowed_connection_types.contains(&opt_connection_type.as_str()) {
match ALLOWED_CONNECTION_TYPES.contains(&opt_connection_type.as_str()) {
true => {}
false => {
println!("Unexpected connection-type: {}", opt_connection_type);
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ pub const INFO: i8 = 0;
pub const WARNING: i8 = 1;
pub const ERROR: i8 = 2;

// Allowed connection types
pub const ALLOWED_CONNECTION_TYPES: [&str; 4] = ["local", "socket", "http", "ssl"];

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Collect binary arguments
let args: Vec<String> = std::env::args().collect();
let args = std::env::args().collect();
let opt = get_opts(args);

// Get Autoheal core variables
Expand Down

0 comments on commit c7e2ccb

Please sign in to comment.