Skip to content

Commit

Permalink
Merge pull request #1 from samply/develop
Browse files Browse the repository at this point in the history
Merge develop into main
  • Loading branch information
lablans authored May 19, 2023
2 parents 1fbdfb3 + 8917447 commit 152afc1
Show file tree
Hide file tree
Showing 14 changed files with 544 additions and 20 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "cargo" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
target-branch: "develop"
26 changes: 26 additions & 0 deletions .github/workflows/dockerhub_readme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Update Docker Hub Readme
on:
push:
branches:
- main
jobs:
PushContainerReadme:
runs-on: ubuntu-latest

strategy:
matrix:
component:
- rustyspot

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Sync Readme
uses: lablans/sync-dockerhub-readme@feature/replace-patterns
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD_REQUIRED_FOR_README_SYNC }}
repository: ${{ github.repository }}-${{ matrix.component }}
readme: "./README.md"
replace_pattern: "](./"
replace_with: "](https://raw.githubusercontent.com/${{ github.repository }}/${{ github.ref_name }}/"
125 changes: 125 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: Build with rust and docker

on:
push:
pull_request:
schedule:
# Fetch new base image updates every night at 1am
- cron: '0 1 * * *'

env:
CARGO_TERM_COLOR: always
PROFILE: release

jobs:
pre-check:
name: Security, License Check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1

build-rust:
name: Build (Rust)
runs-on: ubuntu-20.04

strategy:
matrix:
arch:
- amd64
- arm64

steps:
- name: Set arch ${{ matrix.arch }}
env:
ARCH: ${{ matrix.arch }}
run: |
if [ "${ARCH}" == "arm64" ]; then
echo "rustarch=aarch64-unknown-linux-gnu" >> $GITHUB_ENV
elif [ "${ARCH}" == "amd64" ]; then
echo "rustarch=x86_64-unknown-linux-gnu" >> $GITHUB_ENV
else
exit 1
fi
if [ "$(dpkg --print-architecture)" != "${ARCH}" ]; then
echo "Cross-compiling to ${ARCH}."
echo "is_cross=true" >> $GITHUB_ENV
else
echo "Natively compiling to ${ARCH}."
echo "is_cross=false" >> $GITHUB_ENV
fi
- name: Set profile ${{ env.PROFILE }}
env:
PROFILE: ${{ env.PROFILE }}
run: |
if [ "${PROFILE}" == "release" ]; then
echo "profilestr=--release" >> $GITHUB_ENV
elif [ "${PROFILE}" == "debug" ]; then
echo "profilestr=" >> $GITHUB_ENV
else
echo "profilestr=--profile $PROFILE" >> $GITHUB_ENV
fi
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
target: ${{ env.rustarch }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.arch }}-${{ env.PROFILE }}
prefix-key: "v1-rust" # Increase to invalidate old caches.
- name: Build (${{ matrix.arch }})
uses: actions-rs/cargo@v1
with:
use-cross: ${{ env.is_cross }}
command: build
args: --target ${{ env.rustarch }} ${{ env.profilestr }}
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: binaries-${{ matrix.arch }}
path: |
target/${{ env.rustarch }}/${{ env.PROFILE }}/spot
# test:
# name: Run tests
# needs: [ build-rust ]
# runs-on: ubuntu-22.04

# steps:
# - uses: actions/checkout@v3
# - uses: actions/download-artifact@v3
# with:
# name: binaries-amd64
# path: artifacts/binaries-amd64/
# - run: ./dev/test ci

docker:
needs: [ build-rust, pre-check ]
# This workflow defines how a maven package is built, tested and published.
# Visit: https://github.com/samply/github-workflows/blob/develop/.github/workflows/docker-ci.yml, for more information
uses: samply/github-workflows/.github/workflows/docker-ci.yml@main
with:
# The Docker Hub Repository you want eventually push to, e.g samply/share-client
image-name: "samply/rustyspot"
# Define special prefixes for docker tags. They will prefix each images tag.
# image-tag-prefix: "foo"
# Define the build context of your image, typically default '.' will be enough
# build-context: '.'
# Define the Dockerfile of your image, typically default './Dockerfile' will be enough
build-file: './Dockerfile.ci'
# NOTE: This doesn't work currently
# A list of build arguments, passed to the docker build
# build-args: |
# PROFILE=${{ env.PROFILE }}
# COMPONENT=broker
# Define the target platforms of the docker build (default "linux/amd64,linux/arm64/v8")
# build-platforms: "linux/amd64"
# If your actions generate an artifact in a previous build step, you can tell this workflow to download it
artifact-name: '*'
# This passes the secrets from calling workflow to the called workflow
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
11 changes: 11 additions & 0 deletions .github/workflows/rust_security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
on:
schedule:
- cron: '0 3 * * 1'
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/target
target/
Cargo.lock
13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
name = "spot"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
documentation = "https://github.com/samply/spot"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-sse = "5.1.0"
async-stream = "0.3.4"
axum = "0.6.12"
#axum-macros = "0.3.7"
clap = { version = "4.2.1", features = ["env", "derive"] }
futures = "0.3.28"
hyper = "0.14.25"
Expand All @@ -17,4 +20,12 @@ serde = { version = "1.0.159", features = ["serde_derive"] }
serde_json = "1.0.96"
tokio = { version = "1.27.0", features = ["full"] }
tokio-util = { version = "0.7.7", features = ["io"] }
uuid = { version = "1.3.0", features = ["v4"] }
uuid = { version = "1.3.0", features = ["v4", "serde"] }

# Logging
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
http = "0.2.9"

[build-dependencies]
build-data = "0.1.4"
5 changes: 5 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.aarch64-unknown-linux-gnu]
image = "ghcr.io/lablans/cross-test:aarch64-unknown-linux-gnu"

[target.x86_64-unknown-linux-gnu]
image = "ghcr.io/lablans/cross-test:x86_64-unknown-linux-gnu"
13 changes: 13 additions & 0 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This assumes binaries are present, see COPY directive.

ARG IMGNAME=gcr.io/distroless/cc

FROM alpine AS chmodder
ARG TARGETARCH
COPY /artifacts/binaries-$TARGETARCH/spot /app/
RUN chmod +x /app/*

FROM ${IMGNAME}
COPY --from=chmodder /app/* /usr/local/bin/
ENTRYPOINT [ "/usr/local/bin/spot" ]

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Samply.Spot

This is the Rust re-implementation of Samply.Spot.
26 changes: 26 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use build_data::get_git_dirty;

/// Outputs a readable version number such as
/// 0.4.0 (if git commit is clean)
/// 0.4.0-SNAPSHOT (if git commit is dirty, should not happen in CI/CD builds)
fn version() -> String {
let version = String::from(env!("CARGO_PKG_VERSION"));
match get_git_dirty().unwrap() {
false => version,
true => {
format!("{}-SNAPSHOT", version)
}
}
}

fn main() {
build_data::set_GIT_COMMIT_SHORT();
build_data::set_GIT_DIRTY();
build_data::set_BUILD_DATE();
build_data::set_BUILD_TIME();
build_data::no_debug_rebuilds();
println!(
"cargo:rustc-env=SAMPLY_USER_AGENT=Samply.Spot/{}",
version()
);
}
Loading

0 comments on commit 152afc1

Please sign in to comment.