-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocker.yml
87 lines (71 loc) · 2.66 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 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
pool:
vmImage: 'Ubuntu 16.04'
variables:
skipComponentGovernanceDetection: 'true'
DOCKER_BUILDKIT: 1
system.debug: 'true'
agent.diagnostic: 'true'
# buildkit tool itself
BUILD_KIT_CACHE: '$(Pipeline.Workspace)/buildkitcache'
BUILDKIT_COMMIT: 10cef0c6e178bcaca1ad02b041a96b1091f52071
BUILDKIT_CACHE_KEY: GOOFS=0 | buildkit | $(BUILDKIT_COMMIT)
DOCKER_COMMAND: 'buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=.'
CACHE_KEY_SALT: 2
CACHE_KEY_BUILDKIT: '"DOCKER_BUILDKIT=$(DOCKER_BUILDKIT)" | "BUILDKIT_COMMIT=$(BUILDKIT_COMMIT)"'
CACHE_KEY_FALLBACK: '"CACHE_KEY_SALT=$(CACHE_KEY_SALT)" | "$(Agent.OS) $(Agent.JobName)" | $(CACHE_KEY_BUILDKIT) | "$(DOCKER_COMMAND)"'
CACHE_KEY_EXACT: '$(CACHE_KEY_FALLBACK) | $(System.DefaultWorkingDirectory)/Dockerfile,$(System.DefaultWorkingDirectory)/Cargo.*'
steps:
# Build/restore the BuildKit tool
- task: CacheBeta@0
inputs:
key: $(BUILDKIT_CACHE_KEY)
path: '$(System.DefaultWorkingDirectory)/buildkit'
cacheHitVar: 'BuildKitToolHit'
displayName: 'cache buildkit tool'
- script: |
git clone https://github.com/moby/buildkit.git
cd buildkit
git checkout $(BUILDKIT_COMMIT)
make
displayName: "Build BuildKit on cache miss"
condition: and(succeeded(), ne(variables['BuildKitToolHit'], 'true'))
- script: |
cd buildkit
sudo make install
which buildctl
which buildkitd
# restore the BuildKit cache based on the Dockerfile ...
- task: CacheBeta@0
inputs:
key: $(CACHE_KEY_EXACT)
path: '$(BUILD_KIT_CACHE)'
cacheHitVar: 'BuildKitLayersHit'
restoreKeys: |
$(CACHE_KEY_FALLBACK)
displayName: 'cache docker layers'
- script: |
set -e -x
sudo buildkitd --debug --root /var/lib/buildkit &
until sudo buildctl du -v
do
echo "Waiting for daemon to load"
sleep 1
done
DOCKER_COMMAND="$(DOCKER_COMMAND)"
if [ -d "$(BUILD_KIT_CACHE)" ]; then
echo "Will use cached layers from $(BUILD_KIT_CACHE)"
find $(BUILD_KIT_CACHE)
DOCKER_COMMAND="$DOCKER_COMMAND --import-cache type=local,src=$(BUILD_KIT_CACHE)"
fi
if [ "$(BuildKitLayersHit)" != "true" ]; then
echo "Will store cached layers to $(BUILD_KIT_CACHE)"
DOCKER_COMMAND="$DOCKER_COMMAND --export-cache mode=max,type=local,dest=$(BUILD_KIT_CACHE)"
fi
sudo $DOCKER_COMMAND
find $(BUILD_KIT_CACHE)
sudo kill -9 $(jobs -p)
displayName: 'docker build'