Add a way to invalidate docker images cache

This commit is contained in:
Mikhail f. Shiryaev 2022-06-08 14:25:41 +02:00
parent a3e3be5221
commit 9ca03d09cc
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4
4 changed files with 16 additions and 12 deletions

View File

@ -1,15 +1,16 @@
# rebuild in #36968 # rebuild in #36968
# docker build -t clickhouse/docs-builder . # docker build -t clickhouse/docs-builder .
# nodejs 17 prefers ipv6 and is broken in our environment # nodejs 17 prefers ipv6 and is broken in our environment
FROM node:16.14.2-alpine3.15 FROM node:16-alpine
RUN apk add --no-cache git openssh bash RUN apk add --no-cache git openssh bash
# TODO: clean before merge! # At this point we want to really update /opt/clickhouse-docs
ARG DOCS_BRANCH=main # despite the cached images
ARG CACHE_INVALIDATOR=0
RUN git clone https://github.com/ClickHouse/clickhouse-docs.git \ RUN git clone https://github.com/ClickHouse/clickhouse-docs.git \
--depth=1 --branch=${DOCS_BRANCH} /opt/clickhouse-docs --depth=1 --branch=main /opt/clickhouse-docs
WORKDIR /opt/clickhouse-docs WORKDIR /opt/clickhouse-docs

View File

@ -8,8 +8,6 @@ if [ "$GIT_DOCS_BRANCH" ] && ! [ "$GIT_DOCS_BRANCH" == "$GIT_BRANCH" ]; then
git fetch origin --depth=1 -- "$GIT_DOCS_BRANCH:$GIT_DOCS_BRANCH" git fetch origin --depth=1 -- "$GIT_DOCS_BRANCH:$GIT_DOCS_BRANCH"
git checkout "$GIT_DOCS_BRANCH" git checkout "$GIT_DOCS_BRANCH"
else else
# Untracked yarn.lock could cause pull to fail
git clean -fdx
# Update docs repo # Update docs repo
git pull git pull
fi fi

View File

@ -12,14 +12,14 @@ from typing import Dict, List, Optional, Set, Tuple, Union
from github import Github from github import Github
from env_helper import GITHUB_WORKSPACE, RUNNER_TEMP, GITHUB_RUN_URL
from s3_helper import S3Helper
from pr_info import PRInfo
from get_robot_token import get_best_robot_token, get_parameter_from_ssm
from upload_result_helper import upload_results
from commit_status_helper import post_commit_status
from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse
from commit_status_helper import post_commit_status
from env_helper import GITHUB_WORKSPACE, RUNNER_TEMP, GITHUB_RUN_URL
from get_robot_token import get_best_robot_token, get_parameter_from_ssm
from pr_info import PRInfo
from s3_helper import S3Helper
from stopwatch import Stopwatch from stopwatch import Stopwatch
from upload_result_helper import upload_results
NAME = "Push to Dockerhub (actions)" NAME = "Push to Dockerhub (actions)"
@ -237,6 +237,8 @@ def build_and_push_one_image(
"docker buildx build --builder default " "docker buildx build --builder default "
f"--label build-url={GITHUB_RUN_URL} " f"--label build-url={GITHUB_RUN_URL} "
f"{from_tag_arg}" f"{from_tag_arg}"
# A hack to invalidate cache, grep for it in docker/ dir
f"--build-arg CACHE_INVALIDATOR={GITHUB_RUN_URL} "
f"--tag {image.repo}:{version_string} " f"--tag {image.repo}:{version_string} "
f"--cache-from type=registry,ref={image.repo}:{version_string} " f"--cache-from type=registry,ref={image.repo}:{version_string} "
f"--cache-from type=registry,ref={image.repo}:latest " f"--cache-from type=registry,ref={image.repo}:latest "

View File

@ -124,6 +124,7 @@ class TestDockerImageCheck(unittest.TestCase):
self.assertIn( self.assertIn(
f"docker buildx build --builder default --label build-url={GITHUB_RUN_URL} " f"docker buildx build --builder default --label build-url={GITHUB_RUN_URL} "
"--build-arg FROM_TAG=version " "--build-arg FROM_TAG=version "
f"--build-arg CACHE_INVALIDATOR={GITHUB_RUN_URL} "
"--tag name:version --cache-from type=registry,ref=name:version " "--tag name:version --cache-from type=registry,ref=name:version "
"--cache-from type=registry,ref=name:latest " "--cache-from type=registry,ref=name:latest "
"--cache-to type=inline,mode=max --push --progress plain path", "--cache-to type=inline,mode=max --push --progress plain path",
@ -142,6 +143,7 @@ class TestDockerImageCheck(unittest.TestCase):
self.assertIn( self.assertIn(
f"docker buildx build --builder default --label build-url={GITHUB_RUN_URL} " f"docker buildx build --builder default --label build-url={GITHUB_RUN_URL} "
"--build-arg FROM_TAG=version2 " "--build-arg FROM_TAG=version2 "
f"--build-arg CACHE_INVALIDATOR={GITHUB_RUN_URL} "
"--tag name:version2 --cache-from type=registry,ref=name:version2 " "--tag name:version2 --cache-from type=registry,ref=name:version2 "
"--cache-from type=registry,ref=name:latest " "--cache-from type=registry,ref=name:latest "
"--cache-to type=inline,mode=max --progress plain path", "--cache-to type=inline,mode=max --progress plain path",
@ -159,6 +161,7 @@ class TestDockerImageCheck(unittest.TestCase):
mock_machine.assert_not_called() mock_machine.assert_not_called()
self.assertIn( self.assertIn(
f"docker buildx build --builder default --label build-url={GITHUB_RUN_URL} " f"docker buildx build --builder default --label build-url={GITHUB_RUN_URL} "
f"--build-arg CACHE_INVALIDATOR={GITHUB_RUN_URL} "
"--tag name:version2 --cache-from type=registry,ref=name:version2 " "--tag name:version2 --cache-from type=registry,ref=name:version2 "
"--cache-from type=registry,ref=name:latest " "--cache-from type=registry,ref=name:latest "
"--cache-to type=inline,mode=max --progress plain path", "--cache-to type=inline,mode=max --progress plain path",