Skip to content

Commit

Permalink
Added initial files for running build inside Docker.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisspen committed Apr 13, 2020
1 parent be99bb0 commit af9b177
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 66 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
@@ -0,0 +1,4 @@
.git
_build
archlinux
dist
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ tmp
/*.geany
*.out
/_build
/dist
65 changes: 5 additions & 60 deletions .travis.yml
Expand Up @@ -3,70 +3,15 @@
dist: xenial
sudo: required
language: python
python: 2.7
python: 3.7

env:
- MAX_CPU_PERCENT=20 MAX_MEM_PERCENT=5
services:
- docker

install:
- sudo apt-key update
- sudo apt-get -yq update
- sudo apt -yq install xvfb gnome-shell

# Install NodeJS from upstream, since the version that comes with Ubuntu 14 is ancient.
# https://askubuntu.com/a/548776/13217
- sudo apt-get -yq install curl
- curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
- sudo apt-get install -yq nodejs

# Necessary on some versions of Ubuntu 14, which has a malformed npm/nodejs package.
- sudo bash -c "[ ! -f /usr/bin/node ] && ln -s /usr/bin/nodejs /usr/bin/node || true"
- which nodejs
- which node

# Install NPM from upstream.
- git clone git://github.com/npm/cli.git
- cd cli/scripts
- chmod +x install.sh
- sudo ./install.sh
- cd ../..

- sudo npm install -g eslint

before_script:
- "export DISPLAY=:99.0"
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16"
- sleep 3 # give xvfb some time to start
- sudo gnome-shell &
- sleep 3 # give gnome-shell some time to start

script:

# Clear initial gnome-shell errors we don't care about.
- sudo journalctl /usr/bin/gnome-shell
- sudo journalctl --rotate
- sudo journalctl --vacuum-time=1s

# Show pre-extension gnome-shell performance.
- ps -C gnome-shell -o %cpu,%mem,cmd

# Run JSlint check.
- cd $TRAVIS_BUILD_DIR
- ./checkjs.sh

# Install and enable extension.
- sudo make install
- gnome-shell-extension-tool --enable-extension=system-monitor@paradoxxx.zero.gmail.com

# Give extension time to run.
- sleep 10

# Show post-extension gnome-shell performance.
- ps -C gnome-shell -o %cpu,%mem,cmd
# Check CPU. On localhost with 2.80GHz x 4 takes ~3%, on Travis ~15%.
- bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %cpu|tail -1) < $MAX_CPU_PERCENT") -eq 1 ]]'
# Check memory. On localhost with 32GB of memory, ~0.6%, on Travis ~3%.
- bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %mem|tail -1) < $MAX_MEM_PERCENT") -eq 1 ]]'
# Confirm extension hasn't thrown any errors.
- sudo journalctl /usr/bin/gnome-shell
- sudo journalctl /usr/bin/gnome-shell|grep "\-\- No entries \-\-"
- ./run_docker_tests.sh ubuntu1804
- ./run_docker_tests.sh ubuntu2004
48 changes: 48 additions & 0 deletions Dockerfile.ubuntu1804
@@ -0,0 +1,48 @@
FROM ubuntu:18.04
ENV PYTHONUNBUFFERED 1

USER root
ENV HOME /home/root

# Install sudo. Not strictly required inside Docker, but it will allow Docker to run scripts that typically run outside Docker
# which do use sudo.
RUN apt update && apt -yq install sudo
RUN sudo echo "hi"

# Setup localization.
ENV DEBIAN_FRONTEND noninteractive
RUN apt update
RUN apt install -y locales
RUN rm -rf /var/lib/apt/lists/* && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
RUN apt update
ENV LANG en_US.utf8

# Install dependencies
RUN apt-get -yq update && apt-get install -y gnupg2
RUN apt-key update
RUN apt-get -yq update
RUN apt-get -yq install xvfb gnome-shell git make bc dbus procps

# Install NodeJS from upstream, since the version that comes with the distro is ancient.
# https://askubuntu.com/a/548776/13217
RUN apt-get -yq install curl
RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
RUN apt-get install -yq nodejs

# Necessary on some versions of Ubuntu 14, which has a malformed npm/nodejs package.
RUN bash -c "[ ! -f /usr/bin/node ] && ln -s /usr/bin/nodejs /usr/bin/node || true"
RUN which nodejs
RUN which node

# Install NPM from upstream.
RUN git clone git://github.com/npm/cli.git
RUN cd cli/scripts; chmod +x install.sh; ./install.sh
RUN npm install -g eslint

# Install code.
RUN mkdir -p /home/root/git/gnome-shell-system-monitor-applet
COPY . /home/root/git/gnome-shell-system-monitor-applet
WORKDIR /home/root/git/gnome-shell-system-monitor-applet

# Run test wrapper.
CMD ./docker_cmd_ubuntu1804.sh
47 changes: 47 additions & 0 deletions Dockerfile.ubuntu2004
@@ -0,0 +1,47 @@
FROM ubuntu:20.04
ENV PYTHONUNBUFFERED 1

USER root

# Install sudo. Not strictly required inside Docker, but it will allow Docker to run scripts that typically run outside Docker
# which do use sudo.
RUN apt update && apt -yq install sudo
RUN sudo echo "hi"

# Setup localization.
ENV DEBIAN_FRONTEND noninteractive
RUN apt update
RUN apt install -y locales
RUN rm -rf /var/lib/apt/lists/* && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
RUN apt update
ENV LANG en_US.utf8

# Install dependencies
RUN apt-get -yq update && apt-get install -y gnupg2
RUN apt-key update
RUN apt-get -yq update
RUN apt-get -yq install xvfb gnome-shell git make bc dbus

# Install NodeJS from upstream, since the version that comes with the distro is ancient.
# https://askubuntu.com/a/548776/13217
RUN apt-get -yq install curl
RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
RUN apt-get install -yq nodejs

# Necessary on some versions of Ubuntu 14, which has a malformed npm/nodejs package.
RUN bash -c "[ ! -f /usr/bin/node ] && ln -s /usr/bin/nodejs /usr/bin/node || true"
RUN which nodejs
RUN which node

# Install NPM from upstream.
RUN git clone git://github.com/npm/cli.git
RUN cd cli/scripts; chmod +x install.sh; ./install.sh
RUN npm install -g eslint

# Install code.
RUN mkdir -p /home/root/git/gnome-shell-system-monitor-applet
COPY . /home/root/git/gnome-shell-system-monitor-applet
WORKDIR /home/root/git/gnome-shell-system-monitor-applet

# Run test wrapper.
CMD ./docker_cmd_ubuntu2004.sh
1 change: 1 addition & 0 deletions checkjs.sh
@@ -1,4 +1,5 @@
#!/bin/bash
# Install eslint with:
# sudo apt-get install npm && sudo npm install -g eslint
set -e
eslint system-monitor@paradoxxx.zero.gmail.com
12 changes: 12 additions & 0 deletions docker-compose.ubuntu1804.yml
@@ -0,0 +1,12 @@
#https://docs.docker.com/compose/compose-file/#shm_size
version: "3.5"
services:

test:
build:
context: .
# Increase the size of shared memory.
# The default shared memory is only 64mb, causing odd Selenium errors like:
# selenium.common.exceptions.WebDriverException: Message: Failed to decode response from marionette
shm_size: '1gb'
dockerfile: Dockerfile.ubuntu1804
12 changes: 12 additions & 0 deletions docker-compose.ubuntu2004.yml
@@ -0,0 +1,12 @@
#https://docs.docker.com/compose/compose-file/#shm_size
version: "3.5"
services:

test:
build:
context: .
# Increase the size of shared memory.
# The default shared memory is only 64mb, causing odd Selenium errors like:
# selenium.common.exceptions.WebDriverException: Message: Failed to decode response from marionette
shm_size: '1gb'
dockerfile: Dockerfile.ubuntu2004
11 changes: 11 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,11 @@
#https://docs.docker.com/compose/compose-file/#shm_size
version: "3.5"
services:
test:
build:
context: .
# Increase the size of shared memory.
# The default shared memory is only 64mb, causing odd Selenium errors like:
# selenium.common.exceptions.WebDriverException: Message: Failed to decode response from marionette
shm_size: '1gb'
dockerfile: Dockerfile.${DISTRO}
53 changes: 53 additions & 0 deletions docker_cmd_ubuntu1804.sh
@@ -0,0 +1,53 @@
#!/bin/bash
# Called from the Dockerfile.* to execute our tests via the CMD.
set -e

echo "[$(date)] Launching Dbus."
mkdir -p /var/run/dbus
dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address
sleep 3 # give Dbus some time to start

echo "[$(date)] Launching Xvfb."
export DISPLAY=:99.0
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16
sleep 3 # give xvfb some time to start

echo "[$(date)] Launching Gnome-Shell."
sudo gnome-shell &
sleep 3 # give gnome-shell some time to start
echo "[$(date)] Confirming Gnome-Shell is running."
pgrep gnome-shell

echo "[$(date)] Showing Gnome-Shell log entries."
sudo journalctl /usr/bin/gnome-shell || true
echo "[$(date)] Rotating Gnome-Shell log entries."
sudo journalctl --rotate || true
echo "[$(date)] Clearing Gnome-Shell log entries."
sudo journalctl --vacuum-time=1s || true

echo "[$(date)] Show pre-extension Gnome-Shell performance."
ps -C gnome-shell -o %cpu,%mem,cmd || true

echo "[$(date)] Running JSLint check."
#cd $TRAVIS_BUILD_DIR
./checkjs.sh

echo "[$(date)] Installing extension."
sudo make install
gnome-shell-extension-tool --enable-extension=system-monitor@paradoxxx.zero.gmail.com
sleep 10 # Give extension time to run.

echo "[$(date)] Showing post-extension Gnome-Shell performance."
export MAX_CPU_PERCENT=20
export MAX_MEM_PERCENT=5
ps -C gnome-shell -o %cpu,%mem,cmd
# Check CPU. On localhost with 2.80GHz x 4 takes ~3%, on Travis ~15%.
bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %cpu|tail -1) < $MAX_CPU_PERCENT") -eq 1 ]]'
# Check memory. On localhost with 32GB of memory, ~0.6%, on Travis ~3%.
bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %mem|tail -1) < $MAX_MEM_PERCENT") -eq 1 ]]'

echo "[$(date)] Confirming extension hasn't thrown any errors."
# Note, finding no entries returns an error code of 1, which in our case means no error.
sudo journalctl /usr/bin/gnome-shell
sudo journalctl /usr/bin/gnome-shell|grep "\-\- No entries \-\-"
sudo journalctl --since=$(date '+%Y-%m-%d') /usr/bin/gnome-shell|grep -i "Extension \"system-monitor@paradoxxx.zero.gmail.com\" had error"
49 changes: 49 additions & 0 deletions docker_cmd_ubuntu2004.sh
@@ -0,0 +1,49 @@
#!/bin/bash
# Called from the Dockerfile.* to execute our tests via the CMD.
set -e

echo "[$(date)] Launching Dbus."
mkdir -p /var/run/dbus
dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address
sleep 3 # give Dbus some time to start

echo "[$(date)] Launching Xvfb."
export DISPLAY=:99.0
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16
sleep 3 # give xvfb some time to start

echo "[$(date)] Launching Gnome-Shell."
sudo gnome-shell &
sleep 3 # give gnome-shell some time to start

echo "[$(date)] Clearing Gnome-Shell log entries."
sudo journalctl /usr/bin/gnome-shell || true
sudo journalctl --rotate
sudo journalctl --vacuum-time=1s

echo "[$(date)] Show pre-extension Gnome-Shell performance."
ps -C gnome-shell -o %cpu,%mem,cmd

echo "[$(date)] Running JSLint check."
#cd $TRAVIS_BUILD_DIR
./checkjs.sh

echo "[$(date)] Installing extension."
sudo make install
gnome-shell-extension-tool --enable-extension=system-monitor@paradoxxx.zero.gmail.com
sleep 10 # Give extension time to run.

echo "[$(date)] Showing post-extension Gnome-Shell performance."
export MAX_CPU_PERCENT=20
export MAX_MEM_PERCENT=5
ps -C gnome-shell -o %cpu,%mem,cmd
# Check CPU. On localhost with 2.80GHz x 4 takes ~3%, on Travis ~15%.
bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %cpu|tail -1) < $MAX_CPU_PERCENT") -eq 1 ]]'
# Check memory. On localhost with 32GB of memory, ~0.6%, on Travis ~3%.
bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %mem|tail -1) < $MAX_MEM_PERCENT") -eq 1 ]]'

echo "[$(date)] Confirming extension hasn't thrown any errors."
# Note, finding no entries returns an error code of 1, which in our case means no error.
sudo journalctl /usr/bin/gnome-shell
sudo journalctl /usr/bin/gnome-shell|grep "\-\- No entries \-\-"
sudo journalctl --since=$(date '+%Y-%m-%d') /usr/bin/gnome-shell|grep -i "Extension \"system-monitor@paradoxxx.zero.gmail.com\" had error"
60 changes: 60 additions & 0 deletions run_docker_tests.sh
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
# The top-level user script for executing tests from Docker.
# The first argument should be a distro identifier.

export DISTRO=${1:-ubuntu1804}

echo "[$(date)] Running $DISTRO tests."

COMPOSE_FILE_LOC="docker-compose.yml"

# This must match the name in the docker-compose.*.yml file.
TEST_CONTAINER_NAME="test"

COMPOSE_PROJECT_NAME_ORIGINAL="test_${BUILD_TAG}"
echo "[$(date)] COMPOSE_PROJECT_NAME_ORIGINAL=$COMPOSE_PROJECT_NAME_ORIGINAL"

# Project name is sanitized by Compose, so we need to do the same thing.
# See https://github.com/docker/compose/issues/2119.
COMPOSE_PROJECT_NAME=$(echo $COMPOSE_PROJECT_NAME_ORIGINAL | awk '{print tolower($0)}' | sed 's/[^a-z0-9]*//g')
echo "[$(date)] COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME"
TEST_CONTAINER_REF="${COMPOSE_PROJECT_NAME}_${TEST_CONTAINER_NAME}_1"
echo "[$(date)] TEST_CONTAINER_REF=$TEST_CONTAINER_REF"

# Record installed version of Docker and Compose with each build
echo "[$(date)] Docker environment:"
docker --version
docker-compose --version

function cleanup {
echo "[$(date)] Shutting down..."
docker-compose -f $COMPOSE_FILE_LOC -p $COMPOSE_PROJECT_NAME down --remove-orphans
echo "[$(date)] Stopping..."
docker ps -a --no-trunc | grep $COMPOSE_PROJECT_NAME | awk '{print $1}' | xargs --no-run-if-empty docker stop
echo "[$(date)] Removing..."
docker ps -a --no-trunc | grep $COMPOSE_PROJECT_NAME | awk '{print $1}' | xargs --no-run-if-empty docker rm
echo "[$(date)] Delete old containers."
docker system prune -a -f
}

function run_tests {
echo "[$(date)] Creating containers..."
docker-compose -f $COMPOSE_FILE_LOC -p $COMPOSE_PROJECT_NAME up --build --force-recreate --exit-code-from test
ret_code=$?
echo "[$(date)] Docker Compose exit code: $ret_code"

# List images and containers related to this build
docker images | grep $COMPOSE_PROJECT_NAME | awk '{print $0}'
docker ps -a | grep $COMPOSE_PROJECT_NAME | awk '{print $0}'

# Follow the container with tests...
docker logs -f $TEST_CONTAINER_REF

exit $ret_code
}

set -e
cleanup # Initial cleanup.
trap cleanup EXIT # Cleanup after tests finish running

run_tests

0 comments on commit af9b177

Please sign in to comment.