From e6de13ba44cbe3866e2aff1580a83cc1f4493601 Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Sun, 19 May 2019 21:02:06 -0400 Subject: [PATCH] Update azure-pipelines.yml for Azure Pipelines (#331) * Update azure-pipelines.yml for Azure Pipelines * Add Python build scripts. * Run scripts with Python 3. * Add strategy for both variants. * Fix variables for jobs and use the right variant to build. * Fix build and test script. --- azure-pipelines.yml | 44 ++++++++++++++++++------- build.py | 79 +++++++++++++++++++++++++++++++++++++++++++++ test.py | 39 ++++++++++++++++++++++ tests/test.sh | 6 ++-- 4 files changed, 153 insertions(+), 15 deletions(-) create mode 100755 build.py create mode 100644 test.py diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3917c74..c9adff0 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,18 +1,38 @@ -# Docker image -# Build a Docker image to deploy, run, or push to a container registry. -# Add steps that use Docker Compose, tag images, push to a registry, run an image, and more: -# https://docs.microsoft.com/azure/devops/pipelines/languages/docker - trigger: - master pool: vmImage: 'Ubuntu-16.04' -steps: - - script: | - docker --version - docker-compose --version - docker build -t maxking/mailman-core:latest core/ - docker build -t maxking/mailman-web:latest web/ - docker build -t maxking/postorius postorius/ +strategy: + maxParallel: 2 + matrix: + Stable: + variant: stable + Rolling: + variant: rolling + +steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.7' + architecture: 'x64' + - task: PythonScript@0 + inputs: + scriptSource: 'filepath' + scriptPath: 'build.py' + arguments: $(variant) + - task: PythonScript@0 + inputs: + scriptSource: 'filepath' + scriptPath: 'test.py' + arguments: $(variant) + - task: Bash@3 + inputs: + filePath: 'tests/test.sh' + - task: PythonScript@0 + inputs: + scriptSource: 'filePath' + scriptPath: '.travis/deploy.py' + condition: and(eq(variables['Build.SourceBranch'], 'refs/heads/master'), + eq(variables['variant'], 'rolling')) diff --git a/build.py b/build.py new file mode 100755 index 0000000..2b95c61 --- /dev/null +++ b/build.py @@ -0,0 +1,79 @@ +#/usr/bin/env python3 + +# This is the build script to build container images for Mailman. +import sys +import subprocess +from pathlib import Path + + +STABLE_DOCKERFILES = { + 'core-stable': Path('core/Dockerfile'), + 'web-stable': Path('web/Dockerfile'), + 'postorius-stable': Path('postorius/Dockerfile'), +} + +ROLLING_DOCKERFILES = { + 'core-rolling': Path('core/Dockerfile.dev'), + 'web-rolling': Path('web/Dockerfile.dev'), + 'postorius-rolling': Path('postorius/Dockerfile.dev'), +} + +VARIANTS = { + 'stable': STABLE_DOCKERFILES, + 'rolling': ROLLING_DOCKERFILES, +} + +def run_command(args): + print(' '.join(args)) + subprocess.run( + args, + stdout=sys.stdout, + stderr=sys.stderr, + check=True) + + +def docker_build(dockerfile, tag, args=None, labels=None): + cmd = [ + 'docker', 'build', + '-t', tag, + '-f', str(dockerfile), + str(dockerfile.parent) + ] + + if args: + for arg in args: + cmd.append('--build-arg') + cmd.append(arg) + + if labels: + for label in labels: + cmd.append('--label') + cmd.append(label) + + return run_command(cmd) + + +def docker_tag(from_tag, to_tag): + cmd = [ + 'docker', 'tag', + from_tag, to_tag, + ] + + return run_command(cmd) + +def usage(): + print('usage: python build.py (stable|rolling)') + + +if __name__ == '__main__': + if len(sys.argv) < 2: + usage() + sys.exit(1) + + variant = sys.argv[1] + if variant not in VARIANTS: + usage() + sys.exit(1) + + for name, path in VARIANTS[variant].items(): + docker_build(dockerfile=path, tag=name) diff --git a/test.py b/test.py new file mode 100644 index 0000000..e213aab --- /dev/null +++ b/test.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +import sys +from pathlib import Path +from build import VARIANTS + +DOCKER_TEST="""version: '2' + +services: + mailman-core: + image: core-{variant} + + mailman-web: + image: web-{variant} + environment: + - SECRET_KEY=abcdefghijklmnopqrstuv +""" + + +def test_setup(variant): + Path('docker-test.yaml').write_text( + DOCKER_TEST.format(variant=variant)) + + +def usage(): + print('usage: python test.py (stable|rolling)') + + +if __name__ == '__main__': + if len(sys.argv) < 2: + usage() + sys.exit(1) + + variant = sys.argv[1] + if variant not in VARIANTS: + usage() + sys.exit(1) + + test_setup(variant) diff --git a/tests/test.sh b/tests/test.sh index 6955b4e..6337b89 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -27,10 +27,10 @@ docker logs mailman-core # Check to see if the core is working as expected. -docker exec -it mailman-core curl -u restadmin:restpass http://172.19.199.2:8001/3.1/system | grep "GNU Mailman" +docker exec mailman-core curl -u restadmin:restpass http://172.19.199.2:8001/3.1/system | grep "GNU Mailman" # Check to see if postorius is working. -docker exec -it mailman-web curl -L http://172.19.199.3:8000/postorius/lists | grep "Mailing List" +docker exec mailman-web curl -L http://172.19.199.3:8000/postorius/lists | grep "Mailing List" # Check to see if hyperkitty is working. -docker exec -it mailman-web curl -L http://172.19.199.3:8000/hyperkitty/ | grep "Available lists" +docker exec mailman-web curl -L http://172.19.199.3:8000/hyperkitty/ | grep "Available lists"