From 8fa301ad1a09892288fb2fb5538033288b5f0725 Mon Sep 17 00:00:00 2001 From: Andrew Brower Date: Sun, 12 Jan 2025 04:21:28 -0500 Subject: [PATCH] ci: nightly container builds --- .containerignore | 14 +++++++ .github/workflows/container.yml | 73 +++++++++++++++++++++++++++++++++ Cargo.toml | 10 ++++- Containerfile | 12 ++++++ README.md | 2 +- src/args.rs | 15 +++---- 6 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 .containerignore create mode 100644 .github/workflows/container.yml create mode 100644 Containerfile diff --git a/.containerignore b/.containerignore new file mode 100644 index 0000000..fc65216 --- /dev/null +++ b/.containerignore @@ -0,0 +1,14 @@ +/target +# nix build result +result +log +tmp/ +.git +.github +.gitignore +Containerfile +.containerignore +DEFAULT_LICENSE +flake.lock +flake.nix +README.md diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml new file mode 100644 index 0000000..058c9b7 --- /dev/null +++ b/.github/workflows/container.yml @@ -0,0 +1,73 @@ +name: build +on: + schedule: + - cron: "00 00 * * *" + workflow_dispatch: + +env: + IMAGE_NAME: crawlspace + IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }} + +jobs: + check-last-commit: + runs-on: ubuntu-24.04 + name: Check last commit date + outputs: + run-approved: ${{ steps.confirm-run.outputs.run-approved }} + steps: + - uses: actions/checkout@v2 + - id: confirm-run + continue-on-error: true + name: Check last commit is <24h old + if: ${{ github.event_name == 'schedule' }} + run: test -z $(git ref-list --after="24 hours" ${{ github.sha }}) && echo "::set-output name=run-approved::false" + + build-container: + name: Build and push container + runs-on: ubuntu-24.04 + permissions: + contents: read + packages: write + needs: check-last-commit + if: ${{ needs.check-last-commit.outputs.run-approved != 'false' }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Generate tag + id: generate-tags + run: | + echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + echo "date=$(date +%m%d%Y)" >> $GITHUB_OUTPUT + + - name: Image Metadata + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.IMAGE_NAME }} + labels: | + io.artifacthub.package.readme-url=https://raw.githubusercontent.com/xoogware/crawlspace/main/README.md + + - name: Build image + id: build + uses: redhat-actions/buildah-build@v2 + with: + containerfiles: | + ./Containerfile + image: ${{ env.IMAGE_NAME }} + labels: ${{ steps.meta.outputs.labels }} + oci: false + tags: | + ${{ steps.generate-tags.outputs.sha }} + ${{ steps.generate-tags.outputs.date }} + nightly + + - name: Push + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build.outputs.image }} + tags: ${{ steps.build.outputs.tags }} + registry: ${{ env.IMAGE_REGISTRY }} + username: ${{ github.actor }} + password: ${{ github.token }} + diff --git a/Cargo.toml b/Cargo.toml index bedd967..ded56e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ bitfield-struct = "0.9.2" byteorder = "1.5.0" bytes = "1.8.0" cfb8 = { version = "0.8.1", optional = true } -clap = { version = "4.5.20", features = ["derive"] } +clap = { version = "4.5.20", features = ["derive", "env"] } color-eyre = "0.6.3" fastanvil = { git = "https://github.com/owengage/fastnbt.git" } fastnbt = { git = "https://github.com/owengage/fastnbt.git" } @@ -53,3 +53,11 @@ lan = [] timings = [] full = ["compression", "encryption"] + +[profile.release-stripped] +inherits = "release" +strip = "symbols" + +[profile.release-lto] +inherits = "release-stripped" +lto = true diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..4a87b61 --- /dev/null +++ b/Containerfile @@ -0,0 +1,12 @@ +FROM rust:1.82 AS build + +WORKDIR /app +COPY . . + +RUN cargo build --profile release-lto --features compression + +FROM ubi9/ubi-micro +WORKDIR /app +COPY --from=build /app/target/release-lto/crawlspace . + +CMD ["/app/crawlspace"] diff --git a/README.md b/README.md index 23d225d..4fa5c8c 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ podman pull ghcr.io/xoogware/crawlspace:latest ``` then run with the world mounted read-only: ```bash -podman run --rm -v=./tmp/DIM1:/world:ro crawlspace -- /world +podman run --rm --read-only -v=./tmp/DIM1:/world:ro,Z -e="LIMBO_WORLD=/world" -p=8006:25565 crawlspace ``` # Configuration diff --git a/src/args.rs b/src/args.rs index 15167c2..4ee9653 100644 --- a/src/args.rs +++ b/src/args.rs @@ -22,28 +22,29 @@ use clap::Parser; #[derive(Debug, Parser)] pub struct Args { /// The directory to load the map from. Should be DIM1, or the equivalent renamed folder. + #[arg(env = "LIMBO_WORLD")] pub map_dir: String, /// The address to serve crawlspace on. - #[arg(short, long, default_value = "[::]")] + #[arg(short, long, default_value = "[::]", env = "LIMBO_ADDRESS")] pub addr: String, /// The port to serve crawlspace on. Defaults to 25565 if not set. - #[arg(short, long, default_value = "25565")] + #[arg(short, long, default_value = "25565", env = "LIMBO_PORT")] pub port: u16, /// The x coordinate of the spawnpoint. - #[arg(short = 'x', long, default_value = "0")] + #[arg(short = 'x', long, default_value = "0", env = "LIMBO_SPAWN_X")] pub spawn_x: f64, /// The y coordinate of the spawnpoint. - #[arg(short = 'y', long, default_value = "100")] + #[arg(short = 'y', long, default_value = "100", env = "LIMBO_SPAWN_Y")] pub spawn_y: f64, /// The z coordinate of the spawnpoint. - #[arg(short = 'z', long, default_value = "0")] + #[arg(short = 'z', long, default_value = "0", env = "LIMBO_SPAWN_Z")] pub spawn_z: f64, /// The border radius, centered around the spawnpoint. Defaults to 10 chunks. One /// chunk past the border will be loaded. - #[arg(short = 'b', long, default_value = "160")] + #[arg(short = 'b', long, default_value = "160", env = "LIMBO_BORDER_RADIUS")] pub border_radius: i32, #[arg(short, long, default_value = "Limbo")] pub motd: String, - #[arg(long, default_value = "500")] + #[arg(long, default_value = "500", env = "LIMBO_MAX_PLAYERS")] pub max_players: usize, } -- 2.51.2