Improve artifacts handling and writing manifest

This commit is contained in:
Ayaz Salikhov
2022-07-05 19:44:25 +04:00
parent 9ff6f86eed
commit 16a2b81ea9
6 changed files with 19 additions and 22 deletions

View File

@@ -70,6 +70,5 @@ jobs:
- name: Cleanup artifacts 🗑️ - name: Cleanup artifacts 🗑️
run: | run: |
rm -f /tmp/${{ inputs.image }}-${{ inputs.platform }}.tar rm -f /tmp/${{ inputs.image }}-${{ inputs.platform }}.tar
docker system prune --all --force
shell: bash shell: bash
if: always() if: always()

View File

@@ -38,9 +38,12 @@ jobs:
platform: ${{ inputs.platform }} platform: ${{ inputs.platform }}
# Self-hosted runners share a state (whole VM) between runs # Self-hosted runners share a state (whole VM) between runs
- name: Reset docker state 🗑️ - name: Reset docker state and cleanup artifacts 🗑️
if: ${{ inputs.platform != 'amd64' }} if: ${{ inputs.platform != 'amd64' }}
run: docker system prune --all --force run: |
docker system prune --all --force
rm -rf /tmp/hist_lines/
rm -rf /tmp/manifests/
shell: bash shell: bash
- name: Load image to Docker 📥 - name: Load image to Docker 📥
@@ -55,8 +58,8 @@ jobs:
docker image ls -a docker image ls -a
shell: bash shell: bash
- name: Write manifest files 🏷 - name: Write manifest and build history file 🏷
run: python3 -m tagging.write_manifests --short-image-name ${{ matrix.image }} --hist-line-dir /tmp/hist_lines/ --manifest-dir /tmp/manifests/ run: python3 -m tagging.write_manifest --short-image-name ${{ matrix.image }} --hist-line-dir /tmp/hist_lines/ --manifest-dir /tmp/manifests/
shell: bash shell: bash
- name: Upload manifest file 💾 - name: Upload manifest file 💾
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
@@ -71,6 +74,11 @@ jobs:
path: /tmp/hist_lines/${{ inputs.platform }}-${{ matrix.image }}-*.txt path: /tmp/hist_lines/${{ inputs.platform }}-${{ matrix.image }}-*.txt
retention-days: 3 retention-days: 3
- name: Remove aarch64 latest tag
if: ${{ inputs.platform != 'amd64' }}
run: docker rmi jupyter/${{ matrix.image }}
shell: bash
- name: Login to Docker Hub 🔐 - name: Login to Docker Hub 🔐
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.event_name == 'schedule' if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.event_name == 'schedule'
uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b # dependabot updates to latest release uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b # dependabot updates to latest release
@@ -82,12 +90,3 @@ jobs:
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.event_name == 'schedule' if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.event_name == 'schedule'
run: docker push --all-tags jupyter/${{ matrix.image }} run: docker push --all-tags jupyter/${{ matrix.image }}
shell: bash shell: bash
# Self-hosted runners share a state (whole VM) between runs
- name: Cleanup artifacts 🗑️
run: |
rm -rf /tmp/hist_lines/
rm -rf /tmp/manifests/
docker system prune --all --force
shell: bash
if: always()

View File

@@ -70,7 +70,7 @@ linkcheck-docs: ## check broken links
hook/%: WIKI_PATH?=wiki hook/%: WIKI_PATH?=wiki
hook/%: ## run post-build hooks for an image hook/%: ## run post-build hooks for an image
python3 -m tagging.tag_image --short-image-name "$(notdir $@)" --owner "$(OWNER)" && \ python3 -m tagging.tag_image --short-image-name "$(notdir $@)" --owner "$(OWNER)" && \
python3 -m tagging.create_manifests --short-image-name "$(notdir $@)" --owner "$(OWNER)" --wiki-path "$(WIKI_PATH)" python3 -m tagging.write_manifest --short-image-name "$(notdir $@)" --owner "$(OWNER)" --wiki-path "$(WIKI_PATH)"
hook-all: $(foreach I, $(ALL_IMAGES), hook/$(I)) ## run post-build hooks for all images hook-all: $(foreach I, $(ALL_IMAGES), hook/$(I)) ## run post-build hooks for all images

View File

@@ -113,7 +113,7 @@ class AptPackagesManifest(ManifestInterface):
- `quoted_output` simply runs the command inside container using `DockerRunner.run_simple_command` and wraps it to triple quotes to create a valid markdown piece of file. - `quoted_output` simply runs the command inside container using `DockerRunner.run_simple_command` and wraps it to triple quotes to create a valid markdown piece of file.
- `manifests.py` contains all the manifests. - `manifests.py` contains all the manifests.
- `create_manifests.py` is a python executable which is used to create the build manifest for an image. - `write_manifest.py` is a python executable which is used to create the build manifest and history line for an image.
### Images Hierarchy ### Images Hierarchy

View File

@@ -37,9 +37,8 @@ def tag_image(short_image_name: str, owner: str) -> None:
"tag", image, f"{owner}/{short_image_name}:{tags_prefix}{tag_value}" "tag", image, f"{owner}/{short_image_name}:{tags_prefix}{tag_value}"
]() ]()
if tags_prefix != "": if tags_prefix != "":
LOGGER.info(f"Changing :latest tag to include {tags_prefix=}") LOGGER.info(f"Adding {tags_prefix}latest tag")
docker["tag", image, f"{owner}/{short_image_name}:{tags_prefix}latest"]() docker["tag", image, f"{owner}/{short_image_name}:{tags_prefix}latest"]()
docker["rmi", image]()
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -73,7 +73,7 @@ def get_file_prefix() -> str:
return "amd64" if machine == "x86_64" else "aarch64" return "amd64" if machine == "x86_64" else "aarch64"
def write_manifests( def write_manifest(
short_image_name: str, short_image_name: str,
owner: str, owner: str,
hist_line_dir: Path, hist_line_dir: Path,
@@ -82,14 +82,14 @@ def write_manifests(
LOGGER.info(f"Creating manifests for image: {short_image_name}") LOGGER.info(f"Creating manifests for image: {short_image_name}")
taggers, manifests = get_taggers_and_manifests(short_image_name) taggers, manifests = get_taggers_and_manifests(short_image_name)
tags_prefix = get_tags_prefix() image = f"{owner}/{short_image_name}:latest"
image = f"{owner}/{short_image_name}:{tags_prefix}latest"
file_prefix = get_file_prefix() file_prefix = get_file_prefix()
commit_hash_tag = GitHelper.commit_hash_tag() commit_hash_tag = GitHelper.commit_hash_tag()
filename = f"{file_prefix}-{short_image_name}-{commit_hash_tag}" filename = f"{file_prefix}-{short_image_name}-{commit_hash_tag}"
with DockerRunner(image) as container: with DockerRunner(image) as container:
tags_prefix = get_tags_prefix()
all_tags = [tags_prefix + tagger.tag_value(container) for tagger in taggers] all_tags = [tags_prefix + tagger.tag_value(container) for tagger in taggers]
write_build_history_line( write_build_history_line(
short_image_name, owner, hist_line_dir, filename, all_tags short_image_name, owner, hist_line_dir, filename, all_tags
@@ -125,6 +125,6 @@ if __name__ == "__main__":
LOGGER.info(f"Current build timestamp: {BUILD_TIMESTAMP}") LOGGER.info(f"Current build timestamp: {BUILD_TIMESTAMP}")
write_manifests( write_manifest(
args.short_image_name, args.owner, args.hist_line_dir, args.manifest_dir args.short_image_name, args.owner, args.hist_line_dir, args.manifest_dir
) )