# https://aka.ms/yaml jobs: - job: test displayName: 'Lint & Test' pool: vmImage: 'ubuntu-18.04' variables: BASE_CHANGED: 'True' VENV_CHANGED: 'True' BASE_PULL: 'False' VENV_PULL: 'False' steps: - 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'))