aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-02-21 22:22:18 -0800
committerGravatar MarkKoz <[email protected]>2020-02-21 22:40:24 -0800
commit604e80a64e1ded4c002ff5a6ae89ceb329f5a120 (patch)
treef6f4698bd3bb3aceedd8cabdc5d742b529e7fba0
parentCI: don't build venv image if it can be pulled (diff)
CI: merge build job with test job
* Remove duplicate build steps * Move push steps to a separate YAML file
-rw-r--r--azure-pipelines.yml111
-rw-r--r--ci/push.yml39
2 files changed, 42 insertions, 108 deletions
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 615d3a8..c45550c 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -1,8 +1,8 @@
# https://aka.ms/yaml
jobs:
- - job: test
- displayName: 'Lint & Test'
+ - job: build-lint-test-push
+ displayName: 'Build, Lint, Test, & Push'
pool:
vmImage: 'ubuntu-18.04'
@@ -17,109 +17,4 @@ jobs:
- template: ci/build.yml
- template: ci/setup.yml
- template: ci/lint-test.yml
-
- # When a pull request, only perform this job if images need to be built.
- # It's always performed for non-PRs because the final image will always need
- # to be built.
- - job: build
- displayName: 'Build'
- condition: >
- and(
- succeeded(),
- or(
- ne(variables['Build.Reason'], 'PullRequest'),
- eq(coalesce(dependencies.test.outputs['check.BASE_CHANGED'], 'True'), 'True'),
- eq(coalesce(dependencies.test.outputs['check.VENV_CHANGED'], 'True'), 'True')
- )
- )
- dependsOn: test
-
- # coalesce() gives variables default values if they are null (i.e. unset).
- variables:
- BASE_CHANGED: $[ coalesce(dependencies.test.outputs['check.BASE_CHANGED'], 'True') ]
- VENV_CHANGED: $[ coalesce(dependencies.test.outputs['check.VENV_CHANGED'], 'True') ]
- BASE_PULL: $[ coalesce(dependencies.test.outputs['check.BASE_PULL'], 'False') ]
-
- steps:
- - task: Docker@1
- displayName: 'Log into Docker Hub'
- inputs:
- command: login
- containerregistrytype: 'Container Registry'
- dockerRegistryEndpoint: 'DockerHub'
-
- # Because this is the base image for the venv image, if the venv needs to
- # be built, this base image must also be present. Build it if it has
- # changed or can't be pulled from Docker Hub.
- - script: |
- docker build \
- -f docker/base.Dockerfile \
- -t pythondiscord/snekbox-base:latest \
- .
- displayName: 'Build Base Image'
- condition: >
- and(
- succeeded(),
- ne(variables.BASE_PULL, 'True'),
- or(
- eq(variables.BASE_CHANGED, 'True'),
- eq(variables.VENV_CHANGED, 'True')
- )
- )
-
- # Also build this image if base has changed - even if this image hasn't.
- - script: |
- docker build \
- -f docker/venv.Dockerfile \
- -t pythondiscord/snekbox-venv:latest \
- .
- displayName: 'Build Virtual Environment Image'
- condition: >
- and(
- succeeded(),
- or(
- eq(variables.BASE_CHANGED, 'True'),
- eq(variables.VENV_CHANGED, 'True')
- )
- )
-
- # 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.
- # These have the same conditions as the build tasks. However, for safety,
- # a condition for not being a pull request is added.
- - 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'))
+ - template: ci/push.yml
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'))