From fd706c13bfa7d725176a5bcc7c4359c526863dbc Mon Sep 17 00:00:00 2001 From: Aykut Bozkurt Date: Tue, 8 Oct 2024 12:42:01 +0300 Subject: [PATCH] Adds dev container --- .devcontainer/Dockerfile | 68 ++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 25 ++++++++++ .devcontainer/scripts/setup-minio.sh | 7 +++ 3 files changed, 100 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/scripts/setup-minio.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..3c7095b --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,68 @@ +FROM ubuntu:22.04 + +ENV DEBIAN_FRONTEND="noninteractive" +ENV TZ="Europe/Istanbul" + +ARG PG_MAJOR=17 + +# install deps +RUN apt-get update && apt-get -y install build-essential libreadline-dev zlib1g-dev \ + flex bison libxml2-dev libxslt-dev libssl-dev \ + libxml2-utils xsltproc ccache pkg-config wget \ + curl lsb-release sudo nano net-tools git awscli + +# install Postgres +RUN sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' +RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - +RUN apt-get update && apt-get -y install postgresql-${PG_MAJOR}-postgis-3 \ + postgresql-server-dev-${PG_MAJOR} \ + postgresql-client-${PG_MAJOR} \ + libpq-dev + +# download and install MinIO server and client +RUN wget https://dl.min.io/server/minio/release/linux-amd64/minio +RUN chmod +x minio +RUN mv minio /usr/local/bin/minio + +# download and install MinIO admin +RUN wget https://dl.min.io/client/mc/release/linux-amd64/mc +RUN chmod +x mc +RUN mv mc /usr/local/bin/mc + +# set up pgrx with non-sudo user +ARG USERNAME=rust +ARG USER_UID=1000 +ARG USER_GID=$USER_UID +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -s /bin/bash -m $USERNAME + +RUN mkdir /workspaces && chown -R $USER_UID:$USER_GID /workspaces + +# set up permissions so that the user below can create extensions +RUN chmod a+rwx `pg_config --pkglibdir` \ + `pg_config --sharedir`/extension \ + /var/run/postgresql/ + +# add it to sudoers +RUN echo "$USERNAME ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USERNAME + +# now it is time to switch to user +USER $USERNAME + +# install Rust environment +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y +ENV PATH="/home/rust/.cargo/bin:${PATH}" + +# install and configure pgrx +ARG PGRX_VERSION=0.12.5 +RUN cargo install --locked cargo-pgrx@${PGRX_VERSION} +RUN cargo pgrx init --pg${PG_MAJOR} $(which pg_config) +RUN echo "shared_preload_libraries = 'pg_parquet'" >> $HOME/.pgrx/data-${PG_MAJOR}/postgresql.conf + +ENV MINIO_ROOT_USER=admin +ENV MINIO_ROOT_PASSWORD=admin123 +ENV AWS_S3_TEST_BUCKET=testbucket +ENV AWS_REGION=us-east-1 +ENV AWS_ACCESS_KEY_ID=admin +ENV AWS_SECRET_ACCESS_KEY=admin123 +ENV PG_PARQUET_TEST=true diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..efdd2d9 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,25 @@ +{ + "build": { + "dockerfile": "Dockerfile" + }, + "customizations": { + "vscode": { + "extensions": [ + "vadimcn.vscode-lldb", + "GitHub.copilot", + "eamodio.gitlens", + "bradymholt.pgformatter", + "rust-lang.rust-analyzer", + "ms-vscode.cpptools", + "henriiik.docker-linter" + ] + } + }, + "postStartCommand": "bash .devcontainer/scripts/setup-minio.sh", + "forwardPorts": [ + 5432 + ], + "capAdd": [ + "SYS_PTRACE" + ] +} diff --git a/.devcontainer/scripts/setup-minio.sh b/.devcontainer/scripts/setup-minio.sh new file mode 100644 index 0000000..d611b70 --- /dev/null +++ b/.devcontainer/scripts/setup-minio.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +nohup minio server /tmp/minio-storage > /dev/null 2>&1 & + +mc alias set local http://localhost:9000 $MINIO_ROOT_USER $MINIO_ROOT_PASSWORD + +aws --endpoint-url http://localhost:9000 s3 mb s3://testbucket