From a179f77777acdf00ca565f60757b35ae5c19cbe2 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 29 Oct 2018 17:16:33 +0100 Subject: [PATCH] Add automated update script and more tests Signed-off-by: Knut Ahlers --- .travis.yml | 13 +------ Dockerfile | 4 +-- Makefile | 30 +++++++++++++++++ patcher/index.py | 73 ++++++++++++++++++++++++++++++++++++++++ patcher/requirements.txt | 2 ++ 5 files changed, 108 insertions(+), 14 deletions(-) create mode 100644 Makefile create mode 100644 patcher/index.py create mode 100644 patcher/requirements.txt diff --git a/.travis.yml b/.travis.yml index 2d75cea..9082fef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,5 @@ language: bash services: docker -install: - - git clone https://github.com/docker-library/official-images.git ~/official-images - -before_script: - - env | sort - - image="luzifer/teamspeak3:latest" - script: - - travis_retry docker build -t "$image" . - - ~/official-images/test/run.sh "$image" - -after_script: - - docker images + - make test diff --git a/Dockerfile b/Dockerfile index e235263..6b7b07f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,8 @@ LABEL maintainer Knut Ahlers ENV TEAMSPEAK_VERSION=3.5.0 \ TEAMSPEAK_SHA256=9bd56e115afea19351a6238a670dc93e365fe88f8a6c28b5b542ef6ae2ca677e -RUN set -ex \ - && apt-get update \ +SHELL ["/bin/bash", "-exo", "pipefail", "-c"] +RUN apt-get update \ && apt-get install -y curl bzip2 ca-certificates --no-install-recommends \ && curl -sSfLo teamspeak3-server_linux-amd64.tar.bz2 \ "http://dl.4players.de/ts/releases/${TEAMSPEAK_VERSION}/teamspeak3-server_linux_amd64-${TEAMSPEAK_VERSION}.tar.bz2" \ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f8a9060 --- /dev/null +++ b/Makefile @@ -0,0 +1,30 @@ +default: test + +build: + # Build image + docker build -t "luzifer/teamspeak3:latest" . + +hadolint: + # Execute hadolint on Dockerfile + docker run --rm -i \ + -v "$(CURDIR):$(CURDIR)" \ + -w "$(CURDIR)" \ + hadolint/hadolint \ + hadolint --ignore=DL3008 Dockerfile + +official-tests: build + # Execute official docker-image tests + git clone https://github.com/docker-library/official-images.git /tmp/official-images + /tmp/official-images/test/run.sh "luzifer/teamspeak3:latest" + rm -rf /tmp/official-images + +test: hadolint official-tests + +update: teamspeaki_version_update test + +teamspeaki_version_update: + docker run --rm -i \ + -v "$(CURDIR):$(CURDIR)" \ + -w "$(CURDIR)" \ + python:3-alpine \ + sh -c "pip install -r patcher/requirements.txt && python3 patcher/index.py" diff --git a/patcher/index.py b/patcher/index.py new file mode 100644 index 0000000..1514809 --- /dev/null +++ b/patcher/index.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +from bs4 import BeautifulSoup +import re +import requests + + +def get_page(): + return BeautifulSoup( + requests.get('https://www.teamspeak.com/en/downloads/').text, + 'html.parser', + ) + + +def filter_file(tag): + # We are searching for div.file + if not tag.has_attr('class') or 'file' not in tag['class']: + return False + + # We only care for the 64-bit server version + if 'Server 64-bit' not in tag.find('h3').text: + return False + + # We only care for the linux version + if 'linux_amd64' not in tag.find('a')['href']: + return False + + return True + + +def latest_version(): + page = get_page() + fd = page.body.find(filter_file) + + version = fd.find('span', 'version').text.strip() + checksum = fd.find('p', 'checksum').text.split(' ')[1] + + return (version, checksum) + + +def main(): + (version, checksum) = latest_version() + + lines = [] + + with open('Dockerfile', 'r') as f: + for line in f: + lines.append(substitute(line, { + 'TEAMSPEAK_VERSION': version, + 'TEAMSPEAK_SHA256': checksum, + }).strip('\n')) + + lines.append('') + + with open('Dockerfile', 'w') as f: + f.write('\n'.join(lines)) + + +def substitute(line, attrs): + for k, v in attrs.items(): + if k not in line: + continue + line = re.sub( + r'({})=[^ ]+'.format(k), + r'\1={}'.format(v), + line + ) + return line + + +if __name__ == '__main__': + main() diff --git a/patcher/requirements.txt b/patcher/requirements.txt new file mode 100644 index 0000000..3b7d55d --- /dev/null +++ b/patcher/requirements.txt @@ -0,0 +1,2 @@ +beautifulsoup4==4.6.3 +requests==2.20.0