Merge pull request #1045 from andre-richter/docker_rework
Rework Docker
This commit is contained in:
commit
e4191db3f0
3
docker/.bash_aliases
Normal file
3
docker/.bash_aliases
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Hijack this file to set this PS1, visually indicating to the user that we are running the docker container
|
||||||
|
|
||||||
|
PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[1;35m\]<$IMAGE_NAME>\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
|
|
@ -1,47 +1,39 @@
|
||||||
FROM ubuntu:17.04
|
FROM rustlang/rust:nightly
|
||||||
|
|
||||||
ENV USER user
|
ENV IMAGE_NAME=redox-os-docker
|
||||||
ARG LOCAL_UID=local
|
|
||||||
ARG LOCAL_GID=local
|
|
||||||
ENV BUILD_UID=${LOCAL_UID:-9001}
|
|
||||||
ENV BUILD_GID=${LOCAL_GID:-9001}
|
|
||||||
|
|
||||||
RUN apt-get update \
|
RUN set -ex; \
|
||||||
&& apt-get install -y dirmngr git gosu gcc fuse nasm qemu-utils pkg-config \
|
apt-get update; \
|
||||||
libfuse-dev make curl wget file sudo apt-transport-https autoconf flex \
|
apt-get install -q -y --no-install-recommends \
|
||||||
bison texinfo \
|
apt-transport-https \
|
||||||
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA12E97F0881517F \
|
bison \
|
||||||
&& echo "deb https://static.redox-os.org/toolchain/apt/ /" >> /etc/apt/sources.list.d/redox.list \
|
flex \
|
||||||
&& apt-get update -o Dir::Etc::sourcelist="redox.list" \
|
fuse \
|
||||||
&& apt-get install -y x86-64-unknown-redox-newlib x86-64-unknown-redox-binutils x86-64-unknown-redox-gcc \
|
gosu \
|
||||||
&& if [ $BUILD_UID != local ] && [ $BUILD_GID != local ]; then \
|
libfuse-dev \
|
||||||
groupadd -g $BUILD_GID user; \
|
nasm \
|
||||||
useradd --shell /bin/bash -u $BUILD_UID -g $BUILD_GID -o -c "" -m $USER; \
|
qemu-utils \
|
||||||
else \
|
sudo \
|
||||||
useradd --shell /bin/bash -c "" -m $USER; \
|
texinfo \
|
||||||
fi \
|
git \
|
||||||
&& echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/user-no-sudo-password
|
; \
|
||||||
|
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA12E97F0881517F; \
|
||||||
|
echo "deb https://static.redox-os.org/toolchain/apt/ /" >> \
|
||||||
|
/etc/apt/sources.list.d/redox.list; \
|
||||||
|
apt-get update -o Dir::Etc::sourcelist="redox.list"; \
|
||||||
|
apt-get install -q -y --no-install-recommends \
|
||||||
|
x86-64-unknown-redox-newlib \
|
||||||
|
x86-64-unknown-redox-binutils \
|
||||||
|
x86-64-unknown-redox-gcc \
|
||||||
|
; \
|
||||||
|
cargo install xargo; \
|
||||||
|
cargo install cargo-config; \
|
||||||
|
apt-get autoremove -q -y; \
|
||||||
|
apt-get clean -q -y; \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
COPY entrypoint.sh /usr/local/bin/
|
||||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
COPY .bash_aliases /etc/skel/
|
||||||
|
|
||||||
USER $USER
|
ENTRYPOINT ["bash", "/usr/local/bin/entrypoint.sh"]
|
||||||
ENV HOME /home/$USER
|
CMD ["/bin/bash"]
|
||||||
ENV PATH $HOME/.cargo/bin:$PATH
|
|
||||||
ENV SRC_PATH $HOME/src
|
|
||||||
WORKDIR $HOME
|
|
||||||
RUN curl https://sh.rustup.rs > sh.rustup.rs \
|
|
||||||
&& sh sh.rustup.rs -y \
|
|
||||||
&& rustup update \
|
|
||||||
&& rustup component add rust-src \
|
|
||||||
&& rustup default nightly \
|
|
||||||
&& curl -O https://ftp.gnu.org/gnu/automake/automake-1.15.1.tar.gz \
|
|
||||||
&& tar -xvpf automake-1.15.1.tar.gz; cd automake-1.15.1; ./configure; make; sudo make install; cd .. \
|
|
||||||
&& cargo install xargo \
|
|
||||||
&& cargo install cargo-config \
|
|
||||||
&& mkdir -p $SRC_PATH
|
|
||||||
|
|
||||||
WORKDIR $SRC_PATH
|
|
||||||
USER root
|
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
|
||||||
|
|
|
@ -12,15 +12,10 @@ git clone https://github.com/redox-os/redox.git ; cd redox
|
||||||
```
|
```
|
||||||
|
|
||||||
### Build the container
|
### Build the container
|
||||||
This will prepare an Ubuntu 17.04 docker image with the required
|
This will prepare a docker image with the required dependencies and
|
||||||
dependencies and the pre-built toolchain. As long as you rely on this particular
|
the pre-built toolchain. As long as you rely on this particular
|
||||||
dependencies and toolchain versions, you don't need to rebuild the container.
|
dependencies and toolchain versions, you don't need to rebuild the
|
||||||
#### Linux
|
container.
|
||||||
```shell
|
|
||||||
docker build --build-arg LOCAL_UID="$(id -u)" --build-arg LOCAL_GID="$(id -g)" \
|
|
||||||
-t redox docker/
|
|
||||||
```
|
|
||||||
#### MacOS
|
|
||||||
```shell
|
```shell
|
||||||
docker build -t redox docker/
|
docker build -t redox docker/
|
||||||
```
|
```
|
||||||
|
@ -34,12 +29,12 @@ git pull --rebase --recurse-submodules && git submodule sync \
|
||||||
```
|
```
|
||||||
|
|
||||||
### Run the container to build Redox
|
### Run the container to build Redox
|
||||||
#### Linux without security modules
|
|
||||||
```shell
|
```shell
|
||||||
docker run --cap-add MKNOD --cap-add SYS_ADMIN --device /dev/fuse \
|
docker run --cap-add MKNOD --cap-add SYS_ADMIN --device /dev/fuse \
|
||||||
-e LOCAL_UID="$(id -u)" -e LOCAL_GID="$(id -g)" \
|
-e LOCAL_UID="$(id -u)" -e LOCAL_GID="$(id -g)" \
|
||||||
-v redox-"$(id -u)"-"$(id -g)"-cargo:/home/user/.cargo \
|
-v redox-"$(id -u)-$(id -g)"-cargo:/usr/local/cargo \
|
||||||
-v "$(pwd):/home/user/src" --rm redox make fetch all
|
-v redox-"$(id -u)-$(id -g)"-rustup:/usr/local/rustup \
|
||||||
|
-v "$(pwd):$(pwd)" -w "$(pwd)" --rm redox make fetch all
|
||||||
```
|
```
|
||||||
#### Linux with security modules<br>
|
#### Linux with security modules<br>
|
||||||
Add the following options depending on the security modules activated on your system:
|
Add the following options depending on the security modules activated on your system:
|
||||||
|
@ -53,23 +48,24 @@ Ex.: for a SELinux only system such as Fedora or CentOS
|
||||||
docker run --cap-add MKNOD --cap-add SYS_ADMIN --device /dev/fuse \
|
docker run --cap-add MKNOD --cap-add SYS_ADMIN --device /dev/fuse \
|
||||||
-e LOCAL_UID="$(id -u)" -e LOCAL_GID="$(id -g)" \
|
-e LOCAL_UID="$(id -u)" -e LOCAL_GID="$(id -g)" \
|
||||||
--security-opt label=disable \
|
--security-opt label=disable \
|
||||||
-v redox-"$(id -u)"-"$(id -g)"-cargo:/home/user/.cargo \
|
-v redox-"$(id -u)-$(id -g)"-cargo:/usr/local/cargo \
|
||||||
-v "$(pwd):/home/user/src" --rm redox make fetch all
|
-v redox-"$(id -u)-$(id -g)"-rustup:/usr/local/rustup \
|
||||||
|
-v "$(pwd):$(pwd)" -w "$(pwd)" --rm redox make fetch all
|
||||||
```
|
```
|
||||||
#### MacOS
|
### Run the container interactively
|
||||||
```shell
|
```shell
|
||||||
docker run --cap-add MKNOD --cap-add SYS_ADMIN --device /dev/fuse \
|
docker run --cap-add MKNOD --cap-add SYS_ADMIN --device /dev/fuse \
|
||||||
-v redox-cargo:/home/user/.cargo \
|
-e LOCAL_UID="$(id -u)" -e LOCAL_GID="$(id -g)" \
|
||||||
-v "$(pwd):/home/user/src" --rm redox make fetch all
|
-v redox-"$(id -u)-$(id -g)"-cargo:/usr/local/cargo \
|
||||||
|
-v redox-"$(id -u)-$(id -g)"-rustup:/usr/local/rustup \
|
||||||
|
-v "$(pwd):$(pwd)" -w "$(pwd)" --rm -it redox
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Demo
|
||||||
|

|
||||||
|
|
||||||
### Clear the named volume containing the cargo cache
|
### Clear the named volume containing the cargo cache
|
||||||
#### Linux
|
|
||||||
```shell
|
```shell
|
||||||
docker volume rm redox-"$(id -u)"-"$(id -g)"-cargo
|
docker volume rm redox-"$(id -u)-$(id -g)"-cargo \
|
||||||
```
|
redox-"$(id -u)-$(id -g)"-rustup
|
||||||
|
|
||||||
#### MacOS
|
|
||||||
```shell
|
|
||||||
docker volume rm redox-cargo
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,18 +1,29 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Use -e LOCAL_UID="$(id -u)" -e LOCAL_GID="$(id -g)"
|
# Add local user
|
||||||
# on the docker run command line if the container build user is different
|
# Either use LOCAL_UID and LOCAL_GID if passed in at runtime via
|
||||||
# from the run user
|
# -e LOCAL_UID="$(id -u)" -e LOCAL_GID="$(id -g)" or fallback
|
||||||
|
USER_NAME=redox
|
||||||
|
RUN_UID=${LOCAL_UID:-9001}
|
||||||
|
RUN_GID=${LOCAL_GID:-9001}
|
||||||
|
|
||||||
CONT_UID=`id -u user`
|
groupadd --non-unique --gid $RUN_GID $USER_NAME
|
||||||
CONT_GID=`id -g user`
|
useradd --non-unique --create-home --uid $RUN_UID --gid $USER_NAME --groups sudo $USER_NAME
|
||||||
RUN_UID=${LOCAL_UID:-$CONT_UID}
|
|
||||||
RUN_GID=${LOCAL_GID:-$CONT_GID}
|
|
||||||
|
|
||||||
if [ $RUN_UID != $CONT_UID ] || [ $RUN_GID != $CONT_GID ]; then
|
echo "$USER_NAME ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/user-no-sudo-password
|
||||||
|
|
||||||
|
export HOME=/home/$USER_NAME
|
||||||
|
|
||||||
|
# Check current UID and GID of files in the named volume caches for
|
||||||
|
# cargo and rustup. Test only one of the top level folders to speed
|
||||||
|
# things up.
|
||||||
|
TESTFILE=$RUSTUP_HOME/settings.toml
|
||||||
|
CACHED_UID=$(stat -c "%u" $TESTFILE)
|
||||||
|
CACHED_GID=$(stat -c "%g" $TESTFILE)
|
||||||
|
|
||||||
|
if [ $CACHED_UID != $RUN_UID ] || [ $RUN_GID != $CACHED_GID ]; then
|
||||||
echo -e "\033[01;38;5;155mChanging user id:group to ${RUN_UID}:${RUN_GID}. Please wait...\033[0m"
|
echo -e "\033[01;38;5;155mChanging user id:group to ${RUN_UID}:${RUN_GID}. Please wait...\033[0m"
|
||||||
groupmod -g $RUN_GID user
|
chown $RUN_UID:$RUN_GID -R $CARGO_HOME $RUSTUP_HOME
|
||||||
usermod -u $RUN_UID -g $RUN_GID user
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec gosu user:user "$@"
|
exec gosu $USER_NAME "$@"
|
||||||
|
|
BIN
docker/interactive_demo.gif
Normal file
BIN
docker/interactive_demo.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 946 KiB |
Loading…
Reference in a new issue