first commit
This commit is contained in:
commit
c409ffbd6d
1
.dockerignore
Normal file
1
.dockerignore
Normal file
@ -0,0 +1 @@
|
||||
/target
|
61
.github/workflows/build-version.yaml
vendored
Normal file
61
.github/workflows/build-version.yaml
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
---
|
||||
name: "Version build"
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
target: x86_64-unknown-linux-gnu
|
||||
- os: macos-latest
|
||||
target: x86_64-apple-darwin
|
||||
- os: macos-latest
|
||||
target: aarch64-apple-darwin
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
target: ${{ matrix.target }}
|
||||
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: build
|
||||
args: --release --all-features --target=${{ matrix.target }}
|
||||
|
||||
- name: Archive build artifacts
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: build-${{matrix.target}}
|
||||
path: ${{ github.workspace }}/target/${{ matrix.target }}/release/clin
|
||||
|
||||
release:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Download artifact
|
||||
uses: actions/download-artifact@v2
|
||||
|
||||
- name: Set version variable
|
||||
run: echo "CLIN_VERSION=${GITHUB_REF##*/}" >> $GITHUB_ENV
|
||||
|
||||
- name: Rename release to avoid name conflict
|
||||
run: ./scripts/rename_releases.sh
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: release/*
|
53
.github/workflows/container-stable.yaml
vendored
Normal file
53
.github/workflows/container-stable.yaml
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
---
|
||||
name: "Stable container"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "src/**"
|
||||
|
||||
jobs:
|
||||
containerization:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set action link variable
|
||||
run: echo "LINK=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@master
|
||||
with:
|
||||
platforms: all
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@master
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.CR_PAT }}
|
||||
|
||||
- name: Build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
builder: ${{ steps.buildx.outputs.name }}
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
ghcr.io/allanger/${{ env.GITHUB_REPOSITORY }}:stable
|
||||
ghcr.io/allanger/${{ env.GITHUB_REPOSITORY }}:latest
|
||||
labels: |
|
||||
action_id=${{ github.action }}
|
||||
action_link=${{ env.LINK }}
|
||||
actor=${{ github.actor }}
|
||||
sha=${{ github.sha }}
|
||||
ref=${{ github.ref }}
|
53
.github/workflows/container-version.yaml
vendored
Normal file
53
.github/workflows/container-version.yaml
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
---
|
||||
name: "Version container"
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
|
||||
jobs:
|
||||
containerization:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set version variable
|
||||
run: echo "TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV
|
||||
|
||||
- name: Set action link variable
|
||||
run: echo "LINK=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@master
|
||||
with:
|
||||
platforms: all
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@master
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.CR_PAT }}
|
||||
|
||||
- name: Build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
builder: ${{ steps.buildx.outputs.name }}
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
ghcr.io/allanger/${{ env.GITHUB_REPOSITORY }}:${{ env.TAG }}
|
||||
labels: |
|
||||
action_id=${{ github.action }}
|
||||
action_link=${{ env.LINK }}
|
||||
actor=${{ github.actor }}
|
||||
sha=${{ github.sha }}
|
||||
ref=${{ github.ref }}
|
57
.github/workflows/tests.yaml
vendored
Normal file
57
.github/workflows/tests.yaml
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
---
|
||||
name: "Tests"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "src/**"
|
||||
|
||||
jobs:
|
||||
cargo_udeps:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: nightly
|
||||
|
||||
- name: Install cargo-udeps
|
||||
run: cargo install cargo-udeps --locked
|
||||
|
||||
- name: Check dependencies
|
||||
run: cargo +nightly udeps
|
||||
|
||||
cargo_test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: build
|
||||
args: --release --all-features
|
||||
- run: cargo test
|
||||
cargo_clippy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: build
|
||||
args: --release --all-features
|
||||
- run: cargo clippy
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
1337
Cargo.lock
generated
Normal file
1337
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
15
Cargo.toml
Normal file
15
Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "clin"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.1.1", features = ["derive", "env"] }
|
||||
handlebars = "4.3.1"
|
||||
env_logger = "0.10.0"
|
||||
log = "0.4.17"
|
||||
http = "0.2.8"
|
||||
serde = { version = "1.0.126", features = ["derive"] }
|
||||
reqwest = { version = "0.11", features = ["json", "blocking"] }
|
12
Dockerfile
Normal file
12
Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
FROM rust:1.66.1-alpine3.17 as builder
|
||||
WORKDIR /src
|
||||
RUN apk update && apk add --no-cache libressl-dev musl-dev gcc
|
||||
COPY ./ .
|
||||
RUN cargo build --release
|
||||
|
||||
|
||||
FROM alpine:3.17.1
|
||||
COPY --from=builder /src/target/release/clin /bin/clin
|
||||
RUN apk update && apk add openssl --no-cache
|
||||
WORKDIR /workdir
|
||||
ENTRYPOINT ["/bin/clin"]
|
50
scripts/download_clin.sh
Normal file
50
scripts/download_clin.sh
Normal file
@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
case "$(uname)" in
|
||||
|
||||
"Darwin")
|
||||
SYSTEM="apple-darwin"
|
||||
case $(uname -m) in
|
||||
"arm64")
|
||||
TARGET="aarch64-$SYSTEM"
|
||||
;;
|
||||
"x86_64")
|
||||
TARGET="x86_64-$SYSTEM"
|
||||
;;
|
||||
*)
|
||||
echo "Unsuported target"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
"Linux")
|
||||
SYSTEM="unknown-linux-gnu"
|
||||
case $(uname -m) in
|
||||
"x86_64")
|
||||
TARGET="x86_64-$SYSTEM"
|
||||
;;
|
||||
*)
|
||||
echo "Unsuported target"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo "Signal number $1 is not processed"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
LATEST_VERSION="v$(curl -s https://raw.githubusercontent.com/allanger/clever-install/main/Cargo.toml | awk -F ' = ' '$1 ~ /version/ { gsub(/[\"]/, "", $2); printf("%s",$2); exit}')"
|
||||
echo "Downloading $LATEST_VERSION"
|
||||
|
||||
RELEASE_NAME=clin-$LATEST_VERSION-$TARGET
|
||||
RELEASE_URL="https://github.com/allanger/clever-install/releases/download/$LATEST_VERSION/$RELEASE_NAME"
|
||||
echo "Link for downloading: $RELEASE_URL"
|
||||
curl -LJO $RELEASE_URL
|
||||
|
||||
mv $RELEASE_NAME clin
|
||||
chmod +x clin
|
||||
|
||||
echo 'Make sure that clin is in your $PATH'
|
||||
echo 'Try: '
|
||||
echo ' $ export PATH=$PATH:$PWD'
|
||||
echo ' $ clin -h'
|
10
scripts/rename_releases.sh
Executable file
10
scripts/rename_releases.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
echo 'renaming clin to clin-$VERSION-$SYSTEM format'
|
||||
mkdir -p release
|
||||
echo "version - $clin_VERSION"
|
||||
for BUILD in build*; do
|
||||
SYSTEM=$(echo $BUILD | sed -e 's/build-//g')
|
||||
echo "system - $SYSTEM"
|
||||
cp $BUILD/clin release/clin-$CLIN_VERSION-$SYSTEM
|
||||
done
|
||||
ls release
|
68
src/main.rs
Normal file
68
src/main.rs
Normal file
@ -0,0 +1,68 @@
|
||||
use clap::Parser;
|
||||
use handlebars::Handlebars;
|
||||
use http::{StatusCode};
|
||||
use log::{error, info};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use std::{
|
||||
env::consts::{ARCH, OS},
|
||||
fs::File,
|
||||
io,
|
||||
process::exit,
|
||||
};
|
||||
|
||||
/// Check you helm releaseas managed by Argo
|
||||
#[derive(Parser)]
|
||||
#[clap(author = "allanger <allanger@zohomail.com>", version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// A templated link for downloading
|
||||
#[clap(short, long, env = "CLIN_LINK")]
|
||||
link_template: String,
|
||||
/// Version that you want to download
|
||||
#[clap(short, long, env = "CLIN_VERSION")]
|
||||
package_version: String,
|
||||
/// Path to download
|
||||
#[clap(short, long, env = "CLIN_PATH")]
|
||||
install_path: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
struct Values {
|
||||
version: String,
|
||||
os: String,
|
||||
arch: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
let args = Args::parse();
|
||||
let mut reg = Handlebars::new();
|
||||
reg.register_template_string("download_link", args.link_template)
|
||||
.unwrap();
|
||||
|
||||
let archs: Vec<String> = match ARCH {
|
||||
"x86_64" => vec!["x86_64".to_string(), "amd64".to_string()],
|
||||
"aarch64" => vec!["aarch64".to_string(), "arm64".to_string()],
|
||||
_ => {
|
||||
error!("Unknown architecture");
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
for arch in archs {
|
||||
let version = args.package_version.clone();
|
||||
let os = OS.to_string();
|
||||
let values = Values { arch, os, version };
|
||||
|
||||
let link = reg.render("download_link", &values).unwrap();
|
||||
info!("Trying to download from {}", link.clone());
|
||||
let mut resp = reqwest::blocking::get(link).unwrap();
|
||||
if resp.status() == StatusCode::OK {
|
||||
info!("Response is 200, I'll try to download");
|
||||
let mut out = File::create(args.install_path).expect("failed to create file");
|
||||
io::copy(&mut resp, &mut out).expect("failed to copy content");
|
||||
break;
|
||||
}
|
||||
info!("Will try another name for arch, because response is not 200");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user