From e14b507b0ac560bf3c746e93c3e838c694c4f6d3 Mon Sep 17 00:00:00 2001 From: Andrei Marcut Date: Wed, 8 May 2024 20:09:31 +0000 Subject: [PATCH] initial dev container for building on macos with arm cpu --- .env | 6 +++++ .gitignore | 1 + Dockerfile | 62 +++++++++++++++++++++++++--------------------- Dockerfile.backup | 37 +++++++++++++++++++++++++++ devcontainer.json | 6 +++++ docker-compose.yml | 9 +++++++ 6 files changed, 93 insertions(+), 28 deletions(-) create mode 100644 .env create mode 100644 Dockerfile.backup create mode 100644 devcontainer.json create mode 100644 docker-compose.yml diff --git a/.env b/.env new file mode 100644 index 00000000..dca08295 --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +UBUNTU_VERSION=20.04 +USER_NAME=developer +USER_HOME=/home/developer +PROJECT_NAME=rencfs + +PROJECT_HOME=${USER_HOME}/${PROJECT_NAME} \ No newline at end of file diff --git a/.gitignore b/.gitignore index ea8c4bf7..3a8cabc9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.idea diff --git a/Dockerfile b/Dockerfile index 5dbb4f74..f99c6e3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,37 +1,43 @@ -################ -##### Builder -FROM alpine:3.16.0 as builder +# Use an argument to specify the Ubuntu version, with a default +ARG UBUNTU_VERSION=20.04 -RUN apk add binutils build-base ca-certificates curl file g++ gcc libressl-dev make patch rust +# Use the specified Ubuntu version from the .env file +FROM ubuntu:${UBUNTU_VERSION} -RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +ARG USER_NAME=developer +ARG USER_HOME=/home/developer +ARG PROJECT_NAME=rencfs + +ENV USER_NAME=${USER_NAME} +ENV USER_HOME=${USER_HOME} +ENV PROJECT_NAME=${PROJECT_NAME} -RUN . ~/.cargo/env && rustup target add x86_64-unknown-linux-musl +ENV DEBIAN_FRONTEND=noninteractive -# Cache downloaded+built dependencies -#COPY Cargo.toml Cargo.lock /usr/src/rencfs/ -#RUN mkdir /usr/src/rencfs/src && \ -# echo 'fn main() {}' > /usr/src/rencfs/src/main.rs -# -#RUN . ~/.cargo/env && cd /usr/src/rencfs/ && cargo build --release && \ -# rm -Rvf /usr/src/rencfs/src +RUN apt-get update && apt-get install -y \ + sudo \ + git \ + curl \ + gcc \ + pkg-config \ + build-essential \ + libssl-dev \ + fuse3 -# Build our actual code -COPY Cargo.toml Cargo.lock /usr/src/rencfs/ -COPY src /usr/src/rencfs/src -RUN touch /usr/src/rencfs/src/main.rs -RUN . ~/.cargo/env && \ - cd /usr/src/rencfs/ && \ - cargo build --target x86_64-unknown-linux-musl --release +RUN useradd -m -s /bin/bash -d ${USER_HOME} ${USER_NAME} \ + && echo "${USER_NAME} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/${USER_NAME} \ + && chmod 0440 /etc/sudoers.d/${USER_NAME} -################ -##### Runtime -FROM alpine:3.16.0 AS runtime +# Switch to the new user +USER ${USER_NAME} +WORKDIR ${USER_HOME} + +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -RUN apk add fuse3 +# Set the environment variables needed for Rust +ENV PATH="${USER_HOME}/.cargo/bin:${PATH}" -# Copy application binary from builder image -COPY --from=builder /usr/src/rencfs/target/x86_64-unknown-linux-musl/release/rencfs /usr/local/bin +WORKDIR ${USER_HOME}/${PROJECT_NAME} -# Run the application -CMD ["rencfs", "--help"] +# Command to keep the container running +CMD ["sleep", "infinity"] diff --git a/Dockerfile.backup b/Dockerfile.backup new file mode 100644 index 00000000..5dbb4f74 --- /dev/null +++ b/Dockerfile.backup @@ -0,0 +1,37 @@ +################ +##### Builder +FROM alpine:3.16.0 as builder + +RUN apk add binutils build-base ca-certificates curl file g++ gcc libressl-dev make patch rust + +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + +RUN . ~/.cargo/env && rustup target add x86_64-unknown-linux-musl + +# Cache downloaded+built dependencies +#COPY Cargo.toml Cargo.lock /usr/src/rencfs/ +#RUN mkdir /usr/src/rencfs/src && \ +# echo 'fn main() {}' > /usr/src/rencfs/src/main.rs +# +#RUN . ~/.cargo/env && cd /usr/src/rencfs/ && cargo build --release && \ +# rm -Rvf /usr/src/rencfs/src + +# Build our actual code +COPY Cargo.toml Cargo.lock /usr/src/rencfs/ +COPY src /usr/src/rencfs/src +RUN touch /usr/src/rencfs/src/main.rs +RUN . ~/.cargo/env && \ + cd /usr/src/rencfs/ && \ + cargo build --target x86_64-unknown-linux-musl --release + +################ +##### Runtime +FROM alpine:3.16.0 AS runtime + +RUN apk add fuse3 + +# Copy application binary from builder image +COPY --from=builder /usr/src/rencfs/target/x86_64-unknown-linux-musl/release/rencfs /usr/local/bin + +# Run the application +CMD ["rencfs", "--help"] diff --git a/devcontainer.json b/devcontainer.json new file mode 100644 index 00000000..1f9e4639 --- /dev/null +++ b/devcontainer.json @@ -0,0 +1,6 @@ +{ + "name": "rencfs docker development environment", + "dockerComposeFile": "docker-compose.yml", + "service": "rencfs-development-environment", + "shutdownAction": "stopCompose" +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..b59cbc7a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + rencfs-development-environment: + build: + context: . + dockerfile: Dockerfile + image: local-rencfs-developer + user: ${USER_NAME} + volumes: + - .:/home/developer/rencfs \ No newline at end of file