From efcf83033f45a45c4589320edc6638041e805ca7 Mon Sep 17 00:00:00 2001 From: Serge Logvinov Date: Sat, 19 Sep 2026 10:04:51 +0200 Subject: [PATCH] feat: github actions --- .dockerignore | 9 +++ .github/workflows/build-test.yaml | 50 +++++++++++++++++ .github/workflows/release.yaml | 58 +++++++++++++++++++ .goreleaser.yml | 92 +++++++++++++++++++++++++++++++ Dockerfile | 49 ++++++++++++++++ Makefile | 62 +++++++++++++++++++++ 6 files changed, 320 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/build-test.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .goreleaser.yml create mode 100644 Dockerfile create mode 100644 Makefile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c063991 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git/ +.github/ +.gitignore +.dockerignore +/charts/ +# +docker-compose.yml +# +/.cargo/ diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml new file mode 100644 index 0000000..1d3ba3e --- /dev/null +++ b/.github/workflows/build-test.yaml @@ -0,0 +1,50 @@ +name: Build check + +on: + workflow_dispatch: {} + pull_request: + branches: + - main + paths: + - "src/**" + - "Dockerfile" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + name: Build and Test + timeout-minutes: 15 + runs-on: ubuntu-24.04 + if: github.event.pull_request.draft == false + permissions: + contents: read + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Rust toolchain + uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # v1 + with: + toolchain: "1.98" + components: clippy, rustfmt + - name: Install cargo-deny + uses: taiki-e/install-action@3f74d7c16a4242f1c95561e98edc25d36adb4375 # v2.87.12 + with: + tool: cargo-deny + - name: Rust cache + uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 + + - name: Rust build + run: make build test + + - name: Rust fmt + run: make fmt + - name: Rust linter + run: make lint + - name: Rust dependencies check + run: make deps diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..e34918d --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,58 @@ +name: Release + +on: + workflow_dispatch: {} + # push: + # tags: + # - "v*" + +jobs: + goreleaser: + name: GoReleaser + runs-on: ubuntu-24.04 + permissions: + contents: write + packages: write + id-token: write + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Rust toolchain + uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # v1 + with: + toolchain: "1.98" + components: clippy, rustfmt + - name: Rust cache + uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 + + - name: Install Cosign + uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 + - name: Set up QEMU + uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0 + with: + platforms: arm64 + - name: Set up docker buildx + uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0 + - name: Setup Node.js + uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + with: + node-version: 24 + + - name: Github registry login + uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7.2.3 + with: + version: "v2.18.1" + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..138950e --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,92 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +version: 2 +project_name: aralez + +dist: target +builds: + - id: aralez + builder: rust + flags: + - --release + targets: + - x86_64-unknown-linux-gnu + - aarch64-unknown-linux-gnu + env: + - RUSTFLAGS={{ if eq .Arch "amd64" }}-C target-cpu=x86-64-v3 -C target-feature=+aes,+ssse3{{else}}-C target-cpu=neoverse-n1 -C target-feature=+aes,+sha2,+neon,+crc{{ end }} + + - id: aralez-musl + builder: rust + flags: + - --release + targets: + - x86_64-unknown-linux-musl + - aarch64-unknown-linux-musl + env: + - RUSTFLAGS={{ if eq .Arch "amd64" }}-C target-cpu=x86-64-v3 -C target-feature=+aes,+ssse3{{else}}-C target-cpu=neoverse-n1 -C target-feature=+aes,+sha2,+neon,+crc{{ end }} + +snapshot: + version_template: edge + +archives: + - id: aralez + ids: + - aralez + formats: [binary] + name_template: "{{ .ProjectName }}_{{ .Arch }}-glibc" + + - id: aralez-musl + ids: + - aralez-musl + formats: [binary] + name_template: "{{ .ProjectName }}_{{ .Arch }}-musl" + +dockers_v2: + - id: aralez + ids: + - aralez + flags: + - --target=release + images: + - "ghcr.io/sadoyan/{{ .ProjectName }}" + # - "sadoyan/{{ .ProjectName }}" + tags: + - "{{ if not .IsSnapshot }}v{{.Version}}{{ else }}edge{{ end }}" + platforms: + - linux/amd64 + - linux/arm64 + annotations: + org.opencontainers.image.name: "{{ .ProjectName }}" + org.opencontainers.image.licenses: "Apache-2.0" + org.opencontainers.image.source: "https://github.com/sadoyan/{{ .ProjectName }}" + org.opencontainers.image.url: "{{ .GitURL }}" + org.opencontainers.image.created: "{{ .Date }}" + org.opencontainers.image.version: "{{ .Version }}" + org.opencontainers.image.revision: "{{ .FullCommit }}" + io.artifacthub.package.readme-url: "https://raw.githubusercontent.com/sadoyan/{{ .ProjectName }}/main/README.md" + io.artifacthub.package.license: "Apache-2.0" + +docker_signs: + - id: docker + ids: + - aralez + cmd: cosign + args: + - sign + - "--yes" + - "${artifact}" + output: true + +checksum: + name_template: checksums.txt + algorithm: sha256 + +signs: + - artifacts: checksum + signature: "${artifact}.sigstore.json" + cmd: cosign + args: + - sign-blob + - "--yes" + - "--bundle=${signature}" + - "${artifact}" + output: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1ff0630 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +# syntax = docker/dockerfile:1.22 +######################################## + +FROM rust:1.98-trixie AS builder +ARG TARGETARCH + +RUN apt-get update && \ + apt-get install -y build-essential make cmake pkg-config libssl-dev musl-dev musl-tools + +RUN case "${TARGETARCH}" in \ + amd64) \ + apt-get install -y --no-install-recommends gcc-x86-64-linux-gnu && \ + rustup target add x86_64-unknown-linux-gnu; \ + rustup target add x86_64-unknown-linux-musl; \ + ;; \ + arm64) \ + apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu && \ + rustup target add aarch64-unknown-linux-gnu; \ + rustup target add aarch64-unknown-linux-musl; \ + ;; \ + *) echo "Unsupported architecture: ${TARGETARCH}" >&2; exit 1 ;; \ + esac +RUN rustup component add rustfmt clippy && \ + cargo install cargo-deny + +RUN ARCH=$(case "${TARGETARCH}" in \ + amd64) echo "x86_64" ;; \ + arm64) echo "aarch64" ;; \ + *) echo "${TARGETARCH}" ;; \ + esac) && curl -LO https://ziglang.org/download/0.16.0/zig-${ARCH}-linux-0.16.0.tar.xz \ + && tar -xf zig-${ARCH}-linux-0.16.0.tar.xz -C /opt \ + && ln -s /opt/zig-${ARCH}-linux-0.16.0/zig /usr/local/bin/zig + +RUN echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | tee /etc/apt/sources.list.d/goreleaser.list && \ + apt-get update && apt-get install -y goreleaser + +RUN cargo install cargo-binstall --locked && \ + cargo binstall cargo-zigbuild --no-confirm + +COPY [".", "/src"] + +######################################## + +FROM --platform=${TARGETARCH} gcr.io/distroless/cc-debian13:nonroot AS release + +ARG TARGETPLATFORM +COPY ${TARGETPLATFORM}/aralez /usr/local/bin/aralez + +ENTRYPOINT ["/usr/local/bin/aralez"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..81679ef --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +######################################################## + +TARGET ?= --all-targets +FEATURES ?= --all-features + +######################################################## + +.PHONY: help +help: + @awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +######################################################## + +.PHONY: all +all: build test fmt checkup ## Build and test project + +.PHONY: build +build: ## Build project + cargo build --workspace $(TARGET) $(FEATURES) + +.PHONY: test +test: ## Run tests + cargo test --workspace $(TARGET) $(FEATURES) + +.PHONY: fmt +fmt: ## Check code formatting + cargo fmt --all -- --check + +.PHONY: lint +lint: ## Run linter + cargo clippy --workspace $(TARGET) $(FEATURES) -- -D warnings + +.PHONY: checkup +checkup: lint ## Run linter and check project + cargo check --workspace $(TARGET) $(FEATURES) + +.PHONY: deps +deps: ## Check project dependencies for advisories + cargo deny check advisories + +######################################################## + +.PHONY: update +update: + cargo update --verbose + +.PHONY: features +features: + cargo features + +######################################################## + +.PHONY: fix +fix: + cargo fix + +.PHONY: fix-all +fix-all: + cargo fix --all + cargo clippy --workspace $(TARGET) $(FEATURES) --fix + +########################################################