From ede8ab2d7fb241b677964d393ce7c4cac5006a4d Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Wed, 13 Aug 2025 12:10:24 +0200 Subject: feat: docker publishing --- .editorconfig | 12 ++++++ .envrc | 3 ++ .github/workflows/build.yml | 19 +++++++++ .github/workflows/publish.yml | 46 +++++++++++++++++++++ Dockerfile | 22 ++++++++++ flake.lock | 96 +++++++++++++++++++++++++++++++++++++++++++ flake.nix | 61 +++++++++++++++++++++++++++ rust-toolchain.toml | 3 ++ rustfmt.toml | 1 + 9 files changed, 263 insertions(+) create mode 100644 .editorconfig create mode 100644 .envrc create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/publish.yml create mode 100644 Dockerfile create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust-toolchain.toml create mode 100644 rustfmt.toml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0cd2f7e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_style = tab +trim_trailing_whitespace = true + +[*.{yaml,yml}] +indent_size = 4 +indent_style = space diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..c80ee3b --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +watch_file -- flake-modules/*.nix +use flake . --show-trace diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..86447dc --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,19 @@ +name: Rust + +on: + push: + pull_request: + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..ca570c9 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,46 @@ +name: Publish Docker Image + +on: + push: + branches: + - master + tags: + - "*" + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE: nea89o/discordavatarproxy + +permissions: + contents: read + packages: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: docker/metadata-action@v5 + id: meta + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + - uses: docker/login-action@v3 + with: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ${{ env.REGISTRY }} + + - uses: docker/setup-buildx-action@v3 + - uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..71200f8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM clux/muslrust:1.89.0 AS chef +USER root +RUN cargo install cargo-chef +WORKDIR /app + +FROM chef AS planner +COPY . . +RUN rm rust-toolchain.toml +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +# Notice that we are specifying the --target flag! +RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json +COPY . . +RUN rm rust-toolchain.toml +RUN cargo build --release --target x86_64-unknown-linux-musl --bin pfp + +FROM docker.io/alpine:3 AS runtime +WORKDIR /app +COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/pfp /usr/local/bin/ +CMD ["/usr/local/bin/pfp"] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0c6e621 --- /dev/null +++ b/flake.lock @@ -0,0 +1,96 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1754725699, + "narHash": "sha256-iAcj9T/Y+3DBy2J0N+yF9XQQQ8IEb5swLFzs23CdP88=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "85dbfc7aaf52ecb755f87e577ddbe6dbbdbc1054", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1744536153, + "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1755052812, + "narHash": "sha256-Tjw2YP7Hz8+ibE8wJ+Ps65vh1lzAe5ozmoo9sdQ7rGg=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "433023cba5f4fa66b8b0fdbb8f91d420c9cc2527", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..3fed52b --- /dev/null +++ b/flake.nix @@ -0,0 +1,61 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + rust-overlay, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + rustPlatform = pkgs.makeRustPlatform { + cargo = rustToolchain; + rustc = rustToolchain; + }; + rustWithSrc = rustToolchain.override { + extensions = [ + "rust-analyzer" + "rust-src" + ]; + }; + deps = [ pkgs.openssl.dev ]; + in + with pkgs; + { + defaultPackage = rustPlatform.buildRustPackage { + name = "pfp"; + src = ./.; + cargoLock = { + lockFileContents = builtins.readFile ./Cargo.lock; + }; + buildInputs = deps; + nativeBuildInputs = [ pkgs.pkg-config ]; + }; + devShells.default = mkShell { + buildInputs = [ + rustWithSrc + sccache + cargo-make + lldb + ] + ++ deps; + nativeBuildInputs = [ pkg-config ]; + shellHook = '' + export RUSTC_WRAPPER="${sccache}/bin/sccache" + ''; + }; + formatter = alejandra; + } + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..7df5903 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +# Make sure this is always synced with Dockerfile +channel = "1.89.0" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..218e203 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +hard_tabs = true -- cgit