mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
Try enable cache for docker
This commit is contained in:
6
.github/workflows/docker.yml
vendored
6
.github/workflows/docker.yml
vendored
@@ -9,6 +9,7 @@ on:
|
||||
- 'doc/**'
|
||||
- docker-compose.yml
|
||||
- README.md
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: "docker"
|
||||
@@ -23,6 +24,9 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: true
|
||||
- name: Get cache key
|
||||
id: cache_key
|
||||
run: python3 scripts/get_cache_key.py --docker
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
@@ -37,6 +41,8 @@ jobs:
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
cache-from: type=gha,scope=docker-${{ steps.cache_key.outputs.cache_key }}
|
||||
cache-to: type=gha,mode=max,scope=docker-${{ steps.cache_key.outputs.cache_key }}
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
@@ -19,6 +19,18 @@ def sha256(data) -> str:
|
||||
return s.hexdigest()
|
||||
|
||||
|
||||
def hashfile(fn):
|
||||
if exists(fn):
|
||||
s = _sha256()
|
||||
with open(fn, 'rb') as f:
|
||||
c = f.read(256)
|
||||
while len(c) > 0:
|
||||
s.update(c)
|
||||
c = f.read(256)
|
||||
return s.hexdigest()
|
||||
return ''
|
||||
|
||||
|
||||
def hash_file(feature, prefix) -> str:
|
||||
if prefix is None:
|
||||
fns = [f"build_{feature}.sh"]
|
||||
@@ -43,8 +55,9 @@ def hash_file(feature, prefix) -> str:
|
||||
|
||||
try:
|
||||
p = ArgumentParser(description='Get the cache key which used in action/cache')
|
||||
p.add_argument("features", help="The feature's name", action='append', nargs='+', choices=['all'] + ALL_FEATURES)
|
||||
p.add_argument("features", help="The feature's name", action='append', nargs='*', choices=[[], 'all'] + ALL_FEATURES)
|
||||
p.add_argument('--prefix', help='The prefix of the cache key')
|
||||
p.add_argument('--docker', help='Cache for docker image', action='store_true', default=False)
|
||||
args = p.parse_intermixed_args(sys.argv[1:])
|
||||
features: List[str] = args.features[0]
|
||||
if 'all' in features:
|
||||
@@ -55,6 +68,10 @@ try:
|
||||
dt = strftime('%Y-%m', gmtime(now))
|
||||
h = hash_file(i, args.prefix)
|
||||
d += f"{i}={dt}:{h}\n"
|
||||
if args.docker:
|
||||
dt = strftime('%Y-%m', gmtime(now))
|
||||
h = hashfile('Dockerfile')
|
||||
d += f"docker={dt}:{h}\n"
|
||||
print(d)
|
||||
github_output = environ.get('GITHUB_OUTPUT', '')
|
||||
if github_output != '':
|
||||
|
||||
Reference in New Issue
Block a user