Skip to content

Commit 9cc33be

Browse files
committed
add Docker container with tox, Python, Node.js, npm and javascript dependencies
1 parent 26224f8 commit 9cc33be

4 files changed

Lines changed: 163 additions & 1 deletion

File tree

nodethon/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Builds a docker image with Python and Node.js to use for tox runs.
3+
#
4+
FROM ubuntu:18.04
5+
6+
VOLUME /repo
7+
8+
WORKDIR /repo
9+
10+
11+
ENV SONAR_SCANNER_VERSION 4.2.0.1873
12+
ENV LANG=en_US.UTF-8
13+
ENV LANGUAGE=en_US:en
14+
ENV LC_ALL=en_US.UTF-8
15+
ENV SONAR_SCANNER_HOME=/sonar-scanner-${SONAR_SCANNER_VERSION}-linux
16+
ENV SONAR_SCANNER_OPTS="-server"
17+
18+
ENV PATH="${SONAR_SCANNER_HOME}/sonar-scanner-${SONAR_SCANNER_VERSION}-linux/bin:${PATH}"
19+
20+
COPY provision.sh /
21+
22+
RUN /provision.sh

nodethon/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# "Nodethon" (Node.js + Python) Docker
2+
3+
Builds and pushes a docker environment for use with tox testing. This environment contains Node.js 13 and some other JavaScript dependencies, besides a series of python versions allowing multi-version tox testing locally and in CI services.
4+
5+
The "sq" suffix indicates that the ["sonarqube"](https://www.sonarqube.org) scanner has been included in the image. This scanner allows tox builds to upload coverage and other reports to a sonarqube instance.
6+
7+
## Build and Push
8+
9+
These instructions are for maintainers with permissions to push to the "uavcan" organization on Docker Hub.
10+
11+
```
12+
docker build .
13+
```
14+
```
15+
docker images
16+
17+
REPOSITORY TAG IMAGE ID
18+
nodethon latest d7ab132649d6
19+
```
20+
```
21+
# We use the range of python environments supported as the version tag.
22+
docker tag d7ab132649d6 uavcan/nodethon:py35-py38-node13-sq
23+
docker login --username=yourhubusername
24+
docker push uavcan/nodethon:py35-py38-node13-sq
25+
```
26+
27+
## Testing out the container
28+
29+
Start an interactive session:
30+
31+
```bash
32+
docker run --rm -it -v ${PWD}:/repo uavcan/nodethon:py35-py38-node13-sq
33+
```
34+
35+
On MacOS you'll probably want to optimize `osxfs` with something like cached or delegated:
36+
37+
```bash
38+
docker run --rm -it -v ${PWD}:/repo:delegated uavcan/nodethon:py35-py38-node13-sq
39+
```
40+
41+
See ["Performance tuning for volume mounts"](https://docs.docker.com/docker-for-mac/osxfs-caching/) for details.
42+
43+
## Travis CI
44+
45+
You can use this in your .travis.yml like this:
46+
47+
```none
48+
services:
49+
- docker
50+
51+
before_install:
52+
- docker pull uavcan/nodethon:py35-py38-node13-sq
53+
54+
script:
55+
- docker run --rm -v $TRAVIS_BUILD_DIR:/repo uavcan/nodethon:py35-py38-node13-sq /bin/sh -c tox
56+
57+
```
58+
59+
## BuildKite
60+
61+
Example pipeline.yml:
62+
63+
```yaml
64+
- label: ":github: my containerized build"
65+
command: "nodethon tox"
66+
plugins:
67+
- docker#v3.5.0:
68+
workdir: /repo
69+
image: "uavcan/nodethon:py35-py38-node13-sq"
70+
propagate-environment: true
71+
mount-ssh-agent: true
72+
```

nodethon/provision.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
3+
# +----------------------------------------------------------+
4+
# | BASH : Modifying Shell Behaviour
5+
# | (https://www.gnu.org/software/bash/manual)
6+
# +----------------------------------------------------------+
7+
# Treat unset variables and parameters other than the special
8+
# parameters ‘@’ or ‘*’ as an error when performing parameter
9+
# expansion. An error message will be written to the standard
10+
# error, and a non-interactive shell will exit.
11+
set -o nounset
12+
13+
# Exit immediately if a pipeline returns a non-zero status.
14+
set -o errexit
15+
16+
# If set, the return value of a pipeline is the value of the
17+
# last (rightmost) command to exit with a non-zero status, or
18+
# zero if all commands in the pipeline exit successfully.
19+
set -o pipefail
20+
21+
# +----------------------------------------------------------+
22+
export DEBIAN_FRONTEND=noninteractive
23+
24+
apt-get update
25+
26+
# setup locales in the container so Python can default to utf-8.
27+
apt-get -y install locales
28+
# from http://jaredmarkell.com/docker-and-locales/
29+
locale-gen en_US.UTF-8
30+
export ENV LANG=en_US.UTF-8
31+
export ENV LANGUAGE=en_US:en
32+
export ENV LC_ALL=en_US.UTF-8
33+
34+
apt-get -y install software-properties-common
35+
apt-get -y install git
36+
apt-get -y install curl
37+
apt-get -y install unzip
38+
39+
# deadsnakes maintains a bunch of python versions for Ubuntu.
40+
add-apt-repository -y ppa:deadsnakes/ppa
41+
apt-get update
42+
apt-get -y install python3.5
43+
apt-get -y install python3.6
44+
apt-get -y install python3.7
45+
apt-get -y install python3.8
46+
apt-get -y install python3-pip
47+
pip3 install tox
48+
49+
# Node.js (13), npm (6.14) and JS dependencies
50+
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
51+
apt-get -y install nodejs
52+
node -v
53+
npm -v
54+
# install JSdoc to be used with sphinx-js
55+
npm install -g jsdoc
56+
# install Mocha JavaScript test framework
57+
npm install -g mocha
58+
59+
# Sonarqube
60+
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
61+
unzip -o $HOME/.sonar/sonar-scanner.zip -d $SONAR_SCANNER_HOME
62+
63+
rm -rf $HOME/.sonar
64+
65+
echo "export PATH=$PATH" >> ~/.bashrc
66+
echo "export LANG=en_US.UTF-8" >> ~/.bashrc
67+
echo "export LANGUAGE=en_US:en" >> ~/.bashrc
68+
echo "export LC_ALL=en_US.UTF-8" >> ~/.bashrc

toxic/provision.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ apt-get -y install python3-pip
4747
pip3 install tox
4848

4949
# Sonarqube
50-
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
50+
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
5151
unzip -o $HOME/.sonar/sonar-scanner.zip -d $SONAR_SCANNER_HOME
5252

5353
rm -rf $HOME/.sonar

0 commit comments

Comments
 (0)