diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..8d96444ec --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile +{ + "name": "Existing Dockerfile", + "build": { + // Sets the run context to one level up instead of the .devcontainer folder. + "context": "..", + // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. + "dockerfile": "../Dockerfile" + } + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment the next line to run commands after the container is created. + // "postCreateCommand": "cat /etc/os-release", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "devcontainer" +} diff --git a/.github/workflows/ci-image.yml b/.github/workflows/ci-image.yml new file mode 100644 index 000000000..5ea4440a1 --- /dev/null +++ b/.github/workflows/ci-image.yml @@ -0,0 +1,33 @@ +name: Build Dev Image CI + +on: + workflow_dispatch: + pull_request: + branches: + - main + push: + branches: + - "*" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and Push + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + push: false + build-args: | + VERSION=latest diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index bc1b41ad4..000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Lint -on: - push: - branches: - - main - pull_request: -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - run: rustup component add clippy - - uses: bufbuild/buf-setup-action@v1.17.0 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - - uses: actions-rs/clippy-check@v1 - name: Lint main workspace - with: - token: ${{ secrets.GITHUB_TOKEN }} - name: workspace - args: --all-features --no-deps - - uses: actions-rs/clippy-check@v1 - name: Lint xmtpv3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - name: xmtp - args: --all-features --no-deps --manifest-path xmtp/Cargo.toml diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..61ed5d475 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "rust-lang.rust-analyzer" + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..126d40da2 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,55 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "fmt", + "type": "shell", + "command": "cargo +nightly fmt --check", + "options": { + "cwd": "${workspaceFolder}" + }, + "group": { + "kind": "build", + "isDefault": "false" + } + }, + { + "label": "build", + "type": "shell", + "command": "cargo build", + "options": { + "cwd": "${workspaceFolder}" + }, + "group": { + "kind": "build", + "isDefault": "false" + } + }, + { + "label": "check", + "type": "shell", + "command": "cargo check", + "options": { + "cwd": "${workspaceFolder}" + }, + "group": { + "kind": "build", + "isDefault": "true" + } + }, + { + "label": "test", + "type": "shell", + "command": "cargo test", + "options": { + "cwd": "${workspaceFolder}" + }, + "group": { + "kind": "test", + "isDefault": "true" + } + } + ] +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..fb877a97e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,108 @@ +FROM debian:stable-slim as go-builder +# defined from build kit +# DOCKER_BUILDKIT=1 docker build . -t ... +ARG TARGETARCH + +FROM debian:stable-slim as builder +# defined from build kit +# DOCKER_BUILDKIT=1 docker build . -t ... +ARG TARGETARCH + +RUN export DEBIAN_FRONTEND=noninteractive && \ + apt update && \ + apt install -y -q --no-install-recommends \ + git curl gnupg2 build-essential \ + linux-headers-${TARGETARCH} libc6-dev \ + openssl libssl-dev pkg-config \ + ca-certificates apt-transport-https \ + python3 && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* + +RUN useradd --create-home -s /bin/bash xmtp +RUN usermod -a -G sudo xmtp +RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers + +WORKDIR /rustup +## Rust +ADD https://sh.rustup.rs /rustup/rustup.sh +RUN chmod 755 /rustup/rustup.sh + +ENV USER=xmtp +USER xmtp +RUN /rustup/rustup.sh -y --default-toolchain stable --profile minimal + +ENV PATH=$PATH:~xmtp/.cargo/bin + +FROM debian:stable-slim +ARG TARGETARCH + +RUN export DEBIAN_FRONTEND=noninteractive && \ + apt update && \ + apt install -y -q --no-install-recommends \ + ca-certificates apt-transport-https \ + sudo ripgrep procps build-essential \ + python3 python3-pip python3-dev \ + git curl && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* + +RUN echo "building platform $(uname -m)" + +RUN useradd --create-home -s /bin/bash xmtp +RUN usermod -a -G sudo xmtp +RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers + +## Node and NPM +RUN mkdir -p /usr/local/nvm +ENV NVM_DIR=/usr/local/nvm + +ENV NODE_VERSION=v20.9.0 + +ADD https://raw.githubusercontent.com/creationix/nvm/master/install.sh /usr/local/etc/nvm/install.sh +RUN bash /usr/local/etc/nvm/install.sh && \ + bash -c ". $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm alias default $NODE_VERSION && nvm use default" + +ENV NVM_NODE_PATH ${NVM_DIR}/versions/node/${NODE_VERSION} +ENV NODE_PATH ${NVM_NODE_PATH}/lib/node_modules +ENV PATH ${NVM_NODE_PATH}/bin:$PATH + +RUN npm install npm -g +RUN npm install yarn -g + + +## Rust from builder +COPY --chown=xmtp:xmtp --from=builder /home/xmtp/.cargo /home/xmtp/.cargo +COPY --chown=xmtp:xmtp --from=builder /home/xmtp/.rustup /home/xmtp/.rustup + +USER xmtp + +# fmt coming from nightly +RUN ~xmtp/.cargo/bin/rustup toolchain install nightly +RUN ~xmtp/.cargo/bin/rustup component add rustfmt --toolchain nightly +RUN ~xmtp/.cargo/bin/rustup component add clippy + +WORKDIR /workspaces/libxmtp +COPY --chown=xmtp:xmtp . . + +ENV PATH=~xmtp/.cargo/bin:$PATH +ENV USER=xmtp + +RUN ~xmtp/.cargo/bin/cargo check +RUN ~xmtp/.cargo/bin/cargo +nightly --version +RUN ~xmtp/.cargo/bin/cargo +nightly fmt --check +RUN ~xmtp/.cargo/bin/cargo clippy --all-features --no-deps +RUN ~xmtp/.cargo/bin/cargo clippy --all-features --no-deps --manifest-path xmtp/Cargo.toml +# some tests are setup as integration tests 👀 xmtp_mls +RUN for crate in xmtp xmtp_api_grpc xmtp_api_grpc_gateway xmtp_cryptography xmtp_proto xmtp_v2; do cd ${crate}; ~xmtp/.cargo/bin/cargo test; done + +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="rustdev" \ + org.label-schema.description="Rust Development Container" \ + org.label-schema.url="https://github.com/xmtp/libxmtp" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url="git@github.com:xmtp/libxmtp.git" \ + org.label-schema.vendor="xmtp" \ + org.label-schema.version=$VERSION \ + org.label-schema.schema-version="1.0" \ + org.opencontainers.image.description="Rust Development Container" \ No newline at end of file diff --git a/README.md b/README.md index 2122eea29..242de9b60 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,20 @@ Start Docker Desktop. dev/test ``` +## Quick Start (Dev Containers) + +This project supports containerized development. From Visual Studio Code Dev Containers extension specify the Dockerfile as the target: + +`Reopen in Container` + +or + +Command line build using docker + +```bash +$ docker build . -t libxmtp:1 +``` + ## Structure - [`xmtp`](https://github.com/xmtp/libxmtp/tree/main/xmtp): Pure Rust implementation of XMTP APIs, agnostic to any per-language or per-platform binding diff --git a/xmtp_v2/src/signature.rs b/xmtp_v2/src/signature.rs index 9e30490b6..e4e7249e4 100644 --- a/xmtp_v2/src/signature.rs +++ b/xmtp_v2/src/signature.rs @@ -47,9 +47,8 @@ impl traits::SignatureVerifier for PublicKey { verifying_key .verify_digest(digest, &signature) .map_err(|e| e.to_string()) - } - // The idea for unsupported types is to uncomment this catch-all - // _ => Err("Unsupported signature type for k256 public key".to_string()), + } /* The idea for unsupported types is to uncomment this catch-all + * _ => Err("Unsupported signature type for k256 public key".to_string()), */ } } }