-
Notifications
You must be signed in to change notification settings - Fork 739
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
Docker improvements #571
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Ignore all subdirectories | ||
*/* | ||
|
||
# Allow to run the test script inside the Docker container | ||
!/docker/test_dockerimage.sh | ||
|
||
# Allow the Dockerfile for future re-creation/reference | ||
!/docker/Dockerfile | ||
|
||
# Ignore unnecessary files inside top-level directory | ||
*.bat | ||
*.csh | ||
*.fish | ||
*.ps1 | ||
*.pyc | ||
.emscripten | ||
.emscripten.old | ||
.emscripten_cache | ||
.emscripten_cache__last_clear | ||
.emscripten_sanity | ||
.emscripten_sanity_wasm | ||
.flake8 | ||
emscripten-releases-tot.txt | ||
legacy-*-tags.txt | ||
README.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
#!/usr/bin/env make | ||
# A Makefile to build, test, tag and publish the Emscripten SDK Docker container. | ||
|
||
# Emscripten version to build: Should match the version that has been already released. | ||
# i.e.: 1.38.45, 1.38.45-upstream | ||
# i.e.: 1.39.18 | ||
version = | ||
alias = | ||
|
||
image_name ?= emscripten/emsdk | ||
|
||
.TEST: | ||
ifndef version | ||
$(error argument 'version' is not set. Please call `make version=SOME_VERSION ...`) | ||
endif | ||
|
||
build: .TEST | ||
docker build --network host --build-arg=EMSCRIPTEN_VERSION=${version} --tag emscripten/emsdk:${version} . | ||
build: Dockerfile .TEST | ||
cd .. && docker build --network host --build-arg=EMSCRIPTEN_VERSION=${version} -t ${image_name}:${version} -f docker/$< . | ||
|
||
test: test_dockerimage.sh .TEST | ||
# test as non-root | ||
docker run --rm -u `id -u`:`id -g` -w /emsdk/docker --net=host ${image_name}:${version} \ | ||
bash $< | ||
|
||
push: .TEST | ||
docker push emscripten/emsdk:${version} | ||
docker push ${image_name}:${version} | ||
ifdef alias | ||
docker tag emscripten/emsdk:${version} emscripten/emsdk:${alias} | ||
docker push emscripten/emsdk:${alias} | ||
docker tag ${image_name}:${version} ${image_name}:${alias} | ||
docker push ${image_name}:${alias} | ||
endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Dockerfile for EMSDK | ||
|
||
This Dockerfile builds a self-contained version of emsdk that enables emscripten to be used without any | ||
This Dockerfile builds a self-contained version of Emscripten SDK that enables Emscripten to be used without any | ||
other installation on the host system. | ||
|
||
It is published at https://hub.docker.com/u/emscripten/emsdk | ||
|
@@ -23,7 +23,7 @@ EOF | |
# compile with docker image | ||
docker run \ | ||
--rm \ | ||
-v $(pwd):$(pwd) \ | ||
-v $(pwd):/src \ | ||
-u $(id -u):$(id -g) \ | ||
emscripten/emsdk \ | ||
emcc helloworld.cpp -o helloworld.js | ||
|
@@ -51,7 +51,7 @@ This image requires to specify following build arguments: | |
|
||
| arg | description | | ||
| --- | --- | | ||
| `EMSCRIPTEN_VERSION` | One of released version of Emscripten. For example `1.38.45`<br/> Can be used with `-upstream` variant like: `1.38.45-upstream`<br /> Minimal supported version is **1.38.40**| | ||
| `EMSCRIPTEN_VERSION` | One of released version of Emscripten. For example `1.39.17`<br/> Minimal supported version is **1.39.0**| | ||
|
||
**Building** | ||
|
||
|
@@ -60,13 +60,14 @@ This step will build Dockerfile as given tag on local machine | |
# using docker | ||
docker build \ | ||
--network host \ | ||
--build-arg=EMSCRIPTEN_VERSION=1.38.43-upstream \ | ||
--tag emscripten/emsdk:1.38.43-upstream \ | ||
--build-arg=EMSCRIPTEN_VERSION=1.39.17 \ | ||
-t emscripten/emsdk:1.39.17 \ | ||
-f docker/Dockerfile \ | ||
. | ||
``` | ||
```bash | ||
# using predefined make target | ||
make version=1.38.43-upstream build | ||
make version=1.39.17 build test | ||
``` | ||
|
||
**Tagging** | ||
|
@@ -79,35 +80,24 @@ This step will take local image and push to default docker registry. You need to | |
|
||
```bash | ||
# using docker | ||
docker push emscripten/emsdk:1.38.43-upstream | ||
docker push emscripten/emsdk:1.39.17 | ||
``` | ||
```bash | ||
# using predefined make target | ||
make version=1.38.43-upstream push | ||
make version=1.39.17 push | ||
``` | ||
|
||
In case of pushing the most recent version, this version should be also tagged as `latest` or `latest-upstream` and pushed. | ||
In case of pushing the most recent version, this version should be also tagged as `latest` and pushed. | ||
```bash | ||
# using docker cli | ||
|
||
# in case of fastcomp variant (default backend) | ||
docker tag emscripten/emsdk:1.38.43 emscripten/emsdk:latest | ||
docker tag emscripten/emsdk:1.39.17 emscripten/emsdk:latest | ||
docker push emscripten/emsdk:latest | ||
|
||
# in case of upstream variant | ||
docker tag emscripten/emsdk:1.38.43-upstream emscripten/emsdk:latest-upstream | ||
docker push emscripten/emsdk:latest-upstream | ||
|
||
``` | ||
|
||
```bash | ||
# using predefined make target | ||
|
||
make version=1.38.43-upstream alias=latest-upstream push | ||
|
||
# using make | ||
make version=1.39.17 alias=latest push | ||
``` | ||
|
||
|
||
### Extending | ||
|
||
If your project uses packages that this image doesn't provide you might want to: | ||
|
@@ -117,20 +107,19 @@ If your project uses packages that this image doesn't provide you might want to: | |
1. create own Dockerfile that holds: | ||
```dockerfile | ||
# Point at any base image that you find suitable to extend. | ||
FROM emscripten/emsdk:1.38.25 | ||
FROM emscripten/emsdk:1.39.17 | ||
|
||
# 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this make a difference anywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't make any difference, |
||
docker build -t extended_emscripten . | ||
``` | ||
|
||
3. test | ||
```shell | ||
```bash | ||
docker run --rm extended_emscripten ninja --version | ||
# Python 2.7.16 | ||
# 1.10.0 | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bash | ||
set -ex | ||
|
||
sudo -u nobody `which emcc` --version | ||
if [ $EUID -eq 0 ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( 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' |
||
sudo -u nobody `which emcc` --version | ||
fi | ||
|
||
which asm2wasm | ||
which llvm-ar | ||
which emsdk | ||
node --version | ||
|
@@ -15,5 +16,15 @@ emcc --version | |
java -version | ||
cmake --version | ||
|
||
# cleanup after test | ||
find ${EMSDK} -name "*.pyc" -exec rm {} \; | ||
exit_code=0 | ||
|
||
# test emcc compilation | ||
echo 'int main() { return 0; }' | emcc -o /tmp/main.js -xc - | ||
node /tmp/main.js || exit_code=$? | ||
if [ $exit_code -ne 0 ]; then | ||
echo "Node exited with non-zero exit code: $exit_code" | ||
exit $exit_code | ||
fi | ||
|
||
# test embuilder | ||
embuilder build zlib --force | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 In that I case I think the old way was better. No need to use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. The |
There was a problem hiding this comment.
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-ebacf6f6ae4ee68078bb16454b23247dR26I guess they are the same .. i can't remember why I chose one over the other.
There was a problem hiding this comment.
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.