diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..4adf902 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,55 @@ +name: build + +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] + +jobs: + docker: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: scm.wyattjmiller.com + username: ${{ secrets.GH_ACTION_USERNAME }} + password: ${{ secrets.GH_ACTION_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: scm.wyattjmiller.com/wymiller/caitsith + tags: | + type=sha,prefix= + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Build and test Docker image + uses: docker/build-push-action@v5 + with: + context: . + target: test + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Build and push production Docker image + uses: docker/build-push-action@v5 + with: + context: . + target: production + push: ${{ github.event_name != 'pull_request' }} + tags: scm.wyattjmiller.com/wymiller/caitsith + labels: ${{ steps.meta.outputs.labels }} diff --git a/Cargo.lock b/Cargo.lock index 709cae6..d8408d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -136,6 +136,21 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +[[package]] +name = "cait-sith" +version = "0.1.0" +dependencies = [ + "chrono", + "dotenvy", + "rand 0.8.5", + "reqwest 0.12.15", + "serde", + "serde_json", + "serenity", + "tokio", + "tracing", +] + [[package]] name = "camino" version = "1.1.9" @@ -1786,21 +1801,6 @@ dependencies = [ "uwl", ] -[[package]] -name = "setzer" -version = "0.1.0" -dependencies = [ - "chrono", - "dotenvy", - "rand 0.8.5", - "reqwest 0.12.15", - "serde", - "serde_json", - "serenity", - "tokio", - "tracing", -] - [[package]] name = "sha1" version = "0.10.6" diff --git a/Cargo.toml b/Cargo.toml index 4c39ca5..ab917be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "setzer" +name = "cait-sith" version = "0.1.0" edition = "2021" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5ab8d72 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +# Build stage +FROM rust:1.86 as builder +WORKDIR /usr/src/app +COPY . . +RUN cargo build --release + +# Test stage +FROM builder as test +RUN cargo test + +# Production stage +FROM debian:bookworm-slim as production +WORKDIR /usr/src/app +RUN apt update -q +RUN apt install openssl -y -q +COPY --from=builder /usr/src/app/target/release/cait-sith . +CMD ["./cait-sith"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..aaf12d6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: "3" +services: + caitsith-discord-bot: + image: scm.wyattjmiller.com/wymiller/caitsith:latest + environment: + VIRTUAL_HOST: caitsith.discord.wyattjmiller.com + VIRTUAL_PORT: 80 + LETSENCRYPT_HOST: caitsith.discord.wyattjmiller.com + LETSENCRYPT_EMAIL: wjmiller2016@gmail.com + ## Fill these in when you deploy + # GUILD_ID: + # DISCORD_TOKEN: + expose: + - 80 + +networks: + default: + external: + name: nginx-proxy diff --git a/flake.nix b/flake.nix index e34b476..a67a8aa 100644 --- a/flake.nix +++ b/flake.nix @@ -1,9 +1,7 @@ # This flake was initially generated by fh, the CLI for FlakeHub (version 0.1.18) { - description = "A dice roller bot"; - inputs = { flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*"; @@ -15,51 +13,53 @@ }; }; - - outputs = { self, flake-schemas, nixpkgs, rust-overlay }: - let - - overlays = [ - rust-overlay.overlays.default - (final: prev: { - rustToolchain = final.rust-bin.stable.latest.default.override { extensions = [ "rust-src"]; }; - }) - ]; + outputs = { + self, + flake-schemas, + nixpkgs, + rust-overlay, + }: let + overlays = [ + rust-overlay.overlays.default + (final: prev: { + rustToolchain = final.rust-bin.stable.latest.default.override {extensions = ["rust-src"];}; + }) + ]; - - supportedSystems = [ "x86_64-linux" "aarch64-darwin" "aarch64-linux" ]; - forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f { - pkgs = import nixpkgs { inherit overlays system; }; - }); - in { - - schemas = flake-schemas.schemas; + supportedSystems = ["x86_64-linux" "aarch64-darwin" "aarch64-linux"]; + forEachSupportedSystem = f: + nixpkgs.lib.genAttrs supportedSystems (system: + f { + pkgs = import nixpkgs {inherit overlays system;}; + }); + in { + schemas = flake-schemas.schemas; - - devShells = forEachSupportedSystem ({ pkgs }: { - default = pkgs.mkShell { - - packages = with pkgs; [ - rustToolchain - cargo-bloat - cargo-edit - cargo-outdated - cargo-udeps - cargo-watch - rust-analyzer - curl - git - jq - wget - nixpkgs-fmt - ]; + devShells = forEachSupportedSystem ({pkgs}: { + default = pkgs.mkShell { + packages = with pkgs; [ + rustToolchain + cargo-bloat + cargo-edit + cargo-outdated + cargo-udeps + cargo-watch + rust-analyzer + curl + git + jq + wget + nixpkgs-fmt + pkg-config-unwrapped + openssl.dev + ]; - - env = { - RUST_BACKTRACE = "1"; - RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library"; - }; + env = { + RUST_BACKTRACE = "1"; + RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library"; + PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; }; - }); - }; + }; + }); + }; }