Skip to content

Commit c73ed48

Browse files
authored
chore: improve DevContainer setup (#30)
- use rust-bookwork dockerfile - do not install postgres - move cargo init to postCreateCommand
1 parent c332920 commit c73ed48

2 files changed

Lines changed: 47 additions & 60 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,40 @@
1-
FROM debian:bookworm-slim
1+
FROM rust:1-bookworm
22

33
ENV DEBIAN_FRONTEND=noninteractive
4-
ENV PG_MAJOR=17
54

65
# Install system dependencies
7-
RUN apt-get update \
8-
&& apt-get install -y --no-install-recommends \
9-
ca-certificates curl gnupg apt-transport-https \
10-
build-essential git pkg-config \
11-
libreadline-dev zlib1g-dev flex bison \
12-
libxml2-dev libxslt-dev libssl-dev \
13-
libxml2-utils xsltproc ccache \
14-
clang libclang-dev \
15-
protobuf-compiler libprotobuf-dev \
16-
sudo \
17-
&& update-ca-certificates \
18-
&& sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list' \
19-
&& curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg \
20-
&& apt-get update \
21-
&& apt-get install -y --no-install-recommends \
22-
postgresql-$PG_MAJOR \
23-
postgresql-server-dev-$PG_MAJOR \
24-
postgresql-common \
25-
&& apt-get clean \
6+
RUN apt-get update && apt-get install -y \
7+
build-essential \
8+
bison \
9+
flex \
10+
clang \
11+
protobuf-compiler \
12+
libreadline8 \
13+
libreadline-dev \
14+
git \
15+
curl \
16+
pkg-config \
17+
libssl-dev \
18+
sudo \
2619
&& rm -rf /var/lib/apt/lists/*
2720

28-
# Create vscode user with sudo access
29-
RUN groupadd --gid 1000 vscode \
30-
&& useradd --uid 1000 --gid 1000 -m -s /bin/bash vscode \
31-
&& echo "vscode ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/vscode \
32-
&& chmod 0440 /etc/sudoers.d/vscode \
33-
&& chown -R vscode:vscode /usr/share/postgresql /usr/lib/postgresql
21+
# Create a non-root user for running PostgreSQL
22+
RUN useradd -m -s /bin/bash -u 1000 vscode && \
23+
echo "vscode ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
3424

35-
# Switch to vscode user
25+
# Switch to non-root user
3626
USER vscode
37-
WORKDIR /home/vscode
3827

39-
# Set up Rust environment for vscode user
40-
ENV RUSTUP_HOME=/home/vscode/.rustup
41-
ENV CARGO_HOME=/home/vscode/.cargo
42-
ENV PATH="/home/vscode/.cargo/bin:/usr/lib/postgresql/$PG_MAJOR/bin:${PATH}"
28+
# Set up Rust and cargo for vscode user
29+
ENV PATH="/home/vscode/.cargo/bin:${PATH}"
30+
ENV CARGO_HOME="/home/vscode/.cargo"
4331

44-
# Install Rust
45-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable \
46-
&& . "$CARGO_HOME/env" \
47-
&& rustup component add clippy rustfmt rust-src
48-
49-
# Install cargo-pgrx
32+
# Install pgrx as vscode user
5033
ENV CARGO_PGRX_VERSION=0.16.1
51-
RUN . "$CARGO_HOME/env" \
52-
&& cargo install --force --locked cargo-pgrx@"${CARGO_PGRX_VERSION}"
34+
RUN cargo install --force --locked cargo-pgrx@"${CARGO_PGRX_VERSION}"
5335

54-
# Initialize pgrx
55-
RUN . "$CARGO_HOME/env" \
56-
&& cargo pgrx init --pg$PG_MAJOR $(which pg_config)
36+
# Set working directory
37+
WORKDIR /workspace
5738

39+
# Keep container running
40+
CMD ["sleep", "infinity"]

.devcontainer/devcontainer.json

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
{
2-
"name": "rust-dev",
2+
"name": "etcd_fdw Development",
33
"build": {
4-
"dockerfile": "Dockerfile"
5-
},
6-
"features": {
7-
"ghcr.io/devcontainers/features/common-utils:2": {},
8-
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
9-
"ghcr.io/devcontainers/features/git:1": {},
10-
"ghcr.io/devcontainers/features/github-cli:1": {}
4+
"dockerfile": "Dockerfile",
5+
"context": "."
116
},
127
"customizations": {
138
"vscode": {
14-
"settings": {
15-
"terminal.integrated.shell.linux": "/bin/bash"
16-
},
179
"extensions": [
1810
"rust-lang.rust-analyzer",
19-
"fill-labs.dependi",
11+
"tamasfe.even-better-toml",
12+
"vadimcn.vscode-lldb",
2013
"mk12.better-git-line-blame"
21-
]
14+
],
15+
"settings": {
16+
"rust-analyzer.cargo.features": "all",
17+
"rust-analyzer.check.command": "clippy"
18+
}
2219
}
2320
},
24-
"remoteUser": "vscode",
2521
"mounts": [
26-
"source=cargo-registry,target=/usr/local/cargo/registry,type=volume"
27-
]
22+
"source=etcd-fdw-cargo-cache,target=/home/vscode/.cargo/registry,type=volume"
23+
],
24+
"postCreateCommand": "cargo pgrx init --pg17 download && cargo build",
25+
"remoteUser": "vscode",
26+
"features": {
27+
"ghcr.io/devcontainers/features/common-utils:2": {},
28+
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
29+
"ghcr.io/devcontainers/features/git:1": {},
30+
"ghcr.io/devcontainers/features/github-cli:1": {}
31+
}
2832
}

0 commit comments

Comments
 (0)