From 0469a15e195f4f4ee39279ae6485840f885bc7d4 Mon Sep 17 00:00:00 2001 From: John Cairns Date: Fri, 3 Nov 2023 16:50:36 -0500 Subject: [PATCH] 312: introduce remote container development environment --- .devcontainer/devcontainer.json | 26 ++++++++++++ Dockerfile | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 Dockerfile 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/Dockerfile b/Dockerfile new file mode 100644 index 000000000..c2b73fbbe --- /dev/null +++ b/Dockerfile @@ -0,0 +1,72 @@ +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 '%xmtp 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 && \ + 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 + +## Rust +COPY --chown=xmtp:xmtp --from=builder /home/xmtp/.cargo /home/xmtp/.cargo +COPY --chown=xmtp:xmtp --from=builder /home/xmtp/.rustup /home/xmtp/.rustup + +ENV PATH=/home/xmtp/.cargo/bin:$PATH + +USER xmtp + +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