mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-15 07:28:05 +00:00
Cache docker images for sanity tests (#290124)
Cache sanity tests docker images in Azure DevOps pipelines
This commit is contained in:
@@ -31,6 +31,8 @@ jobs:
|
||||
variables:
|
||||
TEST_DIR: $(Build.SourcesDirectory)/test/sanity
|
||||
LOG_FILE: $(TEST_DIR)/results.xml
|
||||
DOCKER_CACHE_DIR: $(Pipeline.Workspace)/docker-cache
|
||||
DOCKER_CACHE_FILE: $(DOCKER_CACHE_DIR)/${{ parameters.container }}.tar
|
||||
steps:
|
||||
- checkout: self
|
||||
fetchDepth: 1
|
||||
@@ -82,6 +84,18 @@ jobs:
|
||||
|
||||
# Linux Docker container
|
||||
- ${{ if ne(parameters.container, '') }}:
|
||||
- task: Cache@2
|
||||
inputs:
|
||||
key: 'docker-v3 | "${{ parameters.container }}" | "${{ parameters.arch }}" | "$(Agent.OS)" | $(TEST_DIR)/containers/${{ parameters.container }}.dockerfile'
|
||||
path: $(DOCKER_CACHE_DIR)
|
||||
restoreKeys: docker-v3 | "${{ parameters.container }}" | "${{ parameters.arch }}" | "$(Agent.OS)"
|
||||
cacheHitVar: DOCKER_CACHE_HIT
|
||||
displayName: Download Docker Image
|
||||
|
||||
- bash: docker load -i "$(DOCKER_CACHE_FILE)"
|
||||
condition: eq(variables.DOCKER_CACHE_HIT, 'true')
|
||||
displayName: Load Docker Image
|
||||
|
||||
- bash: |
|
||||
$(TEST_DIR)/scripts/run-docker.sh \
|
||||
--container "${{ parameters.container }}" \
|
||||
@@ -94,6 +108,12 @@ jobs:
|
||||
workingDirectory: $(TEST_DIR)
|
||||
displayName: Run Sanity Tests
|
||||
|
||||
- bash: |
|
||||
mkdir -p "$(DOCKER_CACHE_DIR)"
|
||||
docker save -o "$(DOCKER_CACHE_FILE)" "${{ parameters.container }}"
|
||||
condition: and(succeeded(), ne(variables.DOCKER_CACHE_HIT, 'true'))
|
||||
displayName: Save Docker Image
|
||||
|
||||
- task: PublishTestResults@2
|
||||
inputs:
|
||||
testResultsFormat: JUnit
|
||||
|
||||
@@ -23,13 +23,18 @@ fi
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
ROOT_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
|
||||
|
||||
echo "Building container image: $CONTAINER"
|
||||
docker buildx build \
|
||||
--platform "linux/$ARCH" \
|
||||
${BASE_IMAGE:+--build-arg "BASE_IMAGE=$BASE_IMAGE"} \
|
||||
--tag "$CONTAINER" \
|
||||
--file "$ROOT_DIR/containers/$CONTAINER.dockerfile" \
|
||||
"$ROOT_DIR/containers"
|
||||
# Only build if image doesn't exist (i.e., not loaded from cache)
|
||||
if ! docker image inspect "$CONTAINER" > /dev/null 2>&1; then
|
||||
echo "Building container image: $CONTAINER"
|
||||
docker buildx build \
|
||||
--platform "linux/$ARCH" \
|
||||
${BASE_IMAGE:+--build-arg "BASE_IMAGE=$BASE_IMAGE"} \
|
||||
--tag "$CONTAINER" \
|
||||
--file "$ROOT_DIR/containers/$CONTAINER.dockerfile" \
|
||||
"$ROOT_DIR/containers"
|
||||
else
|
||||
echo "Using cached container image: $CONTAINER"
|
||||
fi
|
||||
|
||||
echo "Running sanity tests in container"
|
||||
docker run \
|
||||
|
||||
Reference in New Issue
Block a user