aboutsummaryrefslogtreecommitdiffstats
path: root/ci
diff options
context:
space:
mode:
Diffstat (limited to 'ci')
-rw-r--r--ci/build.yml51
-rw-r--r--ci/lint-test.yml41
-rw-r--r--ci/push.yml39
-rw-r--r--ci/setup.yml24
4 files changed, 155 insertions, 0 deletions
diff --git a/ci/build.yml b/ci/build.yml
new file mode 100644
index 0000000..7d51709
--- /dev/null
+++ b/ci/build.yml
@@ -0,0 +1,51 @@
+steps:
+ - task: ShellScript@2
+ displayName: 'Check If Images Need to Be Built'
+ inputs:
+ scriptPath: scripts/check_dockerfiles.sh
+ disableAutoCwd: true
+
+ # Without a login, the following Docker build steps wouldn't add image tags.
+ - task: Docker@1
+ displayName: 'Log into Docker Hub'
+ inputs:
+ command: login
+ containerregistrytype: 'Container Registry'
+ dockerRegistryEndpoint: 'DockerHub'
+
+ # Building the venv depends on this base image. Build the base if it can't
+ # pulled from Docker Hub, which will be the case if the base Dockerfile has
+ # has had changes.
+ - script: |
+ docker build \
+ -f docker/base.Dockerfile \
+ -t pythondiscord/snekbox-base:latest \
+ .
+ displayName: 'Build Base Image'
+ condition: >
+ and(
+ succeeded(),
+ or(
+ eq(variables.BASE_CHANGED, 'True'),
+ and(
+ eq(variables.VENV_CHANGED, 'True'),
+ eq(variables.BASE_PULL, 'False')
+ )
+ )
+ )
+
+ # Build the venv image if it's had changes or it can't be pulled.
+ - script: |
+ docker build \
+ -f docker/venv.Dockerfile \
+ -t pythondiscord/snekbox-venv:latest \
+ .
+ displayName: 'Build Virtual Environment Image'
+ condition: >
+ and(
+ succeeded(),
+ or(
+ eq(variables.VENV_CHANGED, 'True'),
+ eq(variables.VENV_PULL, 'False')
+ )
+ )
diff --git a/ci/lint-test.yml b/ci/lint-test.yml
new file mode 100644
index 0000000..2d70f6e
--- /dev/null
+++ b/ci/lint-test.yml
@@ -0,0 +1,41 @@
+steps:
+ - script: |
+ docker exec snekbox_test /bin/bash -c \
+ 'flake8; flake8 --format junit-xml --output-file test-lint.xml'
+ displayName: 'Run Linter'
+
+ - task: PublishTestResults@2
+ displayName: 'Publish Lint Results'
+ condition: succeededOrFailed()
+ inputs:
+ testResultsFiles: '**/test-lint.xml'
+ testRunTitle: 'Lint Results'
+
+ # Memory limit tests would fail if this isn't disabled.
+ - script: sudo swapoff -a
+ displayName: 'Disable Swap Memory'
+
+ - script: |
+ docker exec snekbox_test /bin/bash -c \
+ 'coverage run -m xmlrunner'
+ displayName: 'Run Unit Tests'
+
+ - task: PublishTestResults@2
+ displayName: 'Publish Test Results'
+ condition: succeededOrFailed()
+ inputs:
+ testResultsFiles: '**/TEST-*.xml'
+ testRunTitle: 'Test Results'
+
+ # Run report too because the XML report doesn't output to stdout.
+ - script: |
+ docker exec snekbox_test /bin/bash -c \
+ 'coverage report && coverage xml'
+ displayName: 'Generate Coverage Report'
+
+ - task: PublishCodeCoverageResults@1
+ displayName: 'Publish Coverage Results'
+ condition: succeededOrFailed()
+ inputs:
+ codeCoverageTool: Cobertura
+ summaryFileLocation: '**/coverage.xml'
diff --git a/ci/push.yml b/ci/push.yml
new file mode 100644
index 0000000..9449df0
--- /dev/null
+++ b/ci/push.yml
@@ -0,0 +1,39 @@
+steps:
+ # Always build this image unless it's for a pull request.
+ - script: |
+ docker build \
+ -f docker/Dockerfile \
+ -t pythondiscord/snekbox:latest \
+ .
+ displayName: 'Build Final Image'
+ condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
+
+ # Push images only after they've all successfully been built.
+ - script: docker push pythondiscord/snekbox-base:latest
+ displayName: 'Push Base Image'
+ condition: >
+ and(
+ succeeded(),
+ ne(variables['Build.Reason'], 'PullRequest'),
+ ne(variables.BASE_PULL, 'True'),
+ or(
+ eq(variables.BASE_CHANGED, 'True'),
+ eq(variables.VENV_CHANGED, 'True')
+ )
+ )
+
+ - script: docker push pythondiscord/snekbox-venv:latest
+ displayName: 'Push Virtual Environment Image'
+ condition: >
+ and(
+ succeeded(),
+ ne(variables['Build.Reason'], 'PullRequest'),
+ or(
+ eq(variables.BASE_CHANGED, 'True'),
+ eq(variables.VENV_CHANGED, 'True')
+ )
+ )
+
+ - script: docker push pythondiscord/snekbox:latest
+ displayName: 'Push Final Image'
+ condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
diff --git a/ci/setup.yml b/ci/setup.yml
new file mode 100644
index 0000000..cf190de
--- /dev/null
+++ b/ci/setup.yml
@@ -0,0 +1,24 @@
+steps:
+ # The linter and all tests run inside this container.
+ # The venv image will be pulled if it doesn't exist locally.
+ - script: |
+ docker run \
+ --tty \
+ --detach \
+ --name snekbox_test \
+ --privileged \
+ --network host \
+ --hostname pdsnk-dev \
+ -e PYTHONDONTWRITEBYTECODE=1 \
+ -e PIPENV_PIPFILE="/snekbox/Pipfile" \
+ -e ENV="${PWD}/scripts/.profile" \
+ --volume "${PWD}":"${PWD}" \
+ --workdir "${PWD}"\
+ --entrypoint /bin/bash \
+ pythondiscord/snekbox-venv:latest
+ displayName: 'Start Container'
+
+ - script: |
+ docker exec snekbox_test /bin/bash -c \
+ 'pipenv install --system --deploy --dev'
+ displayName: 'Install Development Dependencies'