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.
This commit is contained in:
@@ -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:
|
trigger:
|
||||||
- master
|
- master
|
||||||
|
|
||||||
pool:
|
pool:
|
||||||
vmImage: 'Ubuntu-16.04'
|
vmImage: 'Ubuntu-16.04'
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
maxParallel: 2
|
||||||
|
matrix:
|
||||||
|
Stable:
|
||||||
|
variant: stable
|
||||||
|
Rolling:
|
||||||
|
variant: rolling
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- script: |
|
- task: UsePythonVersion@0
|
||||||
docker --version
|
inputs:
|
||||||
docker-compose --version
|
versionSpec: '3.7'
|
||||||
docker build -t maxking/mailman-core:latest core/
|
architecture: 'x64'
|
||||||
docker build -t maxking/mailman-web:latest web/
|
- task: PythonScript@0
|
||||||
docker build -t maxking/postorius postorius/
|
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'))
|
||||||
|
|||||||
79
build.py
Executable file
79
build.py
Executable file
@@ -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)
|
||||||
39
test.py
Normal file
39
test.py
Normal file
@@ -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)
|
||||||
@@ -27,10 +27,10 @@ docker logs mailman-core
|
|||||||
|
|
||||||
|
|
||||||
# Check to see if the core is working as expected.
|
# 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.
|
# 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.
|
# 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"
|
||||||
|
|||||||
Reference in New Issue
Block a user