Skip to content

Docker improvements #571

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

Merged
merged 3 commits into from
Sep 2, 2020
Merged

Conversation

kleisauke
Copy link
Collaborator

This PR is built on top of #533 with these additional changes:

  • Shallow clone emsdk (saves ~2MB).
  • Test tip-of-tree build within CI.
  • Run the test suite outside the Docker image.
  • Avoid copying the Dockerfile into the final image (it already exists in /emsdk/docker).

Testing the tip-of-tree build within CI hasn't been discussed, hence I've marked this PR as a draft.

/cc @trzecieu, as he's the author of #533.

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Thanks! Mostly looks great


# Install required tools that are useful for your project i.e. ninja-build
RUN apt update && apt install -y ninja-build

```
2. build it
```shell
```bash
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this make a difference anywhere?

Copy link
Collaborator Author

@kleisauke kleisauke Jul 26, 2020

Choose a reason for hiding this comment

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

It doesn't make any difference, bash is an alias for shell within GitHub flavored markdown. I think @trzecieu changed this to align it with the other code blocks.

emcc -c test/main.c -o test/main

# test embuilder
embuilder build zlib
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we test this doesn't actually build anything? (since the re-loaded cache should contain these libraries).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added the --force parameter with commit d702167 to ensure it's not built from the cache.

# cleanup after test
rm -rf test
find ${EMSDK} -name "*.pyc" -exec rm {} \;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why cleanup here at all.. isn't this run with --rm meaning its just gets thrown away anyway?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The --rm parameter will not remove files within the mounted volume. I removed these cleanups with commit d702167 and compiled the test to /tmp instead.

@@ -19,11 +19,12 @@ RUN echo "## Start building" \
&& echo "## Done"

RUN echo "## Get EMSDK" \
&& git clone https://github.com/emscripten-core/emsdk.git ${EMSDK} \
&& git clone --depth=1 https://github.com/emscripten-core/emsdk.git ${EMSDK} \
Copy link
Collaborator

Choose a reason for hiding this comment

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

This whole step seems a little odd given that this Dockerfile now lives in the emsdk repo itself. I've been working on a PR to remove this step and just have the Dockerfile operate of the current checkout that contains it. I'm still up for landing this change first as-is though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great! Copying the current checkout to the Dockerfile is indeed a better way to handle this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Commit 118f091 operates on the current checkout directory within the Dockerfile. This ensures that any changes in emsdk itself or in the Docker test script (i.e. docker/test_dockerimage.sh) are tested during pull requests.

@@ -88,16 +88,16 @@ jobs:
python scripts/test.py

build-docker-image:
executor: bionic
machine: true # required for testing files permissions
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is kind of sad.. I it probably slower to start up and perhaps more costly.

Can you explain a little more why the regular executor doesn't work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure why the regular executor didn't work. This was probably necessary to run privileged Docker containers.

I reverted the executor back to bionic with commit f5f2fbf.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Argh, it looks like mounting volumes doesn't work for the CircleCI Docker executor, that's why CI failed for f5f2fbf. See:
https://discuss.circleci.com/t/docker-compose-yml-and-volume-mounts/10043/7

Fixed with 75ca515.

fi

# test embuilder
embuilder build zlib --force
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry I under standstand now, the cleanup was being done not inside the docker image but here in the docker subdirectory.

In that I case I think the old way was better. No need to use /tmp just write the files here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since I cannot mount volumes using the CircleCI Docker executor, writing the compiled output to the docker subdirectory is not possible. Would you rather use the CircleCI Docker executor (current state) or write to the compiled output to the docker subdirectory (and therefore using the machine executor)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I think its fine to use the /tmp directory inside the container assuming that is what is happening? Since that directory will be destroyed once the container finished running right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. The /tmp is only used inside the container and then cleaned up afterwards once the container is finished (thanks to the --rm parameter).

docker/Makefile Outdated
# FIXME: the `-e HOME=/tmp` is a workaround for:
# https://github.com/emscripten-core/emsdk/issues/535
docker run --rm -u `id -u`:`id -g` -e HOME=/tmp --net=host emscripten/emsdk:${version} \
/bin/bash -c "`cat test_dockerimage.sh`"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This construction seems a little bit hacky... why not just leave test_dockerimage.sh inside the container?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I was overthinking the issue. We could indeed just run /emsdk/docker/test_dockerimage.sh instead.

Commit 118f091 removes this hackish solution.

.dockerignore Outdated
.flake8

# Makefile is not needed
Makefile
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there some say to inherit everything from .gitignore? if not perhaps just include it with a comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps we could symlink it with .gitignore? Anyways, I cleaned up the file a bit with commit 4b64400.

&& git clone https://github.com/emscripten-core/emsdk.git ${EMSDK} \
&& echo "## Done"
# Copy the contents of this repository to the container
COPY . ${EMSDK}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I my version of this change I used ADD . /emsdk: https://github.com/emscripten-core/emsdk/compare/docker_use_local_emsdk?expand=1#diff-ebacf6f6ae4ee68078bb16454b23247dR26

I guess they are the same .. i can't remember why I chose one over the other.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't make much difference: https://stackoverflow.com/a/24958548/10952119. I think COPY is fine here.

Makefile Outdated
@@ -0,0 +1,30 @@
#!/usr/bin/env make
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps comment at the top saying what the purpose of this makefile is? i.e. to build the docker image.

If you could leave the Makefile where it was and rung it with make -f to avoid polluting the top level?

(You can also remove the #! line from the top, I don't think anyone expects to run the Makefile like that).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All done with commit 531f6c8.

@sbc100
Copy link
Collaborator

sbc100 commented Jul 31, 2020

Is this ready t do now? Its still marked as a draft.

@kleisauke kleisauke marked this pull request as ready for review July 31, 2020 18:28
@kleisauke
Copy link
Collaborator Author

Yes, this is now ready for final review. I've removed the draft status.

Since this PR contains some outdated details, would you like me to squash all the commits and update the commit message?

@sbc100
Copy link
Collaborator

sbc100 commented Jul 31, 2020

Yes please. We always squash all out PRs on commit anyway by policy.

IMHO, if something it worth its own commit its probably also work its own PR which means I basically never look at individual commits in PRs.

This also means that each commit in git also goes through CI on its own which makes bisecting easier.

@sbc100
Copy link
Collaborator

sbc100 commented Jul 31, 2020

I think you might also want rebase/integrate #578

@sbc100
Copy link
Collaborator

sbc100 commented Jul 31, 2020

I was going to suggest that we split out the "use emsdk inplace" change since it a fairly major one, and commit the other misc improvements separately. But I don't feel strongly about it.

- Copy the current checkout to the Dockerfile.
- Add .dockerignore to exclude files while copying.
- Test tip-of-tree build within CI.
- Run the test suite outside the Docker image.
- Perform extra sanity tests.
- Switch to make commands for CircleCI.
- Improve Docker README.

Co-authored-by: trzeci <[email protected]>
@kleisauke kleisauke force-pushed the docker-improvements branch from 4b64400 to da0432a Compare August 1, 2020 13:11
set -ex

sudo -u nobody `which emcc` --version
if [ $EUID -eq 0 ]; then
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note that this check is needed for Podman (which is the default container engine on Fedora 32). Podman provides a Docker-compatible command line front end that can simply alias the Docker cli (alias docker=podman).

Without this check, it will fail to perform the tests (probably because Podman is running in rootless mode).

Details
$ make -C ./docker version=tot test
make: Entering directory '/home/kleisauke/emsdk/docker'
# test as non-root
docker run --rm -u `id -u`:`id -g` -w /emsdk/docker --net=host emscripten/emsdk:tot \
	bash test_dockerimage.sh
++ which emcc
+ sudo -u nobody /emsdk/upstream/emscripten/emcc --version
sudo: unable to resolve host pc-kaw: Name or service not known

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

sudo: no tty present and no askpass program specified
make: *** [Makefile:20: test] Error 1
make: Leaving directory '/home/kleisauke/emsdk/docker'

@kleisauke
Copy link
Collaborator Author

kleisauke commented Aug 3, 2020

Rebased and squashed as requested. I've also polished the commit message and added @trzecieu as co-author (thanks!).

If you want, I could make a separate PR for the "emsdk inplace" change. Otherwise, I think this PR is ready to land.

@kleisauke
Copy link
Collaborator Author

@trzecieu I've used trzeci <[email protected]> as co-author, as this seems your primary commit email and username. Let me know if something needs to be changed.

This check became obsolete after WebAssembly/binaryen#3042.
@sbc100
Copy link
Collaborator

sbc100 commented Aug 22, 2020

I this ready to land now?

@kleisauke
Copy link
Collaborator Author

This PR is ready to land (I was waiting for confirmation regarding the added Co-authored-by: ... line, but I think it's fine).

The CI failures in this PR are probably because it hasn't been rebased. Commit 1274e7a should fix the CI failure for the publish-docker-image job (as a result 2.0.1 has not been published on Docker Hub).

@kleisauke kleisauke mentioned this pull request Sep 1, 2020
@sbc100 sbc100 merged commit 645d276 into emscripten-core:master Sep 2, 2020
vargaz pushed a commit to vargaz/emsdk that referenced this pull request Nov 22, 2023
emscripten-core#571)

* Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20231023.4

Microsoft.SourceBuild.Intermediate.source-build-reference-packages
 From Version 9.0.0-alpha.1.23519.2 -> To Version 9.0.0-alpha.1.23523.4

* Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20231023.4

Microsoft.SourceBuild.Intermediate.source-build-reference-packages
 From Version 9.0.0-alpha.1.23519.2 -> To Version 9.0.0-alpha.1.23523.4

* Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20231025.1

Microsoft.SourceBuild.Intermediate.source-build-reference-packages
 From Version 9.0.0-alpha.1.23519.2 -> To Version 9.0.0-alpha.1.23525.1

* Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20231025.1

Microsoft.SourceBuild.Intermediate.source-build-reference-packages
 From Version 9.0.0-alpha.1.23519.2 -> To Version 9.0.0-alpha.1.23525.1

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
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.

3 participants