mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 06:17:49 +00:00
Docker: Add a Dockerfile and Makefile targets (#373)
* add docker build option * add docker section in makefile * add bash_aliases to get different prompt
This commit is contained in:
committed by
Philipp Oppermann
parent
cf2c5550aa
commit
2e8da22b32
25
Makefile
25
Makefile
@@ -19,6 +19,14 @@ assembly_source_files := $(wildcard src/arch/$(arch)/*.asm)
|
||||
assembly_object_files := $(patsubst src/arch/$(arch)/%.asm, \
|
||||
build/arch/$(arch)/%.o, $(assembly_source_files))
|
||||
|
||||
# used by docker_* targets
|
||||
docker_image ?= blog_os
|
||||
tag ?= 0.1
|
||||
docker_cargo_volume ?= blogos-$(shell id -u)-$(shell id -g)-cargo
|
||||
docker_rustup_volume ?= blogos-$(shell id -u)-$(shell id -g)-rustup
|
||||
docker_args ?= -e LOCAL_UID=$(shell id -u) -e LOCAL_GID=$(shell id -g) -v $(docker_cargo_volume):/usr/local/cargo -v $(docker_rustup_volume):/usr/local/rustup -v $(shell pwd):$(shell pwd) -w $(shell pwd)
|
||||
docker_clean_args ?= $(docker_cargo_volume) $(docker_rustup_volume)
|
||||
|
||||
.PHONY: all clean run debug iso cargo gdb
|
||||
|
||||
all: $(kernel)
|
||||
@@ -33,6 +41,23 @@ run: $(iso)
|
||||
debug: $(iso)
|
||||
@qemu-system-x86_64 -cdrom $(iso) -s -S
|
||||
|
||||
# docker_* targets
|
||||
|
||||
docker_build:
|
||||
@docker build docker/ -t $(docker_image):$(tag)
|
||||
|
||||
docker_iso:
|
||||
@docker run --rm $(docker_args) $(docker_image):$(tag) make iso
|
||||
|
||||
docker_run: docker_iso
|
||||
@qemu-system-x86_64 -cdrom $(iso) -s
|
||||
|
||||
docker_interactive:
|
||||
@docker run -it --rm $(docker_args) $(docker_image):$(tag)
|
||||
|
||||
docker_clean:
|
||||
@docker volume rm $(docker_clean_args)
|
||||
|
||||
gdb:
|
||||
@rust-os-gdb/bin/rust-gdb "build/kernel-x86_64.bin" -ex "target remote :1234"
|
||||
|
||||
|
||||
1
docker/.bash_aliases
Normal file
1
docker/.bash_aliases
Normal file
@@ -0,0 +1 @@
|
||||
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\]\$ "
|
||||
40
docker/Dockerfile
Normal file
40
docker/Dockerfile
Normal file
@@ -0,0 +1,40 @@
|
||||
FROM rustlang/rust:nightly
|
||||
|
||||
ENV IMAGE_NAME=blog_os-docker
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -q -y --no-install-recommends \
|
||||
nasm \
|
||||
binutils \
|
||||
grub-common \
|
||||
xorriso \
|
||||
grub-pc-bin && \
|
||||
apt-get autoremove -q -y && \
|
||||
apt-get clean -q -y && \
|
||||
rm -rf /var/lib/apt/lists/* && \
|
||||
cargo install xargo && \
|
||||
rustup component add rust-src
|
||||
|
||||
ENV GOSU_VERSION 1.10
|
||||
|
||||
RUN set -ex; \
|
||||
\
|
||||
fetchDeps=' \
|
||||
ca-certificates \
|
||||
wget \
|
||||
'; \
|
||||
apt-get update; \
|
||||
apt-get install -y --no-install-recommends $fetchDeps; \
|
||||
rm -rf /var/lib/apt/lists/*; \
|
||||
\
|
||||
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
|
||||
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
|
||||
chmod +x /usr/local/bin/gosu; \
|
||||
# verify that the binary works
|
||||
gosu nobody true;
|
||||
|
||||
COPY entrypoint.sh /usr/local/bin/
|
||||
COPY .bash_aliases /etc/skel/
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||
CMD ["/bin/bash"]
|
||||
18
docker/README.md
Normal file
18
docker/README.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# Building Blog OS using Docker
|
||||
Inspired by [redox].
|
||||
You just need `git`, `make`, and `docker`.
|
||||
It is beter to use a non-privileged user to run the `docker` command, which is usually achieved by adding the user to the `docker` group.
|
||||
|
||||
## Run the container to build Blog OS
|
||||
You can build the docker image using `make docker_build` and run it using `make docker_run`.
|
||||
|
||||
## Run the container interactively
|
||||
You can use the `make` target `docker_interactive` to get a shell in the container.
|
||||
|
||||
## Clear the toolchain caches (Cargo & Rustup)
|
||||
To clean the docker volumes used by the toolchain, you just need to run `make docker_clean`.
|
||||
|
||||
[redox]: https://github.com/redox-os/redox
|
||||
|
||||
## License
|
||||
The source code is dual-licensed under MIT or the Apache License (Version 2.0). This excludes the `blog` directory.
|
||||
19
docker/entrypoint.sh
Executable file
19
docker/entrypoint.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
USER_NAME=blogos
|
||||
USER_UID=${LOCAL_UID:-9001}
|
||||
USER_GID=${LOCAL_GID:-9001}
|
||||
|
||||
groupadd --non-unique --gid $USER_GID $USER_NAME
|
||||
useradd --non-unique --create-home --uid $USER_UID --gid $USER_GID $USER_NAME
|
||||
|
||||
export HOME=/home/$USER_NAME
|
||||
|
||||
TESTFILE=$RUSTUP_HOME/settings.toml
|
||||
CACHED_UID=$(stat -c "%u" $TESTFILE)
|
||||
CACHED_GID=$(stat -c "%g" $TESTFILE)
|
||||
|
||||
if [ $CACHED_UID != $USER_UID ] || [ $USER_GID != $CACHED_GID ]; then
|
||||
chown $USER_UID:$USER_GID -R $CARGO_HOME $RUSTUP_HOME
|
||||
fi
|
||||
|
||||
exec gosu $USER_NAME "$@"
|
||||
Reference in New Issue
Block a user