From c73017304d7246ef4f7b635d837948d153ac70a1 Mon Sep 17 00:00:00 2001 From: Pavlo Golub Date: Fri, 12 Dec 2025 14:23:58 +0100 Subject: [PATCH] chore: improve DevContainer setup - use rust-bookwork dockerfile - do not install postgres - move cargo init to postCreateCommand --- .devcontainer/Dockerfile | 71 +++++++++++++-------------------- .devcontainer/devcontainer.json | 36 +++++++++-------- 2 files changed, 47 insertions(+), 60 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index d9177d9..ccedbe8 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,57 +1,40 @@ -FROM debian:bookworm-slim +FROM rust:1-bookworm ENV DEBIAN_FRONTEND=noninteractive -ENV PG_MAJOR=17 # Install system dependencies -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - ca-certificates curl gnupg apt-transport-https \ - build-essential git pkg-config \ - libreadline-dev zlib1g-dev flex bison \ - libxml2-dev libxslt-dev libssl-dev \ - libxml2-utils xsltproc ccache \ - clang libclang-dev \ - protobuf-compiler libprotobuf-dev \ - sudo \ - && update-ca-certificates \ - && sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list' \ - && curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg \ - && apt-get update \ - && apt-get install -y --no-install-recommends \ - postgresql-$PG_MAJOR \ - postgresql-server-dev-$PG_MAJOR \ - postgresql-common \ - && apt-get clean \ +RUN apt-get update && apt-get install -y \ + build-essential \ + bison \ + flex \ + clang \ + protobuf-compiler \ + libreadline8 \ + libreadline-dev \ + git \ + curl \ + pkg-config \ + libssl-dev \ + sudo \ && rm -rf /var/lib/apt/lists/* -# Create vscode user with sudo access -RUN groupadd --gid 1000 vscode \ - && useradd --uid 1000 --gid 1000 -m -s /bin/bash vscode \ - && echo "vscode ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/vscode \ - && chmod 0440 /etc/sudoers.d/vscode \ - && chown -R vscode:vscode /usr/share/postgresql /usr/lib/postgresql +# Create a non-root user for running PostgreSQL +RUN useradd -m -s /bin/bash -u 1000 vscode && \ + echo "vscode ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers -# Switch to vscode user +# Switch to non-root user USER vscode -WORKDIR /home/vscode -# Set up Rust environment for vscode user -ENV RUSTUP_HOME=/home/vscode/.rustup -ENV CARGO_HOME=/home/vscode/.cargo -ENV PATH="/home/vscode/.cargo/bin:/usr/lib/postgresql/$PG_MAJOR/bin:${PATH}" +# Set up Rust and cargo for vscode user +ENV PATH="/home/vscode/.cargo/bin:${PATH}" +ENV CARGO_HOME="/home/vscode/.cargo" -# Install Rust -RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable \ - && . "$CARGO_HOME/env" \ - && rustup component add clippy rustfmt rust-src - -# Install cargo-pgrx +# Install pgrx as vscode user ENV CARGO_PGRX_VERSION=0.16.1 -RUN . "$CARGO_HOME/env" \ - && cargo install --force --locked cargo-pgrx@"${CARGO_PGRX_VERSION}" +RUN cargo install --force --locked cargo-pgrx@"${CARGO_PGRX_VERSION}" -# Initialize pgrx -RUN . "$CARGO_HOME/env" \ - && cargo pgrx init --pg$PG_MAJOR $(which pg_config) +# Set working directory +WORKDIR /workspace +# Keep container running +CMD ["sleep", "infinity"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a31de34..bdcb351 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,28 +1,32 @@ { - "name": "rust-dev", + "name": "etcd_fdw Development", "build": { - "dockerfile": "Dockerfile" - }, - "features": { - "ghcr.io/devcontainers/features/common-utils:2": {}, - "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}, - "ghcr.io/devcontainers/features/git:1": {}, - "ghcr.io/devcontainers/features/github-cli:1": {} + "dockerfile": "Dockerfile", + "context": "." }, "customizations": { "vscode": { - "settings": { - "terminal.integrated.shell.linux": "/bin/bash" - }, "extensions": [ "rust-lang.rust-analyzer", - "fill-labs.dependi", + "tamasfe.even-better-toml", + "vadimcn.vscode-lldb", "mk12.better-git-line-blame" - ] + ], + "settings": { + "rust-analyzer.cargo.features": "all", + "rust-analyzer.check.command": "clippy" + } } }, - "remoteUser": "vscode", "mounts": [ - "source=cargo-registry,target=/usr/local/cargo/registry,type=volume" - ] + "source=etcd-fdw-cargo-cache,target=/home/vscode/.cargo/registry,type=volume" + ], + "postCreateCommand": "cargo pgrx init --pg17 download && cargo build", + "remoteUser": "vscode", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": {}, + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}, + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers/features/github-cli:1": {} + } } \ No newline at end of file