diff --git a/.github/workflows/build-nix-image.yml b/.github/workflows/build-nix-image.yml new file mode 100644 index 0000000000..6554cf6c08 --- /dev/null +++ b/.github/workflows/build-nix-image.yml @@ -0,0 +1,101 @@ +name: Build Nix Docker image + +on: + push: + branches: + - develop + paths: + - ".github/workflows/build-nix-image.yml" + - "docker/nix.Dockerfile" + - "flake.nix" + - "flake.lock" + - "nix/**" + pull_request: + paths: + - ".github/workflows/build-nix-image.yml" + - "docker/nix.Dockerfile" + - "flake.nix" + - "flake.lock" + - "nix/**" + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +defaults: + run: + shell: bash + +env: + UBUNTU_VERSION: "20.04" + RHEL_VERSION: "9" + DEBIAN_VERSION: "bookworm" + +jobs: + build: + name: Build and push Nix image (${{ matrix.distro }}) + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + matrix: + include: + - distro: nixos + - distro: ubuntu + - distro: rhel + - distro: debian + + steps: + - name: Checkout repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Determine base image + id: vars + run: | + case "${{ matrix.distro }}" in + nixos) + echo "base_image=nixos/nix:latest" >> $GITHUB_OUTPUT + ;; + ubuntu) + echo "base_image=ubuntu:${UBUNTU_VERSION}" >> $GITHUB_OUTPUT + ;; + rhel) + echo "base_image=registry.access.redhat.com/ubi${RHEL_VERSION}/ubi:latest" >> $GITHUB_OUTPUT + ;; + debian) + echo "base_image=debian:${DEBIAN_VERSION}" >> $GITHUB_OUTPUT + ;; + esac + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 + + - name: Login to GitHub Container Registry + if: github.event_name == 'push' + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker metadata + id: meta + uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0 + with: + images: ghcr.io/xrplf/ci/nix-${{ matrix.distro }} + tags: | + type=sha,prefix=sha-,format=short + type=raw,value=latest + + - name: Build and push + uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0 + with: + context: . + file: docker/nix.Dockerfile + platforms: linux/amd64 + push: ${{ github.event_name == 'push' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: BASE_IMAGE=${{ steps.vars.outputs.base_image }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1c0dc94550..1313ad567c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -70,7 +70,11 @@ repos: rev: a42085ade523f591dca134379a595e7859986445 # frozen: v9.7.0 hooks: - id: cspell # Spell check changed files - exclude: (.config/cspell.config.yaml|^include/xrpl/protocol_autogen/(transactions|ledger_entries)/) + exclude: | + (?x)^( + .config/cspell.config.yaml| + include/xrpl/protocol_autogen/(transactions|ledger_entries)/.* + )$ - id: cspell # Spell check the commit message name: check commit message spelling args: diff --git a/cspell.config.yaml b/cspell.config.yaml index 8b8589a8c9..34482d9d8f 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -63,6 +63,7 @@ words: - Bougalis - Britto - Btrfs + - Buildx - canonicality - changespq - checkme diff --git a/docker/nix.Dockerfile b/docker/nix.Dockerfile new file mode 100644 index 0000000000..52faa8b8dc --- /dev/null +++ b/docker/nix.Dockerfile @@ -0,0 +1,66 @@ +ARG BASE_IMAGE=nixos/nix:latest + +# Nix builder +FROM nixos/nix:latest AS builder-source + +RUN mkdir -p ~/.config/nix && \ + echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf + +# Copy our source and setup our working dir. +COPY nix/ci-env.nix /tmp/build/nix/ci-env.nix +COPY nix/packages.nix /tmp/build/nix/packages.nix +COPY nix/utils.nix /tmp/build/nix/utils.nix +COPY flake.nix /tmp/build/ +COPY flake.lock /tmp/build/ +WORKDIR /tmp/build + +FROM builder-source AS builder + +# Build our Nix CI environment (all build tools in a single store path) +RUN nix \ + --option filter-syscalls false \ + build + +# Copy the Nix store closure into a directory. The Nix store closure is the +# entire set of Nix store values that we need for our build. +RUN mkdir /tmp/nix-store-closure && \ + cp -R $(nix-store -qR result/) /tmp/nix-store-closure + +# Final image +FROM ${BASE_IMAGE} + +# bash is not located at /bin/bash in nixos/nix, so we need to create a symlink to it. +RUN if [ -d /nix ]; then \ + ln -s /root/.nix-profile/bin/bash /bin/bash; \ + fi + +# Use Bash as the default shell for RUN commands, using the options +# `set -o errexit -o pipefail`, and as the entrypoint. +SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"] +ENTRYPOINT ["/bin/bash"] + +# Copy /nix/store and the env symlink tree +COPY --from=builder /tmp/nix-store-closure /nix/store +COPY --from=builder /tmp/build/result /nix/ci-env + +ENV PATH="/nix/ci-env/bin:$PATH" + +RUN <