Closed utzcoz closed 5 years ago
Thanks for the PR @utzcoz. I think we can slightly improve this.
Rather than starting a Docker container with a shell like in your script which requires the user have to run the ./build.sh
script from within the container, it may be better to use ENTRYPOINT
and CMD
in the Dockerfile to allow the user to just run the container and only pass in the arguments that will be forwarded to build.sh
:
FROM debian:latest
RUN apt-get update && apt-get install -y \
binfmt-support \
debootstrap \
fakeroot \
git \
lxc \
make \
qemu \
qemu-user-static \
ubuntu-archive-keyring \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV MARU_WORKSPACE /var/maru
RUN mkdir -p ${MARU_WORKSPACE}
WORKDIR ${MARU_WORKSPACE}
ENTRYPOINT ["./build.sh"]
CMD ["--", "--minimal"]
The CMD
defines the default arguments to run if the user does not specify any arguments to build-with-docker.sh
.
#!/bin/bash
mkdir -p out
docker build -t maruos/blueprints .
docker run --privileged --rm \
-v /var/cache:/var/cache \
-v "$(pwd)":/var/maru \
-t maruos/blueprints "$@"
We use the $@
special parameter in Bash to pass the positional arguments to the Docker container, which will override CMD
specified in the Dockerfile
.
Create the default container in Docker (specified in Dockerfile
's CMD):
./build-with-docker.sh
Create a Debian arm64 stretch container called "stretch-container" (args will be passed to build.sh
):
./build-with-docker.sh -b debian -n stretch-container -- -a arm64 --minimal
To stop the build early you can run:
docker stop $CONTAINER_ID
What do you think about this? I think it's clearer to read when you just need to pass in the parameters instead of entering the Docker container shell first.
I am happy to merge your PR with these modifications.
@pdsouza I resolved problems based on your advice mostly. The CMD
for default parameter doesn't work correctly for purpose, so I use shell script to do it.
@pdsouza I also use build-with-docker.sh
in .travis.yml
to fix build error.
Add script to build rootfs with docker locally, when we want to build it for debug. There is a basic
Dockerfile
and building script , I just add script to build and run docker environment for rootfs building. Executing ./build-with-docker.sh in blueprints directory, and executing ./build.sh with parameter following document to build rootfs manually, and the rootfs tar gz will generated in out directory.Signed-off-by: utzcoz utzcoz@outlook.com