Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to build rootfs with docker locally #14

Merged
merged 1 commit into from
Feb 14, 2019
Merged

Add script to build rootfs with docker locally #14

merged 1 commit into from
Feb 14, 2019

Conversation

utzcoz
Copy link
Member

@utzcoz utzcoz commented Feb 13, 2019

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 [email protected]

@pdsouza
Copy link
Member

pdsouza commented Feb 13, 2019

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:

Dockerfile

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.

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.

Usage

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.

Copy link
Member

@pdsouza pdsouza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of it looks good to me. Please see my comments on the main PR where I describe a way to use ./build-with-docker without needing to start a separate shell.

Dockerfile Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
build-with-docker.sh Outdated Show resolved Hide resolved
build-with-docker.sh Outdated Show resolved Hide resolved
.gitignore Show resolved Hide resolved
.dockerignore Show resolved Hide resolved
@utzcoz
Copy link
Member Author

utzcoz commented Feb 14, 2019

@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.

Executing ./build-with-docker.sh or
./build-with-docker.sh -b debian -n stretch-container -- -a arm64 --minimal
in blueprints directory, will build rootfs in docker locally.
And the generated rootfs tar gz file will be placed in out
directory.

Signed-off-by: utzcoz <[email protected]>
@utzcoz
Copy link
Member Author

utzcoz commented Feb 14, 2019

@pdsouza I also use build-with-docker.sh in .travis.yml to fix build error.

@@ -26,13 +26,17 @@ See [blueprint/debian](blueprint/debian) as the canonical example for Debian.

## Examples

Build a Debian Stretch armhf container called 'debian' (option defaults):
Create the default container in Docker (specified in `Dockerfile`'s CMD):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use just ./build.sh in the examples and then have a section where we show how you can just substitute ./build-with-docker.sh if you would like to do the builds in a Docker container. This way, people without docker set up can still build it by installing dependencies manually, or in the case where the user is using my pdsouza/maruos-devbox container as described in the Maru Developer Guide.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good enough to merge though; I can update the docs in another commit.

Copy link
Member

@pdsouza pdsouza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I will update the README in another commit to address my comment.

@pdsouza pdsouza merged commit ce7d340 into maruos:master Feb 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants