m/cup
1
0
mirror of https://github.com/sergi0g/cup.git synced 2025-11-08 13:13:49 -05:00

13 Commits

Author SHA1 Message Date
Sergio
75700cd692 Update nightly workflow to upload the correct binaries 2024-07-11 12:36:57 +03:00
Sergio
6573b43ce0 I know I'm not supposed to do this, but I have to. 2024-07-11 12:32:44 +03:00
Sergio
bee808e577 FINALLY fix Dockerfile 2024-07-11 12:27:02 +03:00
Sergio
ac8f97fbcd Update workflows 2024-07-10 19:44:55 +03:00
Sergio
4ec661183f Update nightly.yml
Make jq output unquoted string
2024-07-10 15:20:08 +03:00
Sergio
39b2355c04 Update nightly.yml
Try to fix workflow
2024-07-10 15:15:56 +03:00
Sergio
867ab4ba10 Update Cargo.toml
I have to automate this
2024-07-10 14:49:01 +03:00
Sergio
9a75f5101f Update Dockerfile
Experimental dependency caching
2024-07-10 14:41:21 +03:00
Sergio
54eed353aa Add nightly workflow 2024-07-10 14:39:03 +03:00
Sergio
e3319d9371 Update Dockerfile
Hotfix
2024-07-10 14:23:05 +03:00
Sergio
38d775688a Update Dockerfile
Fix broken build process (attempt 1)
2024-07-10 14:07:22 +03:00
Sergio
31dd605efb Update Cargo.toml
I forgot to change the version
2024-07-10 12:08:00 +03:00
Sergio
06ec23520d Updated image regex to support any image. Removed dependency on fancy_regex in favour of the regex crate 2024-07-10 09:59:00 +03:00
7 changed files with 223 additions and 74 deletions

View File

@@ -1,27 +1,60 @@
name: Build docker image
name: Release
on:
release:
types:
- published
env:
CARGO_TERM_COLOR: always
push:
tags: ["v*.*.*"]
jobs:
build:
get-tag:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get current tag
run: |
TAG=$(echo "$GITHUB_REF" | sed 's/^refs\/tags\///')
echo "Current tag: $TAG"
echo "tag=$TAG" >> $GITHUB_OUTPUT
build-binary:
strategy:
matrix:
platform:
- release_for: linux-aarch64
os: ubuntu-latest
target: aarch64-unknown-linux-musl
bin: cup
name: cup-linux-aarch64
command: build
- name: Get latest release tag
id: release
uses: pozetroninc/github-action-get-latest-release@master
- release_for: linux-x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-musl
bin: cup
name: cup-linux-x86_64
command: build
runs-on: ${{ matrix.platform.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build binary
run: cross ${{ matrix.platform.command }} --target ${{ matrix.platform.target }} --release
- name: Upload binary
uses: actions/upload-artifact@v4
with:
owner: sergi0g
repo: cup
excludes: prerelease, draft
name: ${{ matrix.platform.name }}
path: target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}
build-image:
needs: get-tag
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
@@ -33,17 +66,41 @@ jobs:
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64, linux/arm64
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/sergi0g/cup:latest
ghcr.io/sergi0g/cup:${{ steps.release.outputs.release }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ghcr.io/sergi0g/cup:${{ needs.get-tag.outputs.tag }}
release:
runs-on: ubuntu-latest
needs: [get-tag, build-image, build-binary]
steps:
- name: Download arm64 binary
uses: actions/download-artifact@v4
with:
name: cup-linux-aarch64
path: cup-linux-aarch64
- name: Download x86 binary
uses: actions/download-artifact@v4
with:
name: cup-linux-x86_64
path: cup-linux-x86_64
- name: Create release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
prerelease: true
tag_name: ${{ needs.get-tag.outputs.tag }}
name: ${{ needs.get-tag.outputs.tag }}
files: |
cup-linux-aarch64/cup-linux-aarch64
cup-linux-x86_64/cup-linux-x86_64

121
.github/workflows/nightly.yml vendored Normal file
View File

@@ -0,0 +1,121 @@
name: Nightly Release
on:
workflow_dispatch:
inputs:
tag:
description: "Nightly version tag"
required: true
jobs:
create-tag:
runs-on: ubuntu-latest
outputs:
tagname: ${{ steps.get_tag.outputs.tagname }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get tag from Cargo.toml
id: get_tag
run: |
VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version')
echo "tagname=v$VERSION-nightly.${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
- uses: rickstaa/action-create-tag@v1
with:
tag: ${{ steps.get_tag.outputs.tagname }}
build-binary:
needs: create-tag
strategy:
matrix:
platform:
- release_for: linux-aarch64
os: ubuntu-latest
target: aarch64-unknown-linux-musl
bin: cup
name: cup-linux-aarch64
command: build
- release_for: linux-x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-musl
bin: cup
name: cup-linux-x86_64
command: build
runs-on: ${{ matrix.platform.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build binary
run: cross ${{ matrix.platform.command }} --target ${{ matrix.platform.target }}
- name: Upload CLI
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform.name }}
path: target/${{ matrix.platform.target }}/debug/${{ matrix.platform.bin }}
build-image:
needs: create-tag
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64, linux/arm64
push: true
tags: ghcr.io/sergi0g/cup:${{ needs.create-tag.outputs.tagname }}
nightly-release:
runs-on: ubuntu-latest
needs: [create-tag, build-image, build-binary]
steps:
- name: Download arm64 binary
uses: actions/download-artifact@v4
with:
name: cup-linux-aarch64
path: cup-linux-aarch64
- name: Download x86 binary
uses: actions/download-artifact@v4
with:
name: cup-linux-x86_64
path: cup-linux-x86_64
- name: Create nightly release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
prerelease: true
tag_name: ${{ needs.create-tag.outputs.tagname }}
name: ${{ needs.create-tag.outputs.tagname }}
files: |
cup-linux-aarch64/cup-linux-aarch64
cup-linux-x86_64/cup-linux-x86_64

30
Cargo.lock generated
View File

@@ -140,21 +140,6 @@ version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
[[package]]
name = "bit-set"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1"
dependencies = [
"bit-vec",
]
[[package]]
name = "bit-vec"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
[[package]]
name = "block-buffer"
version = "0.10.4"
@@ -365,17 +350,17 @@ dependencies = [
[[package]]
name = "cup"
version = "0.1.0"
version = "1.1.1"
dependencies = [
"bollard",
"clap",
"fancy-regex",
"http-auth",
"indicatif",
"json",
"liquid",
"once_cell",
"rayon",
"regex",
"termsize",
"tokio",
"ureq",
@@ -426,17 +411,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "fancy-regex"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "531e46835a22af56d1e3b66f04844bed63158bc094a628bec1d321d9b4c44bf2"
dependencies = [
"bit-set",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "flate2"
version = "1.0.30"

View File

@@ -1,6 +1,6 @@
[package]
name = "cup"
version = "0.1.0"
version = "1.1.1"
edition = "2021"
[dependencies]
@@ -14,9 +14,9 @@ xitca-web = { version = "0.5.0", optional = true }
liquid = { version = "0.26.6", optional = true }
bollard = "0.16.1"
once_cell = "1.19.0"
fancy-regex = "0.13.0"
http-auth = { version = "0.1.9", features = [] }
termsize = { version = "0.1.8", optional = true }
regex = "1.10.5"
[features]
default = ["server", "cli"]

View File

@@ -3,12 +3,16 @@ WORKDIR /
RUN apk add musl-dev
RUN USER=root cargo new cup
RUN USER=root cargo new --bin cup
WORKDIR /cup
COPY Cargo.toml Cargo.lock ./
RUN cargo build --release
COPY src ./src
COPY Cargo.toml Cargo.lock .
RUN cargo build --release
RUN rm -rf src/
COPY src src
# This is a very bad workaround, but cargo only triggers a rebuild this way for some reason
RUN printf "\n" >> src/main.rs
RUN cargo build --release
FROM scratch

View File

@@ -143,7 +143,7 @@ $ docker run -v /var/run/docker.sock:/var/run/docker.sock -p <PORT>:<PORT> cup s
Cup is a work in progress. It might not have as many features as What's up Docker. If one of these features is really important for you, please consider using another tool.
- Cup currently doesn't support registries which use repositories without slashes. This includes Azure. This problem may sound a bit weird, but it's due to the regex that's used at the moment. This will (hopefully) be fixed in the future.
- ~~Cup currently doesn't support registries which use repositories without slashes. This includes Azure. This problem may sound a bit weird, but it's due to the regex that's used at the moment. This will (hopefully) be fixed in the future.~~
- Cup doesn't support private images. This is on the roadmap. Currently, it just returns unknown for those images.
- Cup cannot trigger your integrations. If you want that to happen automatically, please use What's up docker instead. Cup was created to be simple. The data is there, and it's up to you to retrieve it (e.g. by running `cup check -r` with a cronjob or periodically requesting the `/json` url from the server)

View File

@@ -1,4 +1,4 @@
use fancy_regex::Regex;
use regex::Regex;
use once_cell::sync::Lazy;
#[macro_export]
@@ -9,27 +9,20 @@ macro_rules! error {
})
}
// Takes an image and splits it into registry, repository and tag. For example ghcr.io/sergi0g/cup:latest becomes ['ghcr.io', 'sergi0g/cup', 'latest']. ONLY REGISTRIES THAT USE A / IN THE REPOSITORY ARE SUPPORTED CURRENTLY. THAT MEANS AZURE WILL NOT WORK.
// Takes an image and splits it into registry, repository and tag. For example ghcr.io/sergi0g/cup:latest becomes ['ghcr.io', 'sergi0g/cup', 'latest'].
pub fn split_image(image: &str) -> (String, String, String) {
static RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r#"^(?P<registry>[\w.\-_]+((?::\d+|)(?=/[a-z0-9._-]+/[a-z0-9._-]+))|)(?:/|)(?P<repository>[a-z0-9.\-_]+(?:/[a-z0-9.\-_]+|))(:(?P<tag>[\w.\-_]{1,127})|)$"#, // From https://regex101.com/r/a98UqN/1
r#"^(?P<name>(?:(?P<registry>(?:(?:localhost|[\w-]+(?:\.[\w-]+)+)(?::\d+)?)|[\w]+:\d+)/)?(?P<repository>[a-z0-9_.-]+(?:/[a-z0-9_.-]+)*))(?::(?P<tag>[\w][\w.-]{0,127}))?$"#, // From https://regex101.com/r/nmSDPA/1
)
.unwrap()
});
match RE.captures(image).unwrap() {
match RE.captures(image) {
Some(c) => {
return (
match c.name("registry") {
Some(registry) => {
let reg = registry.as_str().to_owned();
if reg.is_empty() {
String::from("registry-1.docker.io")
} else {
reg
}
}
None => error!("Failed to parse image {}", image),
Some(registry) => registry.as_str().to_owned(),
None => String::from("registry-1.docker.io"),
},
match c.name("repository") {
Some(repository) => {