Skip to content

Commit

Permalink
initial dev container for building on macos with arm cpu
Browse files Browse the repository at this point in the history
  • Loading branch information
andreimarcut committed May 8, 2024
1 parent c2cdc5e commit e14b507
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 28 deletions.
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UBUNTU_VERSION=20.04
USER_NAME=developer
USER_HOME=/home/developer
PROJECT_NAME=rencfs

PROJECT_HOME=${USER_HOME}/${PROJECT_NAME}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.idea
62 changes: 34 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
37 changes: 37 additions & 0 deletions Dockerfile.backup
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 6 additions & 0 deletions devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "rencfs docker development environment",
"dockerComposeFile": "docker-compose.yml",
"service": "rencfs-development-environment",
"shutdownAction": "stopCompose"
}
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
rencfs-development-environment:
build:
context: .
dockerfile: Dockerfile
image: local-rencfs-developer
user: ${USER_NAME}
volumes:
- .:/home/developer/rencfs

0 comments on commit e14b507

Please sign in to comment.